Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. package maisumpacote;
  2.  
  3. import java.awt.FlowLayout;
  4. import java.awt.event.ActionListener;
  5. import java.awt.event.ActionEvent;
  6. import javax.swing.JFrame;
  7. import javax.swing.JButton;
  8. import javax.swing.Icon;
  9. import javax.swing.ImageIcon;
  10. import javax.swing.JOptionPane;
  11.  
  12. public class ButtonFrame extends JFrame {
  13.  
  14. private JButton plainJButton;
  15. private JButton imageJButton;
  16.  
  17. public ButtonFrame(){
  18. super("Testing Buttons");
  19. setLayout(new FlowLayout());
  20.  
  21. plainJButton = new JButton ("Botão plano");
  22. add(plainJButton);
  23.  
  24. Icon ricardo = new ImageIcon (getClass().getResource("ricardo.png"));
  25. Icon jonas = new ImageIcon (getClass().getResource("jonas.jpg"));
  26. imageJButton = new JButton ("botão de i",ricardo);
  27. imageJButton.setRolloverIcon(jonas);
  28. add(imageJButton);
  29.  
  30. ButtonHandler handler = new ButtonHandler();
  31. plainJButton.addActionListener(handler);
  32. imageJButton.addActionListener(handler);
  33. }
  34.  
  35. private class ButtonHandler implements ActionListener{
  36.  
  37. public void actionPerformed(ActionEvent event){
  38. JOptionPane.showMessageDialog(ButtonFrame.this, String.format("Você pressou: %s", event.getActionCommand()));
  39. }
  40.  
  41. }
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement