Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Class change under same window

 
Rocky Summers
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey ranchers..
I'm having problems with screen transitions... I have this a Class_A.java and Class_B.java ... when i click a JButton in my Class_A.java, I want it to go to Class_B.java under the same window... is there any way that i can do that without windows popping? Thank you for your time.
~ Rockster
 
Rocky Summers
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi. i dont think i explained this very post very well.. okay i'm going to explain it step by step..
i have 4 classes altogether: Controller.java, Class_A.java, Class_B.java, and Actions.java... Controller.java controls the panel switching between class_a and class_b. Actions.java listens to all the actions within Class_A and Class_B.
in my controller class, i declared these as global:

Two important methods in my controller class are the "switch" methods:

and....

now in my main method, it looks like this:

in that one where it says getPanel() can be found in both of my class_a and class_b..

I declared "public static JPanel panel = new JPanel();" globally.
When the user clicks button b1, my Action.java listens to whatever button was clicked:

It successfully calls cont.switchToClassB() and cont.switchToClassA() but it doesnt display it correctly. (ie when i am in class_a, i click the button to go to class_b but it only displays a blank screen)...
Please help...
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems you're having trouble with the removing/adding to the JFrame part of this. So I made this demo up to focus on this aspect.

And along the way, these first two lines are unnecessary since the call to b.getPanel() in line 3 returns a JPanel

Generally you remove a component, add another component, then validate the layout and possibly/usually repaint. validate is a Container method used below to ask the JFrames content pane to layout its components again. revalidate is a Component method used in the same way, eg, redPanel.revalidate().

Try commenting out the calls to validate and repaint to see what happens.
 
Rocky Summers
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help!! It works awesome!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!