Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Login Page not getting displayed  RSS feed

 
Rupjit Chakraborty
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

This is my first post here.
I am trying to build a warehouse system using Java.
So I have a login page and once you login a menu page is displayed.
However when I exit the login page is not getting displayed back again.



Login Page code



Thanks in advance
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch


Looks like you forgot to call setVisible(true);
 
Tim Holloway
Bartender
Posts: 18705
71
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Rupjit!

The term "page" isn't really accurate when using the desktop GUI. Desktop GUI apps normally operate in windows, and the login is usually a dialog window.

"Page" is used to refer to a web page, which would be displayed in a web browser. But you don't use Swing, AWT or SWT to develop GUIs for web pages. The closest you could come would be an applet, and what with recent security issues with applets, that's not a popular solution at the moment.
 
Paul Clapham
Sheriff
Posts: 22476
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd suggest that removing and adding components in a Swing application is hard to get working, and it's rarely necessary. Besides, your code is asymmetric: you remove the Login panel from your frame but then you don't try to add it back, you try to create a new one instead.

What you should do instead, in my opinion, is that your main frame should contain both the login panel and the other panel, whatever that might be. The login panel should be visible initially and the other panel should be invisible. Then after a successful login, make the login panel invisible and the other panel visible.

Or you could use a CardLayout and bring the other panel to the front after a successful login.

If you have an Exit button but you don't want it to just exit the application, then just make it do those things in reverse, i.e. make visible things invisible or bring the login panel to the front in your CardLayout.

But don't mess about with adding and removing components. You're unlikely to get it to work right.
 
Tim Holloway
Bartender
Posts: 18705
71
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, since Swing wasn't designed to use resource templates the way that Macintosh GUI elements were, adding controls dynamically is pretty much the standard simply because there's no other out-of-the-box choice.

Also, doing a show/hide on anything containing passwords ups your security risk, since it means that there's a plain-text copy of the userid and password sitting around in the hidden dialog. It's far better to destroy such data immediately after use.

Normally what I'd be doing is to create a login dialog window class by subclassing the stock dialog and making its constructor build and initialize the sub-controls, instantiate it when login is requested and attach the "close" button to logic that made the parent "destroy" the dialog after use. In Java, since explicit destruction isn't part of the paradigm, that would mean wiping the fields clean and removing references to ensure that everything came up for garbage collection.
 
Paul Clapham
Sheriff
Posts: 22476
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can see that security of the user ID and password isn't top-of-mind in the original design but yes, your point about security is correct. And I would agree with using a dialog to get the login credentials too.
 
Rupjit Chakraborty
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am pretty new to Swings so I don't understand most of the things you are saying. Yes, the part about the destroying of frames and recreation is kind of bad programming but I am still learning Swings and don't know how to redraw panel. I did try to redraw but I was getting a lot of errors. I copy your posts to my system and try to understand what you are getting at. Hopefully, I will understand soon enough. Can you please tell me how I can write good code and build proper(and large) applications using Swing?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!