Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package buttontest;
- import java.awt.FlowLayout;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import javax.swing.JFrame;
- import javax.swing.JButton;
- import javax.swing.Icon;
- import javax.swing.ImageIcon;
- import javax.swing.JOptionPane;
- public class BUttonFrame extends JFrame {
- private JButton plainJButton;
- private JButton fancyJButton;
- public BUttonFrame(){
- super("Testing Buttons");
- setLayout(new FlowLayout());
- plainJButton = new JButton("Plain Button");
- add(plainJButton);
- Icon bug1 = new ImageIcon(getClass().getResource("bug1.jpg"));
- Icon bu2 = new ImageIcon(getClass().getResource("bu2.jpg"));
- fancyJButton = new JButton ("Fancy Button" , bug1);
- fancyJButton.setRolloverIcon(bu2);
- add(fancyJButton);
- ButtonHandler handler = new ButtonHandler();
- fancyJButton.addActionListener(handler);
- plainJButton.addActionListener(handler);
- }
- private class ButtonHandler implements ActionListener{
- public void actionPerformed (ActionEvent event){
- JOptionPane.showMessageDialog(BUttonFrame.this, String.format("You pressed: %s", event.getActionCommand()));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement