i need help, for some reason i cannot remove items that i have added to my JPanels
the welcome.remove will is causing a problem
// The "RunescapeCalc" class.
import java.awt.*;
import hsa.Console;
import javax.swing.*;
import java.awt.event.*;
import sun.audio.*;
import java.io.FileInputStream;
import java.math.*;
public class Game1 extends JFrame implements ActionListener
{
JPanel welcome;
Container contentPane;
JLabel startingText;
JTextField startingField;
JButton startGame;
JMenu menu;
JMenu file;
JMenuBar menuBar;
JMenuItem Quit;
Color menuColor = new Color (200, 255, 100);
public Game1 ()
{
welcome = new JPanel (); // Initializing JPanel as RsPane
welcome.setLayout (null); // the setup is null meaning I chose what goes where
contentPane = getContentPane (); // getting the content pane
contentPane.add (welcome); // adding the JPanel to the content pane
SwingUtilities.updateComponentTreeUI (contentPane); //UPDATES!!!!
validate (); // this method sets everything up in the out put screen
start ();
}
public void start ()
{
JLabel startingText = new JLabel ("What is your name?");
startingText.setBounds (50, 50, 200, 50);
JTextField startingField = new JTextField (8);
startingField.setBounds (200, 65, 200, 25);
JButton startGame = new JButton ("Enter");
startGame.setActionCommand ("startgame");
startGame.addActionListener (this);
startGame.setBounds (125, 150, 150, 50);
SwingUtilities.updateComponentTreeUI (contentPane); //UPDATES!!!!
menuBar = new JMenuBar (); //creates menuBar
menuBar.setBackground (menuColor); //colors the menubar
setJMenuBar (menuBar);
file = new JMenu ("File"); //creates the menu file
file.setBackground (menuColor); //colors the menu
Quit = new JMenuItem ("Quit"); //creates the quit
Quit.setBackground (menuColor); //colors the quit
Quit.setActionCommand ("exit"); //sets the action name as exit
Quit.addActionListener (this); // tells the computer that this is the action name
file.add (Quit); //adds the quit
menuBar.add (file); //adds the menu to the menu bar
welcome.add (startingText);
welcome.add (startingField);
welcome.add (startGame);
contentPane.add (welcome);
}
public void stageOne ()
{
// contentPane.add (welcome);
}
public void actionPerformed (ActionEvent e)
{
String event = e.getActionCommand ();
if (event.equals ("exit"))
{
hide ();
System.exit (0);
}
if (event.equals ("startgame"))
{
String name;
name = startingField.getText ();
welcome.remove (startingText);
welcome.remove (startingField);
welcome.remove (startGame);
stageOne ();
}
}
public static void main (String[] args)
{
Game1 window = new Game1 (); // creating a windown called GasStation
window.setTitle ("Game 1"); // Giving the window a title
window.setSize (900, 700); // giving the size of the window
window.setVisible (true); // asking if this true
}
}