error when ActionPerformed is activated
I have JPanel with a button which when press should send me to another
screen, however I keep getting an error. I tried googling it but couldn't
any information about it.
here is the part of my I'm having trouble whith
CardLayout cl = new CardLayout();
setPanel = new JPanel();//panel to store the other panels
setPanel.setLayout(cl);//create the different set of windows
JButton enter = new JButton("Enter");
JPanel loginPanel = new JPanel();
loginPanel.add(enter);
loginPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
setPanel.add(loginPanel, "LoginScreen");
I have also declared a new JPanel called menuPanel which is the one to be
displayed when "enter" button is clicked, then I added it to the display.
menuPanel = new JPanel();
menuPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
setPanel.add(menuPanel, "MainMenu");
I created an event handler and added the "enter" button to it
getContentPane().add(setPanel);
//create event handler and make buttons events
theHandler handler = new theHandler();//builds an action listener object
enter.addActionListener(handler)
In my event handling class I have the following lines which are to be
executed when the button is pressed.
if(event.getSource()== enter){//getSource = where the event occurred
JOptionPane.showMessageDialog(null, "Hello");
cl.show(setPanel, "MainMenu"); <-----here is the problem
I placed the popup to see if the button was the problem, but the popup
shows when the button is pressed. So the event handling is working for the
button. The message I keep getting when I press the button.
Graphics$theHandler.actionPerformed
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
It's all like this. I have a similar code for another program but it
doesn't give me any errors. Why does it say unknown source?
No comments:
Post a Comment