• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Dynamic Swing

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you get some things to show up on screen when one an event occurs and another thing to show up if something else occurs? I have not put all the logic in place for the following code because I can't get this first one to compile with just one if statement. All the classes that return the data to this screen work fine now (thanks to everyone!). And, I continue to learn lots from this forum (thanks even more for that). I have a class that connects to a DB. Next, I have a class that queries the DB for the info I am looking for. That returns a vector object which is instantiated in another class which creates a panel with a combo box in the panel (the combo box's data comes from the query class). Now I want to have this final class display that panel, (the PatientAdd panel) if the "Add Patient" button is pressed.

The way that I tried to do that was to create my action listener and then put some flow control in that listener. If Add Patient is pressed, then the panel is created and placed on the frame. If some other button is pressed, then some other panel will show up and so on. How do I go about doing this? Right now I am told that I can not use a non-static method (add) in a static context. How does one go about making screens dynamically present other screens on the same frame and am I even close in what I have tried to do here?

Thanks so much.

 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"WorkScreen.add()" is trying to call the add() method as if it were a static method -- which it's not, of course. All the methods of the enclosing class are available in an inner class, so you can actually just say (for example) "add()" instead of "WorkScreen.add()"!

Sometimes, there may be an ambiguity between an inner class method and an enclosing class method. The way to deal with this is to say "WorkSpace.this.add()" -- which refers directly to the enclosing object.

There's one more piece of magic voodoo you need: when you make a change to the layout of a container that's actually visible on screen, as here, you need to call validate() on the container which tells the LayoutManager to fix things up.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you need is an instance of WorkScreen's contentPane or main panel of sorts. Then you need to add your PatientAdd panel (assuming PatientAdd extends JPanel) to that panel. Sooo, something like...



FYI - PatientAdd would be better named something like PatientPanel. Makes more sense when you are looking at your code 6 months from now wondering what the hell you were doing 6 months ago.
 
Al Wells
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You guys are great! I absolutely get it, fixed it and it worked just like it should.

Have a great holiday!

Al
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic