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

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);
  }
}









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 KeyListener
How to use KeyListener      ... to handle different key events on the Java Awt component by using the event handling... on.ADS_TO_REPLACE_1 All the key events are handled through the KeyListener
Advertisements
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
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
JDOM Attribute Example, Different method of Attribute class.
JDOM Attribute Example, Different method of Attribute class. This tutorial explains the use of the  getParent() and getQualifiedName(). These methods are present in the Attribute class. The Attribute class is available
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 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
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
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
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
java jtextfield
java jtextfield  how to validate jTextField which accept only number or alphabets from keyboard....plez do help me
Java class name and file name are different
Java class name and file name are different  Can we run a Java program having class name and file name different?   Hi Friend, No, you...[]) { System.out.println("This is a program with class name and file name are different
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
Squaring of two number in Static class
Squaring of two number in Static class  ... method use no instance variables of any object of the class they are defined...; . To square a static method  are define main class and passing the two
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
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
Multiplication of Two Number in Class
Multiplication of Two Number in Class  ... multiply two number. A class consists of a collection of types of encapsulation... that can used to create object of  the class. The class define two public
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
Display Different Elements from two ArrayLists in Java
Display Different Elements from two ArrayLists Java In this section, we are going to compare two array lists and display the different elements from both of them. To show the different elements from the two list, we have created two
Addition of two Number in Class
Addition of two Numbers in Class   ... variables and type of methods. We are going to use in this program of class... in this program  we are going to use addition of  two number. First of all
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
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
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...;); JPanel cp=new JPanel(); text1=new JTextField(10); cp.add(text1
Swap two xml nodes through java class - XML
Swap two xml nodes through java class   Could you please let me know How to swap the two xml nodes thorugh java class
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
Validate
Validate   hi all..im a beginner java and i need some help from u guys.. Its about validate. My HR request BF = 'brought forward', leave cannot... start of the leave is greater than 31/03, it will use the entitlement leave
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
jTextField in swing
jTextField in swing  I am new to java and i am making a registration form.i just want to know if there is any code in which a string cannot be inserted in a jtextfield where a phone number has to be inserted.the jtextfield should
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
Jlist and JTextfield
Jlist and JTextfield  How can we filter values from jlist by adding only a single letter in jtextfield such that when letter S is pressed in jtextfield then jlist should diplay all the values starting from letter S.I am using
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
JTextField
Java JTextField Validation - Java Beginners
Java JTextField Validation  Hello Sir ,How I can Validate JTextField In Java,when I enter Any Character value in JTextField ,I want To Display MsgBox ("Enter only Numeric Value") for Id Field ,How I can Validate that plz Help Me
JtextField - Java Beginners
JtextField  Hi, How can I populate a jtextfield of another Jframe using the information inputted from another Jframe  Hi Friend, Use...*; import java.awt.*; class CreateTable extends JFrame{ CreateTable
How to read and compare content of two different text file
Description: In the given example you will see how a two text file's content are compared. The BufferedReader class allow us to read a file. The readLine() method used to read the contents of the specified file.  The way
Comparing two Dates in Java with the use of before method
Comparing two Dates in Java with the use of before method... of comparing dates you have seen how to use after() method in java class for comparing... with the use of java.util.Date class. For comparing date we are using before() method
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
Copy data from one JTextField to another JTextField
JTextField. When you run this program it starts with two JTextField. Enter some... You can use JTextField into your swing applications to develop data entry... Copy data from one JTextField to another JTextField
VALIDATE
in abow senario i cant use formbean classes directly i can use dynafalidator form
validate select tag items in javascript
validate select tag items in javascript  Hi, How to validate addition of two numbers from two different <select> tag items in JavaScript..? Thanks in advance
can i restrict a class that it will not allows create more than two objects - Java Interview Questions
can i restrict a class that it will not allows create more than two objects  hi all, can i restrict a class that it will not allows create more than two objects can any help me please. Thaks bala k
Using HeaderFooter class of iText API , Can we display multiple phrases in the footer section of PDF ,each with different alignment.
Using HeaderFooter class of iText API , Can we display multiple phrases in the footer section of PDF ,each with different alignment.  Hi, I have a similar question related to HeaderFooter class, I want to display three Phrases
Dividing of two Matrix in Java
;Here you will learn how to use two matrix array for developing Java program. ... are going to use two matrix for dividing the two element. We are going to make... Dividing of two Matrix in Java   

Ads