Skip to content

Instantly share code, notes, and snippets.

@leoneferreira
Created November 14, 2012 11:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leoneferreira/4071655 to your computer and use it in GitHub Desktop.
Save leoneferreira/4071655 to your computer and use it in GitHub Desktop.
Class Login
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.TextEvent;
import java.awt.event.TextListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
class Login extends JFrame implements ActionListener, TextListener
{
JLabel L1,L2;
JTextField T1,T2;
JButton B1,B2;
public int i=0;
public static void main (String[] args) {
{
JFrame Janela=new Login() {};
Janela.show();
//para fechar a janela
WindowListener x = new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
};
Janela.addWindowListener(x);
}
}
Login()
{
setTitle("Login");
setSize(200,150);
setLocation(550,150);
getContentPane().setBackground(Color.white);
getContentPane().setLayout(new GridLayout(3,3,5,2));
L1 = new JLabel("Usuário");
L1.setForeground(Color.black);
L2 = new JLabel("Senha");
L2.setForeground(Color.black);
B1 = new JButton ("Logar"); B1.addActionListener(this);
B2 = new JButton ("Cancelar"); B2.addActionListener(this);
T1 = new JTextField("");
T2 = new JPasswordField("");
T1.setEditable(true);
T2.setEditable(true);
getContentPane().add(L1);//usuario
getContentPane().add(T1);//usuario
getContentPane().add(L2);//senha
getContentPane().add(T2);//adciona o label 1
getContentPane().add(B1);//adiciona o texto 1
getContentPane().add(B2);
}
public void actionPerformed(ActionEvent e) {
String user="Robson",Pass="123teste";
if (e.getSource()==B1){
if(i<=3 && user.equals(T1.getText())&& Pass.equals(T2.getText()) )
{
Banco page = new Banco();// altertar "banco" para o nome da classe que vai ser chamada
Login page2 = new Login();
page.setVisible(true);
setVisible(false);
}
else{
if(i>=3){
JOptionPane.showMessageDialog(null, "Usuario foi Bloqueado", "Bloqueado", JOptionPane.OK_OPTION);
System.exit(0);
}
else{
JOptionPane.showMessageDialog(null, "Senha Incorreta", "Error", JOptionPane.ERROR_MESSAGE);
T1.setText("");
T2.setText("");
i++;
System.out.println(i);
}
}
}
if (e.getSource()==B2){
System.exit(0);
}
}
public void textValueChanged(TextEvent e) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment