Fabio Rodrigues - Telematica wrote:

> Ola javaneses,
>
> Segue abaixo um codigo de exemplo de como validar Campo a campo na tela
> (TEXTFIELD)
>
> obrigado MARIO e Aristedes
>
> Fabio A.Rodrigues
>
> eh so testar...
>
> =========
>
> import java.awt.event.*;
> import java.awt.*;
> import javax.swing.*;
>
> public class FocusTest2 {
>     public static void main(String args[]) {
>  new FocusTestFrame();
>     }
> }
>
> class FocusTestFrame extends JFrame implements FocusListener {
>     JTextField jtf1 = new JTextField(20);
>     JTextField jtf2 = new JTextField(20);
>     FocusTestFrame() {
>  super();
>  /* Components should be added to the container's content pane */
>  Container cp = getContentPane();
>  cp.add(BorderLayout.NORTH,jtf1);
>  cp.add(BorderLayout.SOUTH,jtf2);
>  jtf1.addFocusListener(this);
>  jtf2.addFocusListener(this);
>  /* Add the window listener */
>  addWindowListener(new WindowAdapter() {
>      public void windowClosing(WindowEvent evt) {
>   dispose(); System.exit(0);}});
>  /* Size the frame */
>  setSize(200,200);
>  /* Center the frame */
>  Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
>  Rectangle frameDim = getBounds();
>  setLocation((screenDim.width - frameDim.width) / 2,(screenDim.height -
> frameDim.height) / 2);
>  /* Show the frame */
>  setVisible(true);
>     }
>     public void focusGained(FocusEvent evt)
>     {
>     }
>     public void focusLost(FocusEvent evt)
>     {
>  Object obj = evt.getSource();
>  if (obj == jtf1)
>      {
>   if (!jtf1.getText().equals("Hello"))
>       {
>    Toolkit.getDefaultToolkit().beep();
>    SwingUtilities.invokeLater(new Runnable() {
>        public void run() {
>     jtf1.requestFocus();}});
>       }
>      }
>     }
> }

    --------------------------- LISTA SOUJAVA ---------------------------
    http://www.soujava.org.br  -  Sociedade de Usu�rios Java da Sucesu-SP
    [d�vidas mais comuns: http://www.soujava.org.br/faq.htm]
    [para sair da lista: http://www.soujava.org.br/forum/cadastrados.htm]
    [regras da lista: http://www.soujava.org.br/regras.htm]
    ---------------------------------------------------------------------

Responder a