|
|
| java swings |
Expert:valarmathi
Hi,
I need the sample code for Jtext box validation. I have the text box,if i enter the wrong input the validation error message is display the textbox right side. Please send the sample code for this... very very urgent.
thanks, valarmathi |
| Answers |
/** * @(#)Validation.java * * @author R.Perumal * * @version 1.00 2009/11/4 */ import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Validation extends JFrame { JTextField CODE; Container CONT; JLabel LBL; public Validation() { CONT = getContentPane(); setBounds(0, 0, 500, 300); CODE = new JTextField(25); setLayout(new FlowLayout()); CONT.add(new JLabel("Enter the mobile nhmber")); CONT.add(CODE); CONT.add(LBL = new JLabel()); LBL.setForeground(Color.red); setDefaultCloseOperation(EXIT_ON_CLOSE); CODE.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent EVT) { if(EVT.getKeyChar() >= '0' && EVT.getKeyChar() <= '9' || EVT.getKeyCode() == 8) { CODE.setEditable(true); LBL.setText(""); } else { CODE.setEditable(false);; LBL.setText("* Enter only numeric characters"); } } }); show(); } /** * @param args the command line arguments */ public static void main(String[] args) { new Validation(); } }
|
/** * @(#)Validation.java * * @author R.Perumal * * @version 1.00 2009/11/4 */ import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Validation extends JFrame { JTextField CODE; Container CONT; JLabel LBL; public Validation() { CONT = getContentPane(); setBounds(0, 0, 500, 300); CODE = new JTextField(25); setLayout(new FlowLayout()); CONT.add(new JLabel("Enter the mobile nhmber")); CONT.add(CODE); CONT.add(LBL = new JLabel()); LBL.setForeground(Color.red); setDefaultCloseOperation(EXIT_ON_CLOSE); CODE.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent EVT) { if(EVT.getKeyChar() >= '0' && EVT.getKeyChar() <= '9' || EVT.getKeyCode() == 8) { CODE.setEditable(true); LBL.setText(""); } else { CODE.setEditable(false);; LBL.setText("* Enter only numeric characters"); } } }); show(); } /** * @param args the command line arguments */ public static void main(String[] args) { new Validation(); } }
|
| More Questions |
|
|
Post Answers
Ask Question
Facing Programming Problem?
|
|
|
|
|