Aproveitando,
Estou com uma pequena dificuldade (Sou novo em GUI).
Quero que após o login seja efetuado com sucesso, o menu seja habilitado, uma vez que está desabilitado.
segue as classes:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* GUILogin.java
*
* Created on 16/03/2011, 17:22:46
*/
package visao;
import java.awt.Dimension;
import javax.swing.JOptionPane;
/**
*
* @author diego
*/
public class GUILogin extends javax.swing.JInternalFrame {
/** Creates new form GUILogin */
public GUILogin() {
initComponents();
}
public void setPosicao(){
Dimension d = this.getDesktopPane().getSize();
//this.setLocation((d.width - this.getSize().width)/2,
// (d.height - this.getSize().height)/2);
this.setLocation(470,200);
}
private boolean verificarSenha(String loginUsuario, String senhaUsuario){
String login = "1";
String senha = "1";
if ((loginUsuario.equals(login)) && (senhaUsuario.equals(senha))){
return true;
}
else{
return false;
}
}
public boolean getAutenticacao(){
return this.autenticacao;
}
/** 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() {
jLabel1 = new javax.swing.JLabel();
tfLogin = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
psSenha = new javax.swing.JPasswordField();
botaoLogin = new javax.swing.JButton();
setTitle("Login");
setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
jLabel1.setText("Login");
jLabel2.setText("Senha");
botaoLogin.setText("Login");
botaoLogin.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
botaoLoginActionPerformed(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(72, 72, 72)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(tfLogin)
.addComponent(psSenha, javax.swing.GroupLayout.DEFAULT_SIZE, 184, Short.MAX_VALUE))
.addContainerGap(78, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(170, Short.MAX_VALUE)
.addComponent(botaoLogin, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(142, 142, 142))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(37, 37, 37)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(tfLogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addGap(77, 77, 77)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(psSenha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(18, 18, 18)
.addComponent(botaoLogin)
.addContainerGap(27, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void botaoLoginActionPerformed(java.awt.event.ActionEvent evt) {
String loginDigitado = tfLogin.getText();
String senhaDigitada = psSenha.getText();
if ((verificarSenha(loginDigitado, senhaDigitada)) == true){
this.setVisible(false);
}
else{
JOptionPane.showMessageDialog(null, "Usuário ou senha inválidos");
psSenha.setText("");
}
}
// Variables declaration - do not modify
private javax.swing.JButton botaoLogin;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPasswordField psSenha;
private javax.swing.JTextField tfLogin;
// End of variables declaration
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* GUIPrincipal.java
*
* Created on 16/03/2011, 16:50:06
*/
package visao;
import javax.swing.JFrame;
/**
*
* @author diego
*/
public class GUIPrincipal extends javax.swing.JFrame {
/** Creates new form GUIPrincipal */
public GUIPrincipal() {
initComponents();
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
desabilitarMenu();
if ((guiLogin == null) || (!guiLogin.isVisible())){
guiLogin = new GUILogin();
desktopPane.add(guiLogin);
guiLogin.setPosicao();
guiLogin.setVisible(true);
}
}
public void desabilitarMenu(){
menuArquivo.setEnabled(false);
menuCadastro.setEnabled(false);
menuRelatorio.setEnabled(false);
menuAjuda.setEnabled(false);
}
public void habilitarMenu(){
menuArquivo.setEnabled(true);
menuCadastro.setEnabled(true);
menuRelatorio.setEnabled(true);
menuAjuda.setEnabled(true);
}
/** 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() {
desktopPane = new javax.swing.JDesktopPane();
menu = new javax.swing.JMenuBar();
menuArquivo = new javax.swing.JMenu();
itemMenuNovaCompra = new javax.swing.JMenuItem();
jSeparator1 = new javax.swing.JPopupMenu.Separator();
itemMenuSair = new javax.swing.JMenuItem();
menuCadastro = new javax.swing.JMenu();
itemMenuCliente = new javax.swing.JMenuItem();
itemMenuFuncionario = new javax.swing.JMenuItem();
itemMenuProduto = new javax.swing.JMenuItem();
itemMenuFornecedor = new javax.swing.JMenuItem();
menuRelatorio = new javax.swing.JMenu();
itemMenuRelatorioGeral = new javax.swing.JMenuItem();
itemMenuRelatorioCompra = new javax.swing.JMenuItem();
itemMenuRelatorioVenda = new javax.swing.JMenuItem();
menuAjuda = new javax.swing.JMenu();
itemMenuSobre = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
menuArquivo.setText("Arquivo");
itemMenuNovaCompra.setText("Nova Compra");
menuArquivo.add(itemMenuNovaCompra);
menuArquivo.add(jSeparator1);
itemMenuSair.setText("Sair");
menuArquivo.add(itemMenuSair);
menu.add(menuArquivo);
menuCadastro.setText("Cadastro");
itemMenuCliente.setText("Cliente");
menuCadastro.add(itemMenuCliente);
itemMenuFuncionario.setText("Funcionário");
menuCadastro.add(itemMenuFuncionario);
itemMenuProduto.setText("Produto");
menuCadastro.add(itemMenuProduto);
itemMenuFornecedor.setText("Fornecedor");
menuCadastro.add(itemMenuFornecedor);
menu.add(menuCadastro);
menuRelatorio.setText("Relatório");
itemMenuRelatorioGeral.setText("Geral");
menuRelatorio.add(itemMenuRelatorioGeral);
itemMenuRelatorioCompra.setText("Compra");
menuRelatorio.add(itemMenuRelatorioCompra);
itemMenuRelatorioVenda.setText("Venda");
menuRelatorio.add(itemMenuRelatorioVenda);
menu.add(menuRelatorio);
menuAjuda.setText("Ajuda");
itemMenuSobre.setText("Sobre");
menuAjuda.add(itemMenuSobre);
menu.add(menuAjuda);
setJMenuBar(menu);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 273, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new GUIPrincipal().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JDesktopPane desktopPane;
private javax.swing.JMenuItem itemMenuCliente;
private javax.swing.JMenuItem itemMenuFornecedor;
private javax.swing.JMenuItem itemMenuFuncionario;
private javax.swing.JMenuItem itemMenuNovaCompra;
private javax.swing.JMenuItem itemMenuProduto;
private javax.swing.JMenuItem itemMenuRelatorioCompra;
private javax.swing.JMenuItem itemMenuRelatorioGeral;
private javax.swing.JMenuItem itemMenuRelatorioVenda;
private javax.swing.JMenuItem itemMenuSair;
private javax.swing.JMenuItem itemMenuSobre;
private javax.swing.JPopupMenu.Separator jSeparator1;
private javax.swing.JMenuBar menu;
private javax.swing.JMenu menuAjuda;
private javax.swing.JMenu menuArquivo;
private javax.swing.JMenu menuCadastro;
private javax.swing.JMenu menuRelatorio;
// End of variables declaration
private GUILogin guiLogin;
}