Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.FlowLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.Icon;
- import javax.swing.ImageIcon;
- import javax.swing.JOptionPane;
- public class ButtonFrame extends JFrame {
- private JButton botaotext;
- private JButton botaoicon;
- public ButtonFrame(){
- super("Testing Buttons");
- setLayout(new FlowLayout());
- botaotext = new JButton("Botao com Texto");
- add(botaotext);
- Icon bot = new ImageIcon(getClass().getResource("botao.png"));
- Icon boom = new ImageIcon(getClass().getResource( "boom.png"));
- botaoicon = new JButton("Botao com icone",bot);
- botaoicon.setRolloverIcon(boom);
- add(botaoicon);
- ButtonHandler handler = new ButtonHandler();
- botaoicon.addActionListener(handler);
- botaotext.addActionListener(handler);
- }
- private class ButtonHandler implements ActionListener{
- public void actionPerformed(ActionEvent event){
- JOptionPane.showMessageDialog(ButtonFrame.this,String.format("voce precionou: %s",event.getActionCommand() ));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement