Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Swing-AWT validate jtextfield in two different class use keylistener
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


M.Ezilarasi
validate jtextfield in two different class use keylistener
1 Answer(s)      2 years and 11 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


Advertisement
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. 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
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
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 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
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
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
java jtextfield
java jtextfield  how to validate jTextField which accept only number or alphabets from keyboard....plez do help 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
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
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
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
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
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
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
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 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
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 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
VALIDATE
in abow senario i cant use formbean classes directly i can use dynafalidator form
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
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
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
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
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
 

 

 

DMCA.com