• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Replacing GUI with new GUI

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, pretty simple question and I think I am just not grasping the concept entirely...

So I have two classes, QuestionBuilder and QuestionReader. The first one allows me to create Questions and Answers and store them. The second one reads, does not allow a user to edit. Both have a load option, only Builder has a save option.

Anyway, long story short, I'd have to call both of these from the command line separately, or package them separately, or whatever I do--it would have to be separate. In an effort to combine these, I made a "QuestionProgram" class. When I run it, it starts with a gui that is the same size as the other programs. Then, in the menuBar, I have an option to "Open Builder" or "Open Reader".

I can click one, and it opens... perfect!

However, it just opened in a new window.

While I like being able to have multiple windows, I'd really like the ability to change my current GUI with the new GUI, all while staying in the same frame. The basic operation for each class is to run the "go" method, which initializes the GUI.


So... how do I do that? Pass it the same frame? Repaint? I'm not really sure what method/strategy I should be using, here...


Any help is appreciated, thanks!
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't know; I don't think we have enough details yet.

This would sit better on our GUI forum. Moving.
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I'd really like the ability to change my current GUI with the new GUI, all while staying in the same frame.



What you need is a single JFrame, then you create multiple JPanels that can be used by the frame. The panels can easily be swapped in/out by using the CardLayout. Read the Swing tutorial on "How to Use Card Layout" for a working example.
 
Brian Drelling
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Campbell, sorry about posting in the wrong place--I didn't know there was a GUI forum. Also wasn't sure how complex my question was and if it was beyond a beginner.

As for details, without posting buckets of code, I thought I had given enough details... I'm not sure what code to give that would be helpful to see, really. What more should I post? (I did read the link--I am still not sure how this applies to my scenario. My program isn't giving an error, and it is acting as expected given the code--I just don't know how to make it change to act as I really expect it.)

Rob, I took a look at http://java.sun.com/docs/books/tutorial/uiswing/layout/card.html to get an idea of what it would be doing. I think it should be easy to apply the situation to a menu item, and it does make sense... I'll take a look when I get home. Thank you so much!
 
Campbell Ritchie
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Brian Drelling wrote:Campbell, sorry . . .

That's all right
 
Brian Drelling
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alright, so I am going to post my code and hope that it isn't too much... not sure if there is a limit, but I don't know any other way to figure out how to do what I want it to do.

I have three classes:

QuestionBuilder
QuestionReader
QuestionProgramTestDrive

QuestionBuilder is meant to allow someone to edit questions

QuestionReader is meant to allow someone only to view questions and navigate through them

QuestionProgramTestDrive is essentially a copy of them with very few components that will allow you to open one of those two programs within a single frame. I was going to add a way to change between the components in each component as well, but perhaps I could have them share a menubar or something. I'm sure I don't have to recreate it each time.

Anyway, I'm not sure if what I have to be doing is hiding all the components and loading them when called, or what... so here is my code and hopefully someone can shed some light:





I can post the referenced programs but maybe it doesn't make a difference?

Inside each of the go() functions for both programs, they are simply used to create and load GUI. I am just calling the function that loads the GUI and passing in no arguments. So do I have to pass in the frame I am using, or what?

Thanks for the help in advance. If I need to post any more, just let me know.
reply
    Bookmark Topic Watch Topic
  • New Topic