Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 imageJButton;
- public ButtonFrame(){
- super("Testing Buttons");
- setLayout(new FlowLayout());
- plainJButton = new JButton ("Plain Button");
- add(plainJButton);
- Icon tim = new ImageIcon (getClass().getResource("tim.png"));
- Icon tam = new ImageIcon (getClass().getResource("tam.jpg"));
- imageJButton = new JButton ("Image Button",lucas);
- imageJButton.setRolloverIcon(tam);
- add(imageJButton);
- ButtonHandler handler = new ButtonHandler();
- plainJButton.addActionListener(handler);
- imageJButton.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