Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package projboton;
- 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 classboton extends JFrame {
- private final JButton plainJButton;
- private final JButton fancyJButton;
- public classboton(){
- super( "Teste de Botões" );
- setLayout( new FlowLayout() );
- plainJButton = new JButton("Opção 1");
- add( plainJButton );
- Icon bug1 = new ImageIcon( getClass().getResource( "Lula.png" ));
- Icon bug2 = new ImageIcon( getClass().getResource( "oi2.jpg" ));
- fancyJButton = new JButton( "Melhor Presidente", bug1 );
- fancyJButton.setRolloverIcon(bug2);
- add ( fancyJButton );
- ButtonHandler handler = new ButtonHandler();
- fancyJButton.addActionListener( handler );
- plainJButton.addActionListener ( handler );
- }
- public class ButtonHandler implements ActionListener{
- public void actionPerformed( ActionEvent event){
- JOptionPane.showMessageDialog(classboton.this, String.format("Você escolheu a(o): %s", event.getActionCommand()));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement