Below is my code for an application as part of my java course project. What I basically managed to do is the main frame the logo for it and filled in what I would like the user to see once he open the application. My problem is as follows, once he logs in or clicks on the admin access button how can I make all this disappear and whatever else it is I need to appear appears.
Please keep in mind this is my first year and my first course in java, in other words I am still a baby learning how to walk with java and keeps tumbling every 2 steps
Rob Camick wrote:Use a CardLayout. You can then just swap panels in the frame.
Check out the section from the Swing tutorial on How to Use CardLayout for more information and a working example to get your started.
Thanks, mate, card layout is similar to a solution I found but cleaner. However, I need a different solution for efficiency. What I am doing right now is setting the panel I have been using to invisible and then creating a new one within the frame which is fine for the small application I am working on however I want to instead of hiding the components is to delete them and clear the memory space they are taking up
Stephan van Hulst wrote:Instead of using a CardLayout, you can also consider using multiple forms. After your login form has checked that the entered credentials are correct, it closes itself and then shows the next form.
Great, you said exactly what I said I don't know how to do lol
Any hints on how I can do that.
I have tried using the repaint method but that does nothing and I tried using removeAll method but that just freezes my application and all I can do then is close it.
So I have settled with hiding the panel every time and then creating a new one but I am sure that is not efficient
First think of all the methods you want your form to support, just like any other well designed class. This is what I came up with:
Now, if your next form also has a show() method, after successful authentication you can just call close() on this form and then show() on the other form. Forms should have a JFrame field. You can implement the show() methods by setting the frame visible, and you can implement the close() method by disposing the frame.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop