ActionListener not working..please help

Discussion in 'Java' started by azmatnaseem, Sep 18, 2011.

  1. azmatnaseem

    azmatnaseem

    Joined:
    Jul 22, 2011
    Messages:
    3
    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);

    }


    }


    }
    azmatnaseem, Sep 18, 2011
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Clive Moore

    ActionListener

    Clive Moore, Dec 2, 2003, in forum: Java
    Replies:
    2
    Views:
    680
    Clive Moore
    Dec 3, 2003
  2. Chris Lawson
    Replies:
    2
    Views:
    802
    Andrew Hobbs
    Feb 5, 2004
  3. Michael
    Replies:
    6
    Views:
    3,154
    Michael
    Jul 11, 2004
  4. Jenny
    Replies:
    1
    Views:
    5,981
    Christian Kaufhold
    Aug 9, 2004
  5. 6e
    Replies:
    1
    Views:
    9,689
Loading...

Share This Page