Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. package buttontest;
  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.  
  13. public class BUttonFrame extends JFrame {
  14. private JButton plainJButton;
  15. private JButton fancyJButton;
  16.  
  17. public BUttonFrame(){
  18. super("Testing Buttons");
  19. setLayout(new FlowLayout());
  20.  
  21. plainJButton = new JButton("Plain Button");
  22. add(plainJButton);
  23.  
  24. Icon bug1 = new ImageIcon(getClass().getResource("bug1.jpg"));
  25. Icon bu2 = new ImageIcon(getClass().getResource("bu2.jpg"));
  26. fancyJButton = new JButton ("Fancy Button" , bug1);
  27. fancyJButton.setRolloverIcon(bu2);
  28. add(fancyJButton);
  29.  
  30. ButtonHandler handler = new ButtonHandler();
  31. fancyJButton.addActionListener(handler);
  32. plainJButton.addActionListener(handler);
  33.  
  34. }
  35. private class ButtonHandler implements ActionListener{
  36. public void actionPerformed (ActionEvent event){
  37. JOptionPane.showMessageDialog(BUttonFrame.this, String.format("You pressed: %s", event.getActionCommand()));
  38. }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement