Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.16 KB | None | 0 0
  1. package principal;
  2.  
  3. import java.awt.Color;
  4. import java.awt.FlowLayout;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7.  
  8. import javax.swing.JButton;
  9. import javax.swing.JFrame;
  10. import javax.swing.JLabel;
  11.  
  12. public class Form extends JFrame implements ActionListener{
  13.    
  14.     private JButton botao;
  15.     private JButton botao2;
  16.     private JLabel label;
  17.    
  18.     public Form(){
  19.         super("Meu Formulario");
  20.         this.setLayout(new FlowLayout());
  21.         this.setBounds(100,100,640,400);   
  22.         this.setDefaultCloseOperation(EXIT_ON_CLOSE);
  23.        
  24.        
  25.         botao = new JButton("OK");
  26.         botao.setBackground(new Color(255, 135, 200 ));
  27.         this.add(botao);
  28.         botao.addActionListener(this);
  29.        
  30.         botao2 = new JButton("Cancelar");
  31.         this.add(botao2);
  32.         botao2.addActionListener(this);
  33.        
  34.         label = new JLabel("Oh my God!");
  35.         this.add(label);
  36.        
  37.        
  38.     }
  39.    
  40.    
  41.     public static void main(String[] args) {
  42.         new Form().setVisible(true);
  43.     }
  44.  
  45.  
  46.     @Override
  47.     public void actionPerformed(ActionEvent evento) {
  48.         if(evento.getSource()==botao){
  49.             label.setText("OK Clicado...");
  50.         }
  51.         if(evento.getSource()==botao2){
  52.             label.setText("Cancelar Clicado...");  
  53.         }
  54.        
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement