Advertisement
rdsedmundo

Login.java

Jan 31st, 2014
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.60 KB | None | 0 0
  1. package gui;
  2.  
  3. import java.awt.Container;
  4. import java.awt.GridLayout;
  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. import javax.swing.JOptionPane;
  12. import javax.swing.JPasswordField;
  13. import javax.swing.JTextField;
  14.  
  15. public class Sistema extends JFrame {
  16.  
  17.     private static final long serialVersionUID = -4673040337179571462L;
  18.  
  19.     JButton logar = new JButton("Logar");
  20.     JButton cancelar = new JButton("Cancelar");
  21.    
  22.     JTextField nome = new JTextField();
  23.     JPasswordField senha = new JPasswordField();
  24.  
  25.     private class ListenEvent implements ActionListener {
  26.  
  27.         @Override
  28.         public void actionPerformed(ActionEvent e) {
  29.             if (e.getSource() == logar) {
  30.                 JOptionPane.showMessageDialog(null, "Nome: " + nome.getText().toString() + "\n" + "Senha: " + senha.getPassword().toString());
  31.             } else if(e.getSource() == cancelar){
  32.                 nome.setText("");
  33.                 senha.setText("");
  34.             }
  35.         }
  36.  
  37.     }
  38.  
  39.     public Sistema() {
  40.         super("Sistema de Login");
  41.  
  42.         Container panContainer = getContentPane();
  43.         panContainer.setLayout(new GridLayout(3, 2));
  44.  
  45.         panContainer.add(new JLabel("Login: "));
  46.         panContainer.add(nome);
  47.         panContainer.add(new JLabel("Senha: "));
  48.         panContainer.add(senha);
  49.         panContainer.add(logar);
  50.         panContainer.add(cancelar);
  51.  
  52.         logar.addActionListener(new ListenEvent());
  53.         cancelar.addActionListener(new ListenEvent());
  54.  
  55.         setDefaultCloseOperation(EXIT_ON_CLOSE);
  56.         setSize(300, 300);
  57.         setVisible(true);
  58.     }
  59.  
  60.     public static void main(String[] args) {
  61.         new Sistema();
  62.     }
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement