Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

GUI building help please!!!!!!!  RSS feed

 
m dawg
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,
I have a JFrame that is 800 X 600. Ok in this JFrame i have a JMenuBar. On the JMenuBar i have a Menu called modes. In this i have two modes one is a runmode and the other will allow the user to build so it is a build mode. My problem is creating these JPanels in the JFrame. But, i don't want them to be on at the same time. Say if one is clicked the other will go away but no lose any data and the other will appear. These JPanels will be about 500X500. I can't get it to show up. I do have the buildmode as a class and the same as the runmode. I really need help if anyone can help me. PLEASE!!! Some sample code could get me going this is what i have so far. I know there are problems please help. I can't get anything. I also have the actionPerformed ready to go with no code in it so that it will go to different frames. Oh yea, there should be a main because the objects on the main screen needs to stay because the diffent thing about the build mode it that it draws a grid where you place objects but it will have some buttons too. Please help thanks

private JPanel buildmode, runmode;
private Dimension bmDim;
private Dimension rmDim;
public GizmoBallGUI() {
initComponents();
setTitle("GizmoBall");
setSize(WIDTH, HEIGHT);
Container contentPane = getContentPane();
buildmode = new JPanel();
buildmode.setLayout(new BorderLayout());
buildmode.setBackground(Color.white);
contentPane.add(buildmode);
bmDim = new Dimension();
bmDim.setSize(500, 500);
buildmode.add(BorderLayout.CENTER, bmDim);
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might look at CardLayout. Put your JPanel components on a card and flip to the card you want when the menu item is clicked.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
m dawg,

Please read the JavaRanch offial policy on usernames. Names must be in the form "First Name" + space + "Last Name", in which first and last names are longer than 1 letter, and names cannot be obviously ficticious.

Thanks,
-Nate
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I would suggest using a JDesktopPane with JInternalFrames. This sounds like the approach you need to take. You can use this method, JInternalFrame.setVisible(boolean), to set the frame visible or not visible, and not lose any data stored in the frame. If you like this idea, check out java.sun.com and the Swing Tutorial and look at JDesktopPane and JInernalFrames. If you have any questions on this, you can E-mail me at Gregg.Bolinger@intrustbank.com. I use these components ALL the time.

------------------
Happy Coding,
Gregg Bolinger
 
m dawg
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all,
i really appreciate all your help!!! If anyone one has any examples please post them thanks.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So did you come to any decision on which way to go? Are you sticking with your JFrame or using a DesktopPane.
Another approach is you could use a JTabbedPane and just disable and enable the panels as needed.
How well do you know Swing, or are you using AWT?
Going through the tutorial and reading some of the API is a really good place to start.

------------------
Happy Coding,
Gregg Bolinger
 
m dawg
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gregg,
Hey, i am haveing some problems. Ok, what i want to be able to do is: Ok, i have a GUI aready built. I have a JMenuBar and on this i have file, edit, modes, help. Ok What i want to be able to do is when i click on modes in this i have the option to click on build mode. this should open on my JFrame as a JPanel that is 500x500, by the way my JFrame itself is 800x600. Ok, and on this build panel i am able to add things to it like a circle and a square and so on. they should click into place. on my build mode panel i have a grid that is each grid box is 25x25, that is easy to make. Ok, now when i go back up to the modes menu and then click on run mode, the grey grid lines will go away and the objecs will still be in the same place. When i ad a ball, then i will have to click the start button for the ball to move and bounce off the objects. My problem is doing the if(command.equals(RunMode){
//is this what i should do and also for the build mode should i do the same thing and in this have two for loops that make the grid thing.
Gregg i really need some help on this on. I would really appreciate it if you could if not i would completely understand. thanks for you time to post back to me
mdawg
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you have so far?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!