sou novato e sofrendo...rs...
caros amigos estou com um projeto
como segue abaixo
e estava querendo testar se o usuario teclou alguma tecla
porem se vcs observarem existe um metodo criado pelo netbeans
formKeyPressed
porque nao executa quando eu digito uma tecla
criei este metodo com o proprio netbeans e nao executa o System.out.println("passou aqui") dele..
porque este metodo nao executa.
um detalhe:
criei um outro jframe e criei novamente o metodo pelo netbeans e funciona
porem neste jframe nao esta funcionando e estou precisando descobrir a causa.
por favor me ajudem...
obrigado desde ja...
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package master00;
import Tabelas.*;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableRowSorter;
/**
*
* @author Jonas
*/
public class Master00 extends javax.swing.JFrame {
public DefaultTableModel modelox;
public Gerenc gerenc = new Gerenc();
public Usuario usuario = new Usuario();
public Modulo modulo = new Modulo();
public UsuarioDAO usuarioDAO;
public ModuloDAO moduloDAO;
public GerencDAO gerencDAO;
public List<Gerenc> lista = new ArrayList<Gerenc>();
public List<String> lmenu = new ArrayList<String>();
/**
* Creates new form Master00
*/
public Master00() {
initComponents();
modelox.addColumn("Tip");
modelox.addColumn("Descricao");
modelox.addColumn("Modulo");
modelox.addColumn("Seq");
Tab.getColumnModel().getColumn(0).setMaxWidth(30);
Tab.getColumnModel().getColumn(0).setPreferredWidth(30);
Tab.getColumnModel().getColumn(1).setMaxWidth(300);
Tab.getColumnModel().getColumn(1).setPreferredWidth(300);
Tab.setRowSorter(new TableRowSorter(modelox));
try {
usuarioDAO = new UsuarioDAO();
moduloDAO = new ModuloDAO();
gerencDAO = new GerencDAO();
} catch (Exception e) {
System.out.println("Erro de Acesso "
+ e.getMessage());
}
}
/**
* 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() {
jScrollPane2 = new javax.swing.JScrollPane();
DefaultTableModel modelo = new
DefaultTableModel();
modelox = modelo;
Tab = new javax.swing.JTable(){
public boolean isCellEditable(int rowIndex, int vColIndex) {
return false;
}
};
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
TxtUsuario = new javax.swing.JTextField();
TxtSenha = new javax.swing.JTextField();
BtnConfirma = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowOpened(java.awt.event.WindowEvent evt) {
formWindowOpened(evt);
}
});
addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
formKeyPressed(evt);
}
});
Tab.setModel(modelo);
Tab.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
TabMouseClicked(evt);
}
});
jScrollPane2.setViewportView(Tab);
jLabel1.setText("Usuario:");
jLabel2.setText("Senha:");
BtnConfirma.setText("Confirma");
BtnConfirma.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BtnConfirmaActionPerformed(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()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 600, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addGap(22, 22, 22)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(TxtUsuario, javax.swing.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE)
.addComponent(TxtSenha))
.addGap(106, 106, 106)
.addComponent(BtnConfirma)
.addGap(0, 0, Short.MAX_VALUE))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 207, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(32, 32, 32)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(TxtUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(TxtSenha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addGap(41, 41, 41)
.addComponent(BtnConfirma)))
.addGap(0, 376, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void formWindowOpened(java.awt.event.WindowEvent evt) {
// TODO add your handling code here:
}
private void BtnConfirmaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try {
usuario = usuarioDAO.getUsuario(TxtUsuario.getText());
} catch (Exception e) {
JOptionPane.showMessageDialog(this, e.getMessage());
TxtUsuario.requestFocus();
return;
}
if (!usuario.getUsusenha().trim().equals(TxtSenha.getText().trim())) {
JOptionPane.showMessageDialog(this, "Senha Invalida");
TxtUsuario.requestFocus();
return;
}
if (lmenu.isEmpty()) {
MontaTabela("MASTER00");
}
}
private void TabMouseClicked(java.awt.event.MouseEvent evt) {
System.out.println(Tab.getSelectedRow());
System.out.println(Tab.getValueAt(Tab.getSelectedRow(), 2));
String menu = Tab.getValueAt(Tab.getSelectedRow(), 2).toString();
MontaTabela(menu);
}
private void formKeyPressed(java.awt.event.KeyEvent evt) {
System.out.println("nao passou aqui");
}
private void MontaTabela(String menu) {
try {
modulo = moduloDAO.getModulo(menu);
} catch (Exception e) {
JOptionPane.showMessageDialog(this, e.getMessage());
Tab.requestFocus();
return;
}
if (modulo.getModmodulo() == null) {
JOptionPane.showMessageDialog(this, "Nenhum Menu Encontrado...");
Tab.requestFocus();
return;
}
if (Tab.getRowCount() > 0) {
int max = Tab.getRowCount() - 1;
for (int i = max; i > -1; i--) {
modelox.removeRow(i);
}
}
try {
lista = gerencDAO.getLista(modulo.getModmodulo());
} catch (Exception e) {
JOptionPane.showMessageDialog(this, e.getMessage());
Tab.requestFocus();
return;
}
for (Gerenc ger : lista) {
if (!ger.getGncprivilegio().
equals(usuario.getUsuprivilegio())) {
continue;
}
try {
modulo = moduloDAO.getModulo(ger.getGncprograma());
} catch (Exception e) {
continue;
}
modelox.addRow(new Object[]{modulo.getModtipo(),
modulo.getModdescricao(),
ger.getGncprograma(),
ger.getGncordem()});
};
lmenu.add(menu);
System.out.println(lmenu.size());
}
/**
* @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(Master00.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Master00.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Master00.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Master00.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 Master00().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton BtnConfirma;
private javax.swing.JTable Tab;
private javax.swing.JTextField TxtSenha;
private javax.swing.JTextField TxtUsuario;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JScrollPane jScrollPane2;
// End of variables declaration
}