Guest User

action listener help?

a guest
Jan 5th, 2012
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1. import javax.swing.*;
  2. import javax.swing.border.*;
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import java.lang.*;
  6.  
  7. public class sound extends JFrame implements ActionListener {
  8.     public sound() {
  9.         //makes the frame
  10.         setTitle("Click it!");
  11.         setSize(200, 200);
  12.         setResizable(false);
  13.         setLocationRelativeTo(null);
  14.         setDefaultCloseOperation(DISPOSE_ON_CLOSE);
  15.         //get content pane
  16.         Container contentPane = getContentPane();
  17.         contentPane.setLayout(null);
  18.         //make the button
  19.         JButton button = new JButton("Click me!");
  20.         button.setBounds(50, 50, 100, 50);
  21.         button.addActionListener(new ActionListener() {
  22.             public void actionPerformed(ActionEvent e) {
  23.                 public void run() {
  24.                     JOptionPane.showMessageDialog(null, "It works!");
  25.                 }
  26.             }
  27.         });
  28.         contentPane.add( button );
  29.     }
  30.    
  31.     public static void main (String [] args) {
  32.         sound frame = new sound();
  33.         frame.setVisible(true);
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment