Like I said the JButton GR
is set to the default size (size of window) when I click JButton MN
.
When the program is started the JButton GR
has the right size (200 by 20), when clicked the menu button appears also at the right size (200 by 20), but when the menu button is clicked the GR JButton
is at its default size. When the full size GR JButton
is clicked the Menu button reappears with the right size.
I'm using BlueJ (school dose not allow other IDEs).
import java.util.Scanner;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JButton;
public class MAIN
{
public static void main(String args[])
{
ActionClass actionEvent = new ActionClass();
//Main window
JFrame Program1 = new JFrame("Program1");
Program1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Program1.setPreferredSize(new Dimension(800, 600));
Program1.pack();
Program1.setVisible(true);
//menu button (returns to home Menu)
JButton MN = new JButton("MENU");
MN.setBounds(300, 10, 200, 20);
MN.setVisible(false);
Program1.add (MN);
//MN.setActionCommand("1");
// Enter GRC
JButton GR = new JButton("GRC");
GR.setBounds(300, 40, 200, 20);
GR.setVisible(true);
Program1.add (GR);
//GR.setActionCommand("2");
GR.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent GRH)
{
MN.setVisible(true);
GR.setVisible(false);
}
}
);
MN.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent MNH)
{
MN.setVisible(false);
GR.setVisible(true);
}
}
);
}
}