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 fancyButton;
- public ButtonFrame(){
- super("Testando Botões");
- setLayout(new FlowLayout());
- plainJButton = new JButton("Botão Simples");
- add(plainJButton);
- Icon bug1 = new ImageIcon(getClass().getResource("bug1.gif"));
- Icon bug2 = new ImageIcon(getClass().getResource("bug2.gif"));
- fancyButton = new JButton("Botão Feito", bug1);
- fancyButton.setRolloverIcon(bug2);
- add(fancyButton);
- ButtonHandler handler = new ButtonHandler();
- fancyButton.addActionListener(handler);
- plainJButton.addActionListener(handler);
- }
- private class ButtonHandler implements ActionListener{
- public void actionPerformed(ActionEvent event){
- JOptionPane.showMessageDialog(ButtonFrame.this, String.format("Pressionado: %", event.getActionCommand()));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement