2 réponses
Voici un exemple, avec des KeyListener :
final JTextField text = new JTextField();
text.setBackground(Color.RED);
text.addKeyListener(new KeyListener()
{
private final SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
@Override
public void keyReleased(KeyEvent ke)
{
try
{
Date d = format.parse(text.getText());
//System.out.println(d);
text.setBackground(Color.GREEN);
}
catch (Exception e)
{
//System.out.println(e);
text.setBackground(Color.RED);
}
}
public void keyPressed(KeyEvent ke) {}
public void keyTyped(KeyEvent ke) {}
});La confiance n'exclut pas le contrôle