Como faço parapara que meu botao avançar funcione com o ENTER do teclado…
grata
Como faço parapara que meu botao avançar funcione com o ENTER do teclado…
grata
Ola… na verdade td e um evento mesmo!!
Tente colocar esse metodo aqui…
mas n esqueca de importar a classe java.awt.event.*;
seuBotao.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e ) {
// Aqui vc coloca a a ação que vc quer
}
});
Espero ter ajudado!!
Abracao e te+
então…funciona a ação…mais gostaria que ao teclar o Enter o botão funcione…ele só funciona com o SPACE ou o clique do mouse…
eae blz?
bom como eu gerelmente resolvo essa situação
no componente que eu quero que execute algo com o ENTER
eu fico verificando os eventos de teclado onde eu verifico
se a tecla precionada foi o ENTER caso seje eu chamo um
método que é o mesmo chamado no evento do click num botão

[]'s
Deve ser + ou - isso que vc tá querendo:
public class TesteKey extends javax.swing.JFrame {
/** Creates new form TesteKey */
public TesteKey() {
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.
*/
private void initComponents() {
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
getContentPane().setLayout(null);
addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
formKeyPressed(evt);
}
public void keyReleased(java.awt.event.KeyEvent evt) {
formKeyReleased(evt);
}
});
addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
formMouseClicked(evt);
}
});
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
getContentPane().add(jTextField1);
jTextField1.setBounds(130, 160, 190, 22);
jTextField2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField2ActionPerformed(evt);
}
});
getContentPane().add(jTextField2);
jTextField2.setBounds(140, 230, 80, 22);
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-400)/2, (screenSize.height-300)/2, 400, 300);
}
private void formKeyReleased(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
System.out.println("release");
k1="";
k2="";
}
private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void formMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
this.setFocusable(true);
System.out.println("clicou");
this.requestFocus();
}
private void formKeyPressed(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
k2=k1;
k1= evt.getKeyText(evt.getKeyCode());
if( k2.equalsIgnoreCase("Ctrl") && k1.equalsIgnoreCase("V") )
System.out.println("Ctrl+V");
if( k1.equalsIgnoreCase("Delete") )
System.out.println("Delete");
}
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit(0);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
new TesteKey().show();
}
// Variables declaration - do not modify
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
// End of variables declaration
private String k1="",k2="";
}