Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package testebotao;
- 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 Botao extends JFrame{
- private JButton pB;
- private JButton fB;
- public Botao(){
- super("Testando botões");
- setLayout(new FlowLayout());
- pB = new JButton("Botão com texto");
- add(pB);
- Icon img1 = new ImageIcon(getClass().getResource("img1.jpg"));
- Icon img2 = new ImageIcon(getClass().getResource("img2.jpg"));
- fB = new JButton("Botão com imagem",img1);
- fB.setRolloverIcon(img2);
- add(fB);
- ButtonHandler bm = new ButtonHandler();
- fB.addActionListener(bm);
- pB.addActionListener(bm);
- }
- private class ButtonHandler implements ActionListener{
- public void actionPerformed( ActionEvent event){
- JOptionPane.showMessageDialog(Botao.this, String.format("Você pressionou: %s", event.getActionCommand()));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement