Segue abaixo:
Classe usuarios
public class usuarios{
principal c1 = new principal();
public String user;
public String usuarias;
public String password;
//public String password = null;
public String getuser() {
return user;
}
public void setuser(String user) {
this.user = user;
}
public String getpassword() {
return password;
}
public void setpassword(String password) {
this.password = password;
}
public String usuariass(){
return usuarias;
}
}
Classe Principal
import javax.swing.SwingUtilities;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JTextField;
import java.awt.Rectangle;
import java.awt.Font;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import java.awt.Color;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
public class principal extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JTextField usuario = null;
private JLabel jLabel = null;
private JLabel jLabel1 = null;
private JPasswordField senha = null;
private JButton jButton = null;
private JButton jButton1 = null;
private JLabel erro = null;
//String user; // @jve:decl-index=0:
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
erro = new JLabel();
erro.setBounds(new Rectangle(74, 176, 193, 16));
erro.setFont(new Font("Dialog", Font.BOLD, 14));
erro.setForeground(Color.red);
erro.setText("Usuário ou Senha Inválidos");
erro.setVisible(false);
jLabel1 = new JLabel();
jLabel1.setBounds(new Rectangle(24, 93, 69, 16));
jLabel1.setText("Senha");
jLabel1.setFont(new Font("Dialog", Font.BOLD, 18));
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(20, 38, 71, 16));
jLabel.setText("Usuário");
jLabel.setFont(new Font("Dialog", Font.BOLD, 18));
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getUsuario(), null);
jContentPane.add(jLabel, null);
jContentPane.add(jLabel1, null);
jContentPane.add(getSenha(), null);
jContentPane.add(getJButton(), null);
jContentPane.add(getJButton1(), null);
jContentPane.add(erro, null);
}
return jContentPane;
}
/**
* This method initializes usuario
*
* @return javax.swing.JTextField
*/
private JTextField getUsuario() {
if (usuario == null) {
usuario = new JTextField();
usuario.setBounds(new Rectangle(99, 33, 193, 29));
usuario.setFont(new Font("Dialog", Font.BOLD, 12));
}
return usuario;
}
/**
* This method initializes senha
*
* @return javax.swing.JPasswordField
*/
private JPasswordField getSenha() {
if (senha == null) {
senha = new JPasswordField();
senha.setBounds(new Rectangle(100, 90, 192, 25));
senha.setFont(new Font("Dialog", Font.BOLD, 12));
senha.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
jButton.doClick();
}
});
}
return senha;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
public JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new Rectangle(30, 135, 101, 34));
jButton.setText("OK");
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
usuarios Usuarios = new usuarios();
Usuarios.setuser(usuario.getText().toUpperCase());
Usuarios.setpassword(senha.getText().toUpperCase());
comunica db = new comunica();
// obtendo a conexao através do obj de banco de dados
Connection conn = db.getConnection();
try {
Statement st = conn.createStatement();
String qry = "SELECT * FROM TBUSUARIOS WHERE usuario='"+ Usuarios.getuser() +"' and senha='"+ Usuarios.getpassword() +"' and tipo='2'";
ResultSet rs = st.executeQuery( qry ); // TODO Auto-generated Event stub actionPerformed()
if(rs.next() ) {
aponta apontamento = new aponta();
apontamento.setLocationRelativeTo(null);
apontamento.setVisible(true);
principal.this.setVisible(false);
Usuarios.setuser(usuario.getText());
} else {
erro.setVisible(true);
}
} catch( Exception ex ) {
ex.printStackTrace();
}
}
});
}
return jButton;
}
/**
* This method initializes jButton1
*
* @return javax.swing.JButton
*/
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setBounds(new Rectangle(180, 136, 100, 33));
jButton1.setText("CANCELAR");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
usuario.setText("");
senha.setText("");
erro.setVisible(false);
usuario.grabFocus();
}
});
}
return jButton1;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Stub de método gerado automaticamente
SwingUtilities.invokeLater(new Runnable() {
public void run() {
principal thisClass = new principal();
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
thisClass.setVisible(true);
}
});
}
/**
* This is the default constructor
*/
public principal() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(323, 234);
this.setResizable(false);
this.setContentPane(getJContentPane());
this.setTitle("BRONZINAS - LOGIN");
}
}
Classe Ver
public class ver extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JButton jButton = null;
/**
* This is the default constructor
*/
public ver() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(300, 200);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getJButton(), null);
}
return jContentPane;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new Rectangle(86, 56, 73, 24));
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
usuarios Usuario = new usuarios();
System.out.println(" O Nome é: " + Usuario.user);
}
});
}
return jButton;
}
}