Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • 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
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Class change under same window  RSS feed

 
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...
 
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!
 
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
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!