Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 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. private JButton plainJButton;
  12. private JButton fancyButton;
  13.  
  14. public ButtonFrame(){
  15.  
  16. super("Testando Botões");
  17. setLayout(new FlowLayout());
  18.  
  19. plainJButton = new JButton("Botão Simples");
  20. add(plainJButton);
  21.  
  22. Icon bug1 = new ImageIcon(getClass().getResource("bug1.gif"));
  23. Icon bug2 = new ImageIcon(getClass().getResource("bug2.gif"));
  24. fancyButton = new JButton("Botão Feito", bug1);
  25. fancyButton.setRolloverIcon(bug2);
  26. add(fancyButton);
  27.  
  28. ButtonHandler handler = new ButtonHandler();
  29. fancyButton.addActionListener(handler);
  30. plainJButton.addActionListener(handler);
  31.  
  32. }
  33.  
  34. private class ButtonHandler implements ActionListener{
  35. public void actionPerformed(ActionEvent event){
  36. JOptionPane.showMessageDialog(ButtonFrame.this, String.format("Pressionado: %", event.getActionCommand()));
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement