Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. package projboton;
  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 classboton extends JFrame {
  13.  
  14. private final JButton plainJButton;
  15. private final JButton fancyJButton;
  16.  
  17.  
  18. public classboton(){
  19.  
  20. super( "Teste de Botões" );
  21. setLayout( new FlowLayout() );
  22.  
  23. plainJButton = new JButton("Opção 1");
  24. add( plainJButton );
  25.  
  26. Icon bug1 = new ImageIcon( getClass().getResource( "Lula.png" ));
  27. Icon bug2 = new ImageIcon( getClass().getResource( "oi2.jpg" ));
  28. fancyJButton = new JButton( "Melhor Presidente", bug1 );
  29. fancyJButton.setRolloverIcon(bug2);
  30. add ( fancyJButton );
  31.  
  32. ButtonHandler handler = new ButtonHandler();
  33. fancyJButton.addActionListener( handler );
  34. plainJButton.addActionListener ( handler );
  35. }
  36. public class ButtonHandler implements ActionListener{
  37.  
  38. public void actionPerformed( ActionEvent event){
  39. JOptionPane.showMessageDialog(classboton.this, String.format("Você escolheu a(o): %s", event.getActionCommand()));
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement