De uma olhada..
Crie um classe para fazer a função de autenticação
Crie outra classe so para os dados do usuario
Crie uma interface
Crie uma janela
[img]http://img87.imageshack.us/img87/6194/semttulocd.jpg[/img]
import java.beans.Statement;
import java.sql.ResultSet;
/**
*
* @author guga
*/
public class clsEntrar implements interfaceEntrar {
//objetos
clsUsuario objUsuario = new clsUsuario();
//variavel para guardar comandos SQLs
String sSQL="";
//metodo construtor
public clsEntrar(){
}
public boolean Entrar() throws Exception {
//conecta seu banco de dados
boolean entrou =false;
sSQL="SELECT * FROM usuarios WHERE usuario ="+objUsuario.getUsuario+" AND senha ="+objUsuario.getSenha;
try {
Statement sta = null;
ResultSet res = null;
sta = cnn.createStatement(res.TYPE_SCROLL_INSENSITIVE,res.CONCUR_READ_ONLY);;
res = sta.executeQuery(sSQL);
if(res.next()){
entrou = true;
}
}catch(Exception e){
e.printStackTrace();
}
return entrou;
}
}
public interface interfaceEntrar {
public boolean Entrar() throws Exception;
}
/**
*
* @author guga
*/
public class clsUsuario {
private static String Usuario;
/**
* @return the Usuario
*/
public static String getUsuario() {
return Usuario;
}
/**
* @param aUsuario the Usuario to set
*/
public static void setUsuario(String aUsuario) {
Usuario = aUsuario;
}
private String Senha;
/**
* @return the Senha
*/
public String getSenha() {
return Senha;
}
/**
* @param Senha the Senha to set
*/
public void setSenha(String Senha) {
this.Senha = Senha;
}
}
import java.util.logging.Level;
import java.util.logging.Logger;
/*
* jfEntrar.java
*
* Created on 30/10/2012, 20:57:41
*/
/**
*
* @author guga
*/
public class jfEntrar extends javax.swing.JFrame {
/** Creates new form jfEntrar */
public jfEntrar() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jtUsuario = new javax.swing.JTextField();
jtSenha = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jbEntrar = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("Usuário");
jLabel2.setText("Senha");
jbEntrar.setText("Entrar");
jbEntrar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbEntrarActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jbEntrar)
.addComponent(jtSenha, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 186, Short.MAX_VALUE)
.addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jtUsuario, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 186, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jtUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jtSenha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jbEntrar)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void jbEntrarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
//pega dados do formulario
PegaDados();
clsEntrar painelLogar = new clsEntrar();
try {
if(painelLogar.Entrar()){
new jfOutraTela().setVisible(true);
}
} catch (Exception ex) {
Logger.getLogger(jfEntrar.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void PegaDados(){
clsUsuario objUsuario = new clsUsuario();
objUsuario.setUsuario(jtUsuario.getText());
objUsuario.setSenha(jtSenha.getText());
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new jfEntrar().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JButton jbEntrar;
private javax.swing.JTextField jtSenha;
private javax.swing.JTextField jtUsuario;
// End of variables declaration
}
Ta bem básico, só pra você ter uma base e ajeitar ai como vc quiser..
;]