0

I'm developing an application for a deposit ATM. Almost everyone has used one of these at least once in their life so it's safe to say you know what I'm talking about.

I'm currently doing the GUI and I think I should use multiple JFrames.

My reasons:

  1. Each frame is set to respond to certain, different conditions - smart card reader sends a signal, timeout occurs, click occurs, different parts of the machine send various signals to which the app must respond and display an appropriate message
  2. Since this is an embedded device the user has zero ability to interact with the os of the machine beyond using this one program. I think this sets aside considerations of esthethics - multiple windows in taskbar.
  3. The Fullscrean mode does a great job of conceiling everything else going on in the background.

What I dislike:

I get a screen flicker when switching from one frame to another. This might not be related to the general topic of the question and might just be because I'm disposing of frames everytime the program switches away from them instead of setting them to be invisible.

Any thoughts on the subject are welcome.

jeb
  • 78,592
  • 17
  • 171
  • 225
isaric
  • 195
  • 3
  • 18
  • It's no real advantage to use multiple `JFrame`s, when you can use a single one and have multiple content panes for it. – Kayaman Mar 30 '15 at 08:05
  • 1
    Eventually, if you really like the multiple frame design, you can take a look at `JInternalFrame` and `JDesktop`. – NiziL Mar 30 '15 at 08:09
  • I don't think internal frames are the way to do it - it's not an MDI. – isaric Mar 30 '15 at 08:12
  • I get a screen flicker when switching from one frame to another. == hasn't something with multiple instances ...., [lwrong dispose == setVisible for JVM that is still alive](http://stackoverflow.com/questions/6309407/remove-top-level-container-on-runtime) – mKorbel Mar 30 '15 at 08:27
  • 1
    you can to use multiple instances instead of CardLayout, but you'll going crazy from this design – mKorbel Mar 30 '15 at 08:29
  • 1
    Each frame is set to respond to certain, different conditions == JMenuItem with CardLayout (with JFrame.pack() as last code line for every Cards) – mKorbel Mar 30 '15 at 08:31
  • 2
    Agree with @mKorbel.. Use a [`CardLayout`](http://download.oracle.com/javase/8/docs/api/java/awt/CardLayout.html) as shown in [this answer](http://stackoverflow.com/a/5786005/418556). – Andrew Thompson Mar 30 '15 at 08:37
  • So far CardLayout seems the way to go. I would like to select your comment as an answer, mKobel, but I can't. If you add it to the answers I will. – isaric Mar 30 '15 at 12:14

2 Answers2

3

You should use a single JFrame, and have multiple JPanels for the various "screens" you want to show. To change "screen", just remove from the JFrame the JPanel currently shown and add the new one.

EDIT: To make the switch, you can use CardLayout as LayoutManager of your frame. It shows one panel at a time and allows you to easily switch between them.

lodo
  • 2,314
  • 19
  • 31
1

It's no real advantage to use multiple JFrames, when you can use a single one and have multiple content panes for it.

This should prevent any useless flickering and make sure that only one of your "screens" is visible at the same time.

Kayaman
  • 72,141
  • 5
  • 83
  • 121
  • Yes, I've heard of this but I don't think I understand. Could you please provide a link describing the method in more detail? – isaric Mar 30 '15 at 08:08
  • 1
    `JFrame.setContentPane()` can be used to replace all the contents of the frame with a new panel, so instead of multiple frames you'd just use multiple content panes (essentially JPanels). – Kayaman Mar 30 '15 at 08:11
  • @Kayaman (2nd. sentence) I'm doubt it about in Java6/7/8 edges – mKorbel Mar 30 '15 at 08:34