Advertisement
guitarman0831

Untitled

Jun 12th, 2011
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1. import java.awt.FlowLayout;
  2. import java.awt.event.ActionListener;
  3. import java.awt.event.ActionEvent;
  4. import javax.swing.JFrame;
  5. import javax.swing.JButton;
  6. import javax.swing.Icon;
  7. import javax.swing.ImageIcon;
  8. import javax.swing.JOptionPane;
  9.  
  10. public class Gui extends JFrame {
  11.     private JButton reg;
  12.     private JButton custom;
  13.    
  14.     public Gui(){
  15.         super("The Title");
  16.         setLayout(new FlowLayout());
  17.        
  18.         reg = new JButton("Reg Button");
  19.         add(reg);
  20.        
  21.         Icon b = new ImageIcon(getClass().getResource("b.png"));
  22.         Icon x = new ImageIcon(getClass().getResource("x.png"));
  23.         custom = new JButton("Custom Button", b);
  24.         custom.setRolloverIcon(x);
  25.         add(custom);
  26.        
  27.         HandlerClass handler = new HandlerClass();
  28.         reg.addActionListener(handler);
  29.         custom.addActionListener(handler);
  30.     }
  31.    
  32.     private class HandlerClass implements ActionListener {
  33.         public void actionPerformed(ActionEvent event){
  34.             JOptionPane.showMessageDialog(null, String.format("%s", event.getActionCommand()));
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement