Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. import java.awt.FlowLayout;
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4. import javax.swing.JButton;
  5. import javax.swing.JFrame;
  6. import javax.swing.Icon;
  7. import javax.swing.ImageIcon;
  8. import javax.swing.JOptionPane;
  9. public class ButtonFrame extends JFrame {
  10. private JButton botaotext;
  11. private JButton botaoicon;
  12.  
  13. public ButtonFrame(){
  14. super("Testing Buttons");
  15. setLayout(new FlowLayout());
  16. botaotext = new JButton("Botao com Texto");
  17. add(botaotext);
  18. Icon bot = new ImageIcon(getClass().getResource("botao.png"));
  19. Icon boom = new ImageIcon(getClass().getResource( "boom.png"));
  20. botaoicon = new JButton("Botao com icone",bot);
  21. botaoicon.setRolloverIcon(boom);
  22. add(botaoicon);
  23. ButtonHandler handler = new ButtonHandler();
  24. botaoicon.addActionListener(handler);
  25. botaotext.addActionListener(handler);
  26.  
  27.  
  28. }
  29. private class ButtonHandler implements ActionListener{
  30. public void actionPerformed(ActionEvent event){
  31. JOptionPane.showMessageDialog(ButtonFrame.this,String.format("voce precionou: %s",event.getActionCommand() ));
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement