validate jtextfield in two different class use keylistener

Ads
 

validate jtextfield in two different class use keylistener

validate jtextfield in java swing will use two class, design part in one class and method calling in one class will use Keylisteners or change listeners

View Answers

December 16, 2011 at 5:12 PM

1)Validation.java

import javax.swing.*;
import java.awt.event.*;
import java.util.regex.*;

class Validation extends JTextField
{
    Validation(){
       this.addKeyListener(new KeyAdapter(){
       public void keyPressed(KeyEvent EVT) {
       String value = getText();
       Pattern p = Pattern.compile("[A-Z,a-z,&%$#@!()*^]");
       Matcher m = p.matcher(value);
       if (m.find()){
         JOptionPane.showMessageDialog(null,"* Enter only numeric digits(0-9)");
         setText("");
       }
        }

        });
      }
    }

2)TextFieldValidation.java

import javax.swing.*;

class TextFieldValidation{
    public static void main(String[]args){
        JLabel l=new JLabel("Enter Number: ");
        Validation v=new Validation();
        JFrame f=new JFrame();
        l.setBounds(10,10,150,20);
        v.setBounds(180,10,150,20);
    f.setLayout(null);
    f.add(l);
    f.add(v);
    f.setVisible(true);
    f.setSize(300,100);
  }
}

Ads









Related Tutorials/Questions & Answers:
validate jtextfield in two different class use keylistener
validate jtextfield in two different class use keylistener  validate jtextfield in java swing will use two class, design part in one class and method calling in one class will use Keylisteners or change listeners
how to use string of one class into another Class
how to use string of one class into another Class  I created textField(JTextField t1=new JTextField();(it is in ClassA. The input of this textField i.e t1.getText() is to be used in different(another Class say in ClassB. How can
Advertisements
use of ActionMapping in validate()
use of ActionMapping in validate()  why do we pass actionmapping in validate(ActionMapping mapping,HttpServletRequest) even we don't use actionmapping in that method
Merging Two Arrays Of Different Lengths
Merging Two Arrays Of Different Lengths  I have two arrays of different lengths and wants to have merged values into third. The only condition is, I want unique values in it(third array). Thanks In Advance
jtextfield
jtextfield  hii..is it possible to make a jtextfield in login page in such a way that some text should already be inserted like username and it should be displayed light in color and when a user enters some text then it should
Use varibles from another class
Use varibles from another class  **I have two classes. class 1:** public class askfigures extends JFrame { method from class1: public void... = new Askvalues(); values.initComponents(); I want to use the variable number
JTextField Validation in java swing
JTextField Validation in java swing In this tutorial, you will learn how to validate jtextfield in java swing. Here we have created a textfield on frame...*; import javax.swing.*; import java.awt.event.*; class TextValidation
What are the different types of property and class mappings?
What are the different types of property and class mappings?  Hi, What are the different types of property and class mappings? thanks
how to store array values into two different tables in java?
how to store array values into two different tables in java?  I have use 4/5 textboxes with same name(e.g.text1) and I get the values in a array and now I want to store these values in two different tables(i.e store 2 array
How to run ActionListenters in two different thread for the following code...
How to run ActionListenters in two different thread for the following code... javazoom.jl.player.Player; import java.io.FileInputStream; public class Play2 extends JFrame { JButton b,b1; JTextField t; Play2
How to run ActionListenters in two different thread for the following code...
How to run ActionListenters in two different thread for the following code... javazoom.jl.player.Player; import java.io.FileInputStream; public class Play2 extends JFrame { JButton b,b1; JTextField t; Play2
How to run ActionListenters in two different thread for the following code...
How to run ActionListenters in two different thread for the following code...; public class Play2 extends JFrame { JButton b,b1; JTextField t; Play2() { JFrame j=new JFrame("MusicPlayer
How to run ActionListenters in two different thread for the following code...
How to run ActionListenters in two different thread for the following code...; public class Play2 extends JFrame { JButton b,b1; JTextField t; Play2() { JFrame j=new JFrame("MusicPlayer
How to read text file to two different name array
How to read text file to two different name array   I have those numbers:12,4,9,5 numbers:19,12,1,1 how to put it in two different name array in text file to java
How to read text file to two different name array
How to read text file to two different name array   I have those numbers:12,4,9,5 numbers:19,12,1,1 how to put it in two different name array in text file to java
How to validate a form in action class and forward errors to the jsp in struts?
How to validate a form in action class and forward errors to the jsp in struts?  How to validate a form in action class and forward errors to the jsp in struts
Two forms submission to one Action Class in Struts2.0
Two forms submission to one Action Class in Struts2.0  Hi, I have two forms.I want to submit two forms with only one submit button to the same action, same method. How can i get this. Please reply me
java code to validate column content of 2 different tables in 2 different databases.
java code to validate column content of 2 different tables in 2 different.... how to compare 2 columns(different col_name) in 2 different databases placed at different server and display output( in excel format) using JAVA. if matched
java jtextfield
java jtextfield  how to validate jTextField which accept only number or alphabets from keyboard....plez do help me
why we use abstract class in java?
why we use abstract class in java?  what is the the purpose of abstract class.Give example when to use abstract and when use interface
PHP related - how to explot a string with commas and store into two different variables?
PHP related - how to explot a string with commas and store into two different variables?  Hi, I have a string and is like this '[tubelist 123456,54321,56789,98765]'. I would like to extract the first value after the tubelist
Why we use singleton class in hibernate sessionfactory?
Why we use singleton class in hibernate sessionfactory?  Hello, Please tell me why we use singleton class in hibernate sessionfactory? hibernate sessionfactory singleton example would be very helpful. Thanks
float validation for jTextField
float validation for jTextField  Hi; I try that users enter only float number into jtextfield but I can not handle it. I try regex in keylistener but I couldn't be successful. Can you help me please
Validate <select> tag Items
Validate select tag Items  Hi, How to validate addition of two numbers of two different "select" tag items in JavaScript..? Thanks in advance
Validate <select> tag Items
Validate select tag Items  Hi, How to validate addition of two numbers of two different "select" tag items in JavaScript..? Thanks in advance
Get JTextField value from another class
Get JTextField value from another class   ... value from other class. For this, we have created two classes ClassA.java...=new JPanel(); text1=new JTextField(10); cp.add(text1); frame.add(cp
Class and interface in same file and accessing the class from a main class in different package
Class and interface in same file and accessing the class from a main class in different package  Hello everyone; I was going through some design... a class named CantFly in same file. A main method CheckAnimal.java. Below
Class and interface in same file and accessing the class from a main class in different package
Class and interface in same file and accessing the class from a main class in different package  Hello everyone; I was going through some design... a class named CantFly in same file. A main method CheckAnimal.java. Below
How to close a frame on action event of a button from a different class ?
How to close a frame on action event of a button from a different class ?  How to close a frame on action event of a button from a different class ? I have a designed a control-frame on 1 class which has jbutton components, I
how to get values for same column name from two different tables in SQL
how to get values for same column name from two different tables in SQL  how to get values for same column name from two different tables in SQL???? column name is emp_id loacated in these two tables company,employee
validate text field iPhone
validate text field iPhone  i got two different UITextfield in my iPhone application for user login. Just wondering how to validate

Ads