ActionListener not working..please help


Joined
Jul 22, 2011
Messages
3
Reaction score
0
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;


public class CheckAction {

public static void main(String[] args){

JFrame frame = new JFrame("Test");
frame.setSize(200,200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);

JPanel panel=new JPanel();
frame.add(panel);

JButton button=new JButton("Click Here!");

panel.add(button);
button.addActionListener(new action());
}
static class action implements ActionListener{


public void actionPerformed(ActionEvent e) {
JFrame frame1=new JFrame("Clicked");
frame1.setVisible(true);
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame1.setSize(200,200);

JLabel label1=new JLabel("You Clicked Me!");

JPanel panel=new JPanel();

frame1.add(panel);
panel.add(label1);

}


}


}
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top