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
posted 15 years ago
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:
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...
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.
posted 15 years ago
Thanks for the help!! It works awesome!
I wish to win the lottery. I wish for a lovely piece of pie. And I wish for a tiny ad:
how do I do my own kindle-like thing - without amazon