Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.awt.*;
  4. import java.awt.event.ActionEvent;
  5. import javax.swing.*;
  6. import java.awt.event.ActionListener;
  7.  
  8. public class ButtonFrame extends JFrame{
  9. private JButton plainJButton;
  10. private JButton fancyJButton;
  11.  
  12. public ButtonFrame() {
  13.  
  14. super("Testing Buttons");
  15. setLayout(new FlowLayout());
  16.  
  17. plainJButton = new JButton("Plain Button");
  18. add(plainJButton);
  19.  
  20. Icon bug1 = new ImageIcon(getClass().getResource("bug1.jpg"));
  21. Icon bug2 = new ImageIcon(getClass().getResource("bug2.jpg"));
  22. fancyJButton = new JButton("Fancy Button", bug1);
  23. fancyJButton.setRolloverIcon(bug2);
  24. add(fancyJButton);
  25.  
  26. ButtonHandler handler = new ButtonHandler();
  27. fancyJButton.addActionListener(handler);
  28. plainJButton.addActionListener(handler);
  29. }
  30.  
  31. private class ButtonHandler implements ActionListener{
  32. public void actionPerformed(ActionEvent event){
  33. JOptionPane.showMessageDialog(ButtonFrame.this,String.format("Você apertou: %s",event.getActionCommand()));
  34. }
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement