Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package gui;
- import java.awt.Container;
- import java.awt.GridLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JPasswordField;
- import javax.swing.JTextField;
- public class Sistema extends JFrame {
- private static final long serialVersionUID = -4673040337179571462L;
- JButton logar = new JButton("Logar");
- JButton cancelar = new JButton("Cancelar");
- JTextField nome = new JTextField();
- JPasswordField senha = new JPasswordField();
- private class ListenEvent implements ActionListener {
- @Override
- public void actionPerformed(ActionEvent e) {
- if (e.getSource() == logar) {
- JOptionPane.showMessageDialog(null, "Nome: " + nome.getText().toString() + "\n" + "Senha: " + senha.getPassword().toString());
- } else if(e.getSource() == cancelar){
- nome.setText("");
- senha.setText("");
- }
- }
- }
- public Sistema() {
- super("Sistema de Login");
- Container panContainer = getContentPane();
- panContainer.setLayout(new GridLayout(3, 2));
- panContainer.add(new JLabel("Login: "));
- panContainer.add(nome);
- panContainer.add(new JLabel("Senha: "));
- panContainer.add(senha);
- panContainer.add(logar);
- panContainer.add(cancelar);
- logar.addActionListener(new ListenEvent());
- cancelar.addActionListener(new ListenEvent());
- setDefaultCloseOperation(EXIT_ON_CLOSE);
- setSize(300, 300);
- setVisible(true);
- }
- public static void main(String[] args) {
- new Sistema();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement