I've checked How can I remove a JPanel from a JFrame? but when I tried to do frame.remove(mainScreen)
the whole thing just froze. I also tried mainScreen.setVisible(false)
; but that showed the balls but they were static (they should move).
// important variables
FlowLayout fL = new FlowLayout();
// create frame
JFrame frame = new JFrame("Ball");
frame.setTitle("GaoMolecules");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500,500);
frame.setResizable(false);
Rectangle fDim = frame.getBounds(); // frameDimensions
// add panel to frame
JPanel mainScreen = new JPanel();
mainScreen.setLayout(fL);
fL.setAlignment(FlowLayout.TRAILING);
frame.add(mainScreen);
// other panel components
JTextField numBallsField = new JTextField(4);
JLabel numBallsLabel = new JLabel("Enter the number of balls to generate");
JButton startButton = new JButton("START");
mainScreen.add(numBallsLabel);
mainScreen.add(numBallsField);
mainScreen.add(startButton);
// add listener to button
startButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
//System.out.println("Button Working!");
mainScreen.setVisible(false);
frame.add(new DrawManager());
start = true;
}
});
// this needs to be the very LAST
frame.setVisible(true);