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 KeyListener
How to use KeyListener      ... to handle different key events on the Java Awt component by using the event handling... on. All the key events are handled through the KeyListener Interface that has
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
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
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
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
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
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
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
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
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
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...; 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... 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 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
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
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
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...; we are going to use addition of  two number. First of all, we have
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
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
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
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

Ads