The Artima Developer Community
Sponsored Link

Java Answers Forum
Making a Menu System out of JFrame

2 replies on 1 page. Most recent reply: Nov 17, 2002 7:04 PM by Palle Jensen

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Kasim Hanif

Posts: 11
Nickname: kasim
Registered: Apr, 2002

Making a Menu System out of JFrame Posted: Nov 17, 2002 2:51 PM
Reply to this message Reply
Advertisement
Hi,

Im trying to create a menu system using Jframe, but the trouble is how do i get additional JFrames, i.e. forms, to appear when selecting certain options. I want at least several forms to appear (in a neat order) according to certain buttons the user presses. I know i would have to create a Jframe class, and have each form as a different constructor within this class, but then how would i tie it all together in main?


import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;


public class myFrameDemo
{
public static void main(String[] argx)
{
myFrame w1 = new myFrame();
w1.setVisible(true);
myFrame w2 = new myFrame();
w2.setVisible(false);


}

}

class myFrame extends JFrame implements ActionListener
{

public static final int WIDTH = 600;
public static final int HEIGHT = 300;
private Container c;
private JPanel north, east, south, west;
private JButton button1;

public myFrame()
{

super();
setSize(WIDTH, HEIGHT);
setTitle("Main Menu");
c = getContentPane();
c.setLayout(new BorderLayout());
c.setBackground(Color.black);

north = new JPanel();
north.setBackground(Color.black);
c.add(north, BorderLayout.NORTH);


button1 = new JButton("Option1");
button1.addActionListener(this);
button1.setForeground(Color.gray);
button1.setBackground(Color.black);
button1.setBorder(new EmptyBorder(2,2,2,2));
button1.setFont(new Font("Verdana", Font.PLAIN , 10));
north.add(button1);

east = new JPanel();
east.setBackground(Color.black);
c.add(east, BorderLayout.EAST);
}//additional form constructors can go here

public void actionPerformed(ActionEvent event)
{
if (event.getSource() == button1)
{

w2.setVisible(true); // i get an error as it doesnt know what this is?!??? so how do i pop this form up
}
}
}


Thank You,


Palle Jensen

Posts: 6
Nickname: palle
Registered: Nov, 2002

Re: Making a Menu System out of JFrame Posted: Nov 17, 2002 3:21 PM
Reply to this message Reply
Hi, try w2.show(), should work

Palle Jensen

Posts: 6
Nickname: palle
Registered: Nov, 2002

Re: Making a Menu System out of JFrame Posted: Nov 17, 2002 7:04 PM
Reply to this message Reply
hi again, as i looked down the code i discovered that the ref. w2 isent visible for the class MyFrame, maby thats the problem

Flat View: This topic has 2 replies on 1 page
Topic: a for loop that needs explaing Previous Topic   Next Topic Topic: Show picture stored in database

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use