Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 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 ButtonFrame extends JFrame {
  11.  
  12. private JButton plainJButton;
  13. private JButton imageJButton;
  14.  
  15. public ButtonFrame(){
  16. super("Testing Buttons");
  17. setLayout(new FlowLayout());
  18.  
  19. plainJButton = new JButton ("Plain Button");
  20. add(plainJButton);
  21.  
  22. Icon tim = new ImageIcon (getClass().getResource("tim.png"));
  23. Icon tam = new ImageIcon (getClass().getResource("tam.jpg"));
  24. imageJButton = new JButton ("Image Button",lucas);
  25. imageJButton.setRolloverIcon(tam);
  26. add(imageJButton);
  27.  
  28. ButtonHandler handler = new ButtonHandler();
  29. plainJButton.addActionListener(handler);
  30. imageJButton.addActionListener(handler);
  31. }
  32.  
  33. private class ButtonHandler implements ActionListener{
  34.  
  35. public void actionPerformed(ActionEvent event){
  36. JOptionPane.showMessageDialog(ButtonFrame.this, String.format("You pressed: %s", event.getActionCommand()));
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement