voidjanelaEntrada(){//criandocomponetentes;texto1=newJLabel("Login:"); texto2 = new JLabel("Senha:"); texto3 = new JLabel("AberturadeChamados"); campo1 = new JTextField(); campo2 = new JPasswordField(); botao1 = new JButton("Entre");texto1.setBounds(50,50,100,100);texto2.setBounds(50,80,100,100);texto3.setBounds(60,10,400,50);campo1.setBounds(100,90,100,20);campo2.setBounds(100,120,100,20);botao1.setBounds(75,155,100,20);//criandoJanela;JPaneljanelaLogin=newJPanel();janelaLogin.setLayout(null);janelaLogin.add(texto1);janelaLogin.add(texto2);janelaLogin.add(texto3);janelaLogin.add(campo1);janelaLogin.add(campo2);janelaLogin.add(botao1);this.setContentPane(janelaLogin);this.setSize(250,250);setSize(250,250);setVisible(true);Verificandoact=newVerificando();botao1.addActionListener(act);}
Como eu faço para quando o usuario aperte ENTER ele disparar o evento do botão
/* * Classe1.java * * Created on 4 de Setembro de 2007, 17:42 *//** * * @author sergio */publicclassClasse1extendsjavax.swing.JFrame{/** Creates new form Classe1 */publicClasse1(){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. */// <editor-fold defaultstate="collapsed" desc=" Generated Code "> privatevoidinitComponents(){jButton1=newjavax.swing.JButton();jLabel1=newjavax.swing.JLabel();getContentPane().setLayout(null);setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);jButton1.setText("Chama janela2");jButton1.addActionListener(newjava.awt.event.ActionListener(){publicvoidactionPerformed(java.awt.event.ActionEventevt){jButton1ActionPerformed(evt);}});getContentPane().add(jButton1);jButton1.setBounds(110,120,150,60);jLabel1.setFont(newjava.awt.Font("Dialog",1,24));jLabel1.setText("Janela 1");getContentPane().add(jLabel1);jLabel1.setBounds(130,70,190,40);java.awt.DimensionscreenSize=java.awt.Toolkit.getDefaultToolkit().getScreenSize();setBounds((screenSize.width-400)/2,(screenSize.height-300)/2,400,300);}// </editor-fold> privatevoidjButton1ActionPerformed(java.awt.event.ActionEventevt){newClasse2().setVisible(true);this.setVisible(false);}/** * @param args the command line arguments */publicstaticvoidmain(Stringargs[]){java.awt.EventQueue.invokeLater(newRunnable(){publicvoidrun(){newClasse1().setVisible(true);}});}// Variables declaration - do not modify privatejavax.swing.JButtonjButton1;privatejavax.swing.JLabeljLabel1;// End of variables declaration }
Classe2.java
/* * Classe2.java * * Created on 4 de Setembro de 2007, 17:44 *//** * * @author sergio */publicclassClasse2extendsjavax.swing.JFrame{/** Creates new form Classe2 */publicClasse2(){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. */// <editor-fold defaultstate="collapsed" desc=" Generated Code "> privatevoidinitComponents(){jLabel1=newjavax.swing.JLabel();jButton1=newjavax.swing.JButton();getContentPane().setLayout(null);setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);jLabel1.setFont(newjava.awt.Font("Dialog",1,24));jLabel1.setText("Janela2");getContentPane().add(jLabel1);jLabel1.setBounds(140,110,100,30);jButton1.setText("Janela 1 novamente...");jButton1.addActionListener(newjava.awt.event.ActionListener(){publicvoidactionPerformed(java.awt.event.ActionEventevt){jButton1ActionPerformed(evt);}});getContentPane().add(jButton1);jButton1.setBounds(100,150,200,70);java.awt.DimensionscreenSize=java.awt.Toolkit.getDefaultToolkit().getScreenSize();setBounds((screenSize.width-406)/2,(screenSize.height-296)/2,406,296);}// </editor-fold> privatevoidjButton1ActionPerformed(java.awt.event.ActionEventevt){this.setVisible(false);newClasse1().setVisible(true);}/** * @param args the command line arguments */publicstaticvoidmain(Stringargs[]){java.awt.EventQueue.invokeLater(newRunnable(){publicvoidrun(){newClasse2().setVisible(true);}});}// Variables declaration - do not modify privatejavax.swing.JButtonjButton1;privatejavax.swing.JLabeljLabel1;// End of variables declaration }