Boa tarde!
Por que os JTextFields do código abaixo não aceitam o que está sendo digitado???
Obrigado pela ajuda.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Exercicio extends JFrame implements FocusListener,KeyListener{
JLabel Nome, End, Idade;
JTextField txt1, txt2, txt3;
public Exercicio ()
{
setSize(800, 600);
setTitle("Exercício Aula 4 - 09.08.2009");
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
txt1 = new JTextField();
txt1.setBounds(100,10,300,30);
txt1.addKeyListener(this);
// txt1.addFocusListener(this);
txt2 = new JTextField();
txt2.setBounds(100,50,300,30);
txt2.addKeyListener(this);
// txt2.addFocusListener(this);
txt3 = new JTextField();
txt3.setBounds(100,90,300,30);
txt3.addKeyListener(this);
// txt3.addFocusListener(this);
Nome = new JLabel("Nome");
Nome.setBounds(10,10,280,20);
End = new JLabel("Endereço");
End.setBounds(10,50,280,20);
Idade = new JLabel("Idade");
Idade.setBounds(10,90,280,20);
getContentPane().setLayout(null);
getContentPane().add(txt1);
getContentPane().add(txt2);
getContentPane().add(txt3);
getContentPane().add(Nome);
getContentPane().add(End);
getContentPane().add(Idade);
}
public void keyPressed(KeyEvent e){
if(e.getSource()==txt1)
if(e.getKeyCode()==10){
txt2.requestFocus();
}
if(e.getSource()==txt2)
if(e.getKeyCode()==10){
txt3.requestFocus();
}
}
public void focusGained(FocusEvent ee){
}
public void focusLost(FocusEvent ef){
}
public void keyTyped(KeyEvent e) {
throw new UnsupportedOperationException("Not supported yet.");
}
public void keyReleased(KeyEvent e) {
throw new UnsupportedOperationException("Not supported yet.");
}
public static void main (String args[]){
Exercicio exe = new Exercicio();
}
}