• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

help with EventHandlers

 
Ranch Hand
Posts: 176
4
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,

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

Cheers

CODE:



Output Window: https://gyazo.com/1297461a5f052b545cfbbf17a0db5274




 
Ranch Hand
Posts: 592
6
jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure about the exact method. but there was some windows close listener which should have Window Event Exit on Close.

Check javadocs to get the exact method name.
 
Rancher
Posts: 3234
30
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Yosuf Ibrahim
Ranch Hand
Posts: 176
4
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Saloon Keeper
Posts: 12878
279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Yosuf Ibrahim
Ranch Hand
Posts: 176
4
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Stephan van Hulst
Saloon Keeper
Posts: 12878
279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic