Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package maisumpacote;
- 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 ("Botão plano");
- add(plainJButton);
- Icon ricardo = new ImageIcon (getClass().getResource("ricardo.png"));
- Icon jonas = new ImageIcon (getClass().getResource("jonas.jpg"));
- imageJButton = new JButton ("botão de i",ricardo);
- imageJButton.setRolloverIcon(jonas);
- 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("Você pressou: %s", event.getActionCommand()));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement