Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package principal;
- import java.awt.Color;
- 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.JLabel;
- public class Form extends JFrame implements ActionListener{
- private JButton botao;
- private JButton botao2;
- private JLabel label;
- public Form(){
- super("Meu Formulario");
- this.setLayout(new FlowLayout());
- this.setBounds(100,100,640,400);
- this.setDefaultCloseOperation(EXIT_ON_CLOSE);
- botao = new JButton("OK");
- botao.setBackground(new Color(255, 135, 200 ));
- this.add(botao);
- botao.addActionListener(this);
- botao2 = new JButton("Cancelar");
- this.add(botao2);
- botao2.addActionListener(this);
- label = new JLabel("Oh my God!");
- this.add(label);
- }
- public static void main(String[] args) {
- new Form().setVisible(true);
- }
- @Override
- public void actionPerformed(ActionEvent evento) {
- if(evento.getSource()==botao){
- label.setText("OK Clicado...");
- }
- if(evento.getSource()==botao2){
- label.setText("Cancelar Clicado...");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement