[code]import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class UsuarioSenha extends JFrame{
JLabel titulo,rotulo2,rotulo3;
JTextField texto1;
JPasswordField texto2;
JButton entrar;
public UsuarioSenha(){
super("Login do Sistema");
Container tela = getContentPane();
tela.setLayout(null);
titulo =new JLabel("Entre com usuario e senha");
rotulo2=new JLabel("Usuario");
rotulo3=new JLabel("Senha");
texto1 = new JTextField(15);
texto2 = new JPasswordField(15);
entrar = new JButton("Entrar");
titulo.setBounds(40,10,200,20);
rotulo2.setBounds(50,60,60,20);
rotulo3.setBounds(50,80,60,20);
texto1.setBounds(100,60,80,20);
texto2.setBounds(100,80,80,20);
entrar.setBounds(100,130,90,20);
entrar.setMnemonic(KeyEvent.VK_E);
entrar.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/teste","root","");
Statement st = con.createStatement();
ResultSet rs =st.executeQuery("select * from usuarios where usuario='"+texto1.getText()+"' and senha='"+texto2.getPassword()+"'");
rs.next();
JOptionPane.showMessageDialog(null,"Bem vindo ao sistema","User Logado",JOptionPane.INFORMATION_MESSAGE);
setVisible(false);
}
catch(Exception event){
JOptionPane.showMessageDialog(null,"Usuario não existe \n Comandos Inválidos","Mensagem do Programa",JOptionPane.ERROR_MESSAGE);
}
}});
tela.add(titulo);
tela.add(rotulo2);
tela.add(rotulo3);
tela.add(texto1);
tela.add(texto2);
tela.add(entrar);
setSize(300,200);
setVisible(true);
}
public static void main(String args[]){
UsuarioSenha app= new UsuarioSenha();
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
[/code]
[code]import javax.swing.;
import java.awt.;
import java.awt.event.;
import java.sql.;
public class UsuarioSenha extends JFrame{
JLabel titulo,rotulo2,rotulo3;
JTextField texto1;
JPasswordField texto2;
JButton entrar;
public UsuarioSenha(){
super(“Login do Sistema”);
Container tela = getContentPane();
tela.setLayout(null);
titulo =new JLabel(“Entre com usuario e senha”);
rotulo2=new JLabel(“Usuario”);
rotulo3=new JLabel(“Senha”);
texto1 = new JTextField(15);
texto2 = new JPasswordField(15);
entrar = new JButton(“Entrar”);
titulo.setBounds(40,10,200,20);
rotulo2.setBounds(50,60,60,20);
rotulo3.setBounds(50,80,60,20);
texto1.setBounds(100,60,80,20);
texto2.setBounds(100,80,80,20);
entrar.setBounds(100,130,90,20);
entrar.setMnemonic(KeyEvent.VK_E);
entrar.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
try{
Class.forName(“com.mysql.jdbc.Driver”);
Connection con = DriverManager.getConnection(“jdbc:mysql://localhost/teste”,“root”,"");
Statement st = con.createStatement();
ResultSet rs =st.executeQuery(“select * from usuarios where usuario=’”+texto1.getText()+"’ and senha=’"+texto2.getPassword()+"’");
rs.next();
JOptionPane.showMessageDialog(null,“Bem vindo ao sistema”,“User Logado”,JOptionPane.INFORMATION_MESSAGE);
setVisible(false);
}
catch(Exception event){
JOptionPane.showMessageDialog(null,“Usuario não existe \n Comandos Inválidos”,“Mensagem do Programa”,JOptionPane.ERROR_MESSAGE);
}
}});
tela.add(titulo);
tela.add(rotulo2);
tela.add(rotulo3);
tela.add(texto1);
tela.add(texto2);
tela.add(entrar);
setSize(300,200);
setVisible(true);
}
public static void main(String args[]){
UsuarioSenha app= new UsuarioSenha();
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
[/code]