• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Class change under same window

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help!! It works awesome!
 
reply
    Bookmark Topic Watch Topic
  • New Topic