5

My program consists of 3 main 'sections'. Main function, Login form and App form. The main function should do something like: Open Login form, wait for it to close, then open App form. I can't get the waiting part to work, or rather, I don't know how I would go around doing that.

I was told by someone to use a JDialog instead and use setModal(true), but with that approach the Login form wouldn't appear on the taskbar, which is terrible in my opinion.

Another thing I considered was to open the App from inside the Login after it closes, but that feels like bad design since that'd make the Login form non-reusable.

So, please, what would you suggest?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
argoneus
  • 1,097
  • 2
  • 13
  • 24
  • 1
    Why must the login appear on the task bar, since the main app will be there, and you don't want more than one task bar item for an individual program. Your best option is to use a modal JDialog. – Hovercraft Full Of Eels Sep 09 '12 at 01:06
  • I dispose of the Login after it closes, so there's always just one at a time. – argoneus Sep 09 '12 at 01:08
  • It may not be "fun" for the user to have a bunch of windows thrown at them. Check out CardLayout. – Hovercraft Full Of Eels Sep 09 '12 at 01:09
  • I've already started using MigLayout. Thought the layout was irrelevant. – argoneus Sep 09 '12 at 01:09
  • Your misunderstanding the point. CardLayout is not a layout in the usual sense. Please check the tutorial out. I've added a link to the tut in my answer. – Hovercraft Full Of Eels Sep 09 '12 at 01:10
  • So basically the moment a user presses 'Login' and it logs him in, instead of closing the window it just takes the 'login' panel out (fortunately I do have a separate panel), resizes the frame and pops the App frame in? – argoneus Sep 09 '12 at 01:12
  • That seems fine for this, but I feel like I won't be able to use that every time :( – argoneus Sep 09 '12 at 01:16
  • You could show the main GUI first, but not let it be "activated" until the login dialog has been successfully complete. Any way, up to you as you have several options that you can choose from. – Hovercraft Full Of Eels Sep 09 '12 at 01:17
  • See also [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/a/9554657/418556) – Andrew Thompson Sep 09 '12 at 01:41

1 Answers1

6
  • Why must the login appear on the task bar, since the main app will be there, and you don't want more than one task bar item for an individual program. Your best option may be to use a modal JDialog.
  • Another option is to use CardLayout to swap "views".
  • A third option is to use a JFrame if you must but attach a listener to it, a WindowListener I believe, to respond to its close event.
  • Regardless of which route you go, your login gui should be a JPanel so that you can place it anywhere you wish and then change your mind later.
Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373