Ir ao conteúdo
  • Cadastre-se

Osnir Tomas

Membro Júnior
  • Posts

    1
  • Cadastrado em

  • Última visita

Reputação

0
  1. Boa tarde a todos,sou novo por aqui mas já conheço o forum, que é um dos melhores que conheço entre varios temas, tenho um problema , que sabe alguém pode me ajudar.... Criei uma tela com login e senha, e preciso que a mudança de label seja com o enter, só que quando chega no botão 'enter', ele nao reconhece ' private void AcessoKeyPressed(java.awt.event.KeyEvent evt)', e não executa. Abaixo o código , quem puder dar uma força agradeço, obrigado. o erro aparece na linha : private void AcessoKeyPressed(java.awt.event.KeyEvent evt) { if (evt.getKeyCode()== evt.VK_ENTER) dispose(); ele não reconhece o private void, abaixo postei o código, abraços a todos ///////////////////////////////////////////////////// package Interface; import javax.swing.JOptionPane; /** * * @author hommer */ public class Login extends javax.swing.JFrame { /** * Creates new form Login */ public Login() { 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() { Acesso = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); login = new javax.swing.JTextField(); Senha = new javax.swing.JPasswordField(); jLabel3 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Tela de Login"); setResizable(false); setSize(new java.awt.Dimension(0, 0)); getContentPane().setLayout(null); Acesso.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N Acesso.setText("Entrar"); Acesso.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { AcessoActionPerformed(evt); } }); Acesso.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(java.awt.event.KeyEvent evt) { AcessoKeyPressed(evt); } }); getContentPane().add(Acesso); Acesso.setBounds(570, 160, 77, 44); jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N jLabel1.setText("Usuario:"); getContentPane().add(jLabel1); jLabel1.setBounds(200, 122, 76, 30); jLabel2.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N jLabel2.setText("Senha:"); getContentPane().add(jLabel2); jLabel2.setBounds(210, 210, 64, 30); login.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { loginActionPerformed(evt); } }); login.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(java.awt.event.KeyEvent evt) { loginKeyPressed(evt); } }); getContentPane().add(login); login.setBounds(290, 120, 266, 32); Senha.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { SenhaActionPerformed(evt); } }); Senha.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(java.awt.event.KeyEvent evt) { SenhaKeyPressed(evt); } }); getContentPane().add(Senha); Senha.setBounds(290, 210, 265, 32); getContentPane().add(jLabel3); jLabel3.setBounds(-20, -20, 870, 390); setBounds(250, 150, 866, 409); }// </editor-fold> private void SenhaActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: } private void AcessoActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: if (login.getText().equals("1")&&(Senha.getText().equals("1"))){ JOptionPane.showMessageDialog(null,"Bem Vindo"); //new Login().setVisible(true); new TelaPrincipal().setVisible(true); this.dispose(); }else{ JOptionPane.showMessageDialog(null,"Acesso negado"); } //new TelaPrincipal().setVisible(true); //this.dispose(); } private void loginKeyPressed(java.awt.event.KeyEvent evt) { if (evt.getKeyCode()== evt.VK_ENTER){ Senha.requestFocus(); } } private void loginActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: } private void SenhaKeyPressed(java.awt.event.KeyEvent evt) { if (evt.getKeyCode()== evt.VK_ENTER){ Acesso.requestFocus(); } private void AcessoKeyPressed(java.awt.event.KeyEvent evt) { if (evt.getKeyCode()== evt.VK_ENTER) dispose(); } /** * @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(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(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 Login().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton Acesso; private javax.swing.JPasswordField Senha; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JTextField login; // End of variables declaration private static class setVisible { public setVisible(boolean { } } } codigo.txt

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...