validate jtextfield in two different class use keylistener

Ads

 
 

Share on Google+Share on Google+

M.Ezilarasi
validate jtextfield in two different class use keylistener
1 Answer(s)      5 years and 9 months ago
Posted in : Swing AWT

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

Ads
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
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
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
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
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
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 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
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
java jtextfield
java jtextfield  how to validate jTextField which accept only number or alphabets from keyboard....plez do help me
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
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
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...("This is a program with class name and file name are different"); } } when I run
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
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
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
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
Use of Throwable Class
Use of Throwable Class Throwable class is the super class of all the exceptional class and error class. Only objects of this class can be thrown & caught... are derived from throwable class. To create your own class of throwable objects
Use Group Class in SWT
Use Group Class in SWT       In this section, you will learn how to use Group class. In SWT, the class Group of package org.eclipse.swt.widgets provides an etched border
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