Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. package testebotao;
  2. import java.awt.FlowLayout;
  3. import java.awt.event.ActionListener;
  4. import java.awt.event.ActionEvent;
  5. import javax.swing.JFrame;
  6. import javax.swing.JButton;
  7. import javax.swing.Icon;
  8. import javax.swing.ImageIcon;
  9. import javax.swing.JOptionPane;
  10. public class Botao extends JFrame{
  11. private JButton pB;
  12. private JButton fB;
  13.  
  14. public Botao(){
  15. super("Testando botões");
  16. setLayout(new FlowLayout());
  17. pB = new JButton("Botão com texto");
  18. add(pB);
  19. Icon img1 = new ImageIcon(getClass().getResource("img1.jpg"));
  20. Icon img2 = new ImageIcon(getClass().getResource("img2.jpg"));
  21. fB = new JButton("Botão com imagem",img1);
  22. fB.setRolloverIcon(img2);
  23. add(fB);
  24. ButtonHandler bm = new ButtonHandler();
  25. fB.addActionListener(bm);
  26. pB.addActionListener(bm);
  27. }
  28. private class ButtonHandler implements ActionListener{
  29. public void actionPerformed( ActionEvent event){
  30. JOptionPane.showMessageDialog(Botao.this, String.format("Você pressionou: %s", event.getActionCommand()));
  31. }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement