This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Dynamic Swing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Dynamic Swing" Watch "Dynamic Swing" New topic
Author

Dynamic Swing

Al Wells
Ranch Hand

Joined: Apr 18, 2005
Posts: 87
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.

Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

"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.


[Jess in Action][AskingGoodQuestions]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.


GenRocket - Experts at Building Test Data
Al Wells
Ranch Hand

Joined: Apr 18, 2005
Posts: 87
You guys are great! I absolutely get it, fixed it and it worked just like it should.

Have a great holiday!

Al
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dynamic Swing
 
Similar Threads
Missing Components
Identifying which button in array is pressed
Images in a LayerPane wont show up.
coding a texteditor: want to open a separate option window
Not to show the ellipse?