ok eu alterei conforme o @darlan_machado estava me ajudando as classes são essas se caso voce quiser mais alguma peça que eu coloque ela estou copiando exatamente a classe toda.
Tela de Login
package aplicacao;
import ClassesDao.UsuarioDao;
import Sessao.Sessao;
import Principais.Usuario;
import Sessao.CriaSessao;
import java.awt.Toolkit;
import java.util.LinkedList;
import javax.swing.JOptionPane;
/**
*
* @author TI
*/
public class Frame_Login extends javax.swing.JFrame {
private String nome;
private String senha;
private FrameMain frameMain;
/**
* Creates new form Frame_Login
*/
public Frame_Login() {
initComponents();
setIcon();
frameMain = new FrameMain();
}
/**
* 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() {
Label_Nome = new javax.swing.JLabel();
txt_Nome = new javax.swing.JTextField();
Label_Senha = new javax.swing.JLabel();
btn_Entrar = new javax.swing.JButton();
txt_Senha = new javax.swing.JPasswordField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("ProMulti Login");
Label_Nome.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
Label_Nome.setText("Nome do Usuario:");
Label_Senha.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
Label_Senha.setText("Senha:");
btn_Entrar.setText("Entrar");
btn_Entrar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_EntrarActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(67, 67, 67)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(Label_Nome)
.addComponent(Label_Senha))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txt_Senha, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txt_Nome, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btn_Entrar, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(157, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(79, 79, 79)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Label_Nome)
.addComponent(txt_Nome, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Label_Senha)
.addComponent(txt_Senha, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addGap(74, 74, 74)
.addComponent(btn_Entrar, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(123, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void btn_EntrarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
UsuarioDao usuarioDao = new UsuarioDao();
LinkedList<Usuario> lista = usuarioDao.busca();
nome = txt_Nome.getText();
senha = txt_Senha.getText();
for (int i = 0; i < lista.size(); i++) {
Usuario u = lista.get(i);
if (nome.equals(u.getNome())) {
if (senha.equals(u.getSenha())) {
CriaSessao cs = new CriaSessao();
cs.criaSessaoEAdicionaUsuario();
frameMain.setVisible(true);
this.setVisible(false);
break;
} else {
JOptionPane.showMessageDialog(null, "Senha incorreta");
break;
}
} else {
JOptionPane.showMessageDialog(null, "Usuario não cadrastrado");
break;
}
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Frame_Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Frame_Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Frame_Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Frame_Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Frame_Login().setVisible(true);
}
});
}
//Metodo somente para colocar uma imagem como icone
private void setIcon() {
setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("Imagens/logo_Multimov.png")));
}
// Variables declaration - do not modify
private javax.swing.JLabel Label_Nome;
private javax.swing.JLabel Label_Senha;
private javax.swing.JButton btn_Entrar;
private javax.swing.JTextField txt_Nome;
private javax.swing.JPasswordField txt_Senha;
// End of variables declaration
}
Tela de principal apos o Login
package aplicacao;
import Sessao.Sessao;
import Principais.Usuario;
import Sessao.RecuperaSessao;
import banco_dados.conecta;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.sql.Connection;
import javax.swing.JFrame;
/**
*
* @author jean.souza
*/
//Criação da Classe FrameMains com herança da classe JFrame
public class FramePrincipal extends javax.swing.JFrame {
/**
* Creates new form FramePrincipal
*/
//declaraçao de variaveis globais privadas
private Frame_Cliente frame_Cliente;
private Frame_Setor frame_Setor;
private Frame_Operacao frame_Operacao;
private Frame_Permicoes frame_Permicoes;
private Frame_Usuario frame_Usuario;
private Frame_Login frame_Login;
private String Nome;
private String Senha;
private Sessao sessao;
//metodo construtor
public FramePrincipal() {
this.setExtendedState(MAXIMIZED_BOTH);
initComponents();
setIcon();
RecuperaSessao rs = new RecuperaSessao();
Usuario usuario = rs.recuperaSessaoELeONome();
//System.out.println(usuario.getNome());
frame_Cliente = new Frame_Cliente(this);
frame_Setor = new Frame_Setor(this);
frame_Operacao = new Frame_Operacao(this);
frame_Permicoes = new Frame_Permicoes(this);
frame_Usuario = new Frame_Usuario(this);
setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
conecta con = new conecta();
con.fechaConexao();
System.exit(0);
}
});
}
/**
* 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() {
jPanel1 = new javax.swing.JPanel();
btnCliente = new javax.swing.JToggleButton();
btn_Setor = new javax.swing.JButton();
btn_Sair = new javax.swing.JButton();
btn_operacao = new javax.swing.JButton();
btn_Usuario = new javax.swing.JButton();
btn_permicoes = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("ProMulti Tela Inicial");
btnCliente.setText("Clientes");
btnCliente.setMaximumSize(new java.awt.Dimension(70, 25));
btnCliente.setMinimumSize(new java.awt.Dimension(70, 25));
btnCliente.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnClienteActionPerformed(evt);
}
});
btn_Setor.setText("Setor");
btn_Setor.setMaximumSize(new java.awt.Dimension(70, 25));
btn_Setor.setMinimumSize(new java.awt.Dimension(70, 25));
btn_Setor.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_SetorActionPerformed(evt);
}
});
btn_Sair.setText("Sair");
btn_Sair.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_SairActionPerformed(evt);
}
});
btn_operacao.setText("Operação");
btn_operacao.setMaximumSize(new java.awt.Dimension(70, 25));
btn_operacao.setMinimumSize(new java.awt.Dimension(70, 25));
btn_operacao.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_operacaoActionPerformed(evt);
}
});
btn_Usuario.setText("Usuario");
btn_Usuario.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_UsuarioActionPerformed(evt);
}
});
btn_permicoes.setText("Permições");
btn_permicoes.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_permicoesActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(69, 69, 69)
.addComponent(btn_permicoes, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btn_Usuario, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btnCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btn_Setor, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btn_operacao, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btn_Sair, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(90, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(50, 50, 50)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btn_Setor, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btn_operacao, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btn_Sair, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btn_Usuario, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btn_permicoes, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(80, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(67, Short.MAX_VALUE)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(126, 126, 126))
);
pack();
}// </editor-fold>
//Botao que chama outro frame
private void btnClienteActionPerformed(java.awt.event.ActionEvent evt) {
//Evento do botao cliente ele somente fecha a main e abre a clientes
frame_Cliente.setVisible(true);
this.setVisible(false);
}
private void btn_SetorActionPerformed(java.awt.event.ActionEvent evt) {
//Evento do botao setor ele somente fecha a main e abre a setor
frame_Setor.setVisible(true);
this.setVisible(false);
}
private void btn_SairActionPerformed(java.awt.event.ActionEvent evt) {
//Evento do botao sair ele fecha a plicaçao;
conecta con = new conecta();
con.fechaConexao();
System.exit(0);
}
private void btn_operacaoActionPerformed(java.awt.event.ActionEvent evt) {
//Evento do botao operacao ele somente fecha a main e abre a operacao
frame_Operacao.setVisible(true);
this.setVisible(false);
}
private void btn_UsuarioActionPerformed(java.awt.event.ActionEvent evt) {
//
frame_Usuario.setVisible(true);
this.setVisible(false);
}
private void btn_permicoesActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
frame_Permicoes.setVisible(true);
this.setVisible(false);
}
// /**
// * @param args the command line arguments
// */
// //metodo main que ira ser executado primeiramente
// public static void main(String args[]) {
// /* Set the Nimbus look and feel */
// //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
// /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
// * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
// */
// try {
// for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
// if ("Nimbus".equals(info.getName())) {
// javax.swing.UIManager.setLookAndFeel(info.getClassName());
// break;
// }
// }
// } catch (ClassNotFoundException ex) {
// java.util.logging.Logger.getLogger(FramePrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
// } catch (InstantiationException ex) {
// java.util.logging.Logger.getLogger(FramePrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
// } catch (IllegalAccessException ex) {
// java.util.logging.Logger.getLogger(FramePrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
// } catch (javax.swing.UnsupportedLookAndFeelException ex) {
// java.util.logging.Logger.getLogger(FramePrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
// }
// //</editor-fold>
// //</editor-fold>
//
// /* Create and display the form */
// java.awt.EventQueue.invokeLater(new Runnable() {
// public void run() {
// new FramePrincipal().setVisible(true);
//
// }
//
// });
// }
//Metodo somente para colocar uma imagem como icone
private void setIcon() {
setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("Imagens/logo_Multimov.png")));
}
// Variables declaration - do not modify
private javax.swing.JToggleButton btnCliente;
private javax.swing.JButton btn_Sair;
private javax.swing.JButton btn_Setor;
private javax.swing.JButton btn_Usuario;
private javax.swing.JButton btn_operacao;
private javax.swing.JButton btn_permicoes;
private javax.swing.JPanel jPanel1;
// End of variables declaration
}
Classe Sessao
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Sessao;
import Principais.Usuario;
/**
*
* @author TI
*/
public class Sessao {
private static final Sessao INSTANCE = new Sessao();
private Usuario usuario;
private Sessao() {
}
public static Sessao getInstance() {
return INSTANCE;
}
public Usuario getUsuario() {
return usuario;
}
public void setUsuario(Usuario usuario) {
this.usuario = usuario;
}
}
Classe que cria Sessao
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Sessao;
import Principais.Usuario;
/**
*
* @author TI
*/
public class CriaSessao {
public void criaSessaoEAdicionaUsuario() {
String nome = "Astolpho";
Usuario user = new Usuario();
user.setNome(nome);
Sessao sessao = Sessao.getInstance();
sessao.setUsuario(user);
}
}
Classe recupera Sessão
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Sessao;
import Principais.Usuario;
/**
*
* @author TI
*/
public class RecuperaSessao {
public Usuario recuperaSessaoELeONome() {
Sessao sessao = Sessao.getInstance();
System.out.println(sessao);
Usuario usuario = sessao.getUsuario();
System.out.println(usuario.getNome());
return usuario;
}
}
Classe Principal do usuario
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Principais;
/**
*
* @author TI
*/
public class Usuario {
private int ID_usuario;
private String nome;
private String senha;
private int ID_grupo_usuario;
private String grupo_usuario;
public int getID_usuario() {
return ID_usuario;
}
public void setID_usuario(int ID_usuario) {
this.ID_usuario = ID_usuario;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getSenha() {
return senha;
}
public void setSenha(String senha) {
this.senha = senha;
}
public int getID_grupo_usuario() {
return ID_grupo_usuario;
}
public void setID_grupo_usuario(int ID_grupo_usuario) {
this.ID_grupo_usuario = ID_grupo_usuario;
}
public String getGrupo_usuario() {
return grupo_usuario;
}
public void setGrupo_usuario(String grupo_usuario) {
this.grupo_usuario = grupo_usuario;
}
}