Note that there are some explanatory texts on larger screens.

plurals
  1. POvalidate jtextfield in two different class use keylistener
    primarykey
    data
    text
    <p>I created a <code>classA</code> for designing process and <code>classB</code> for creating methods; that method is used to call a <code>classA</code> <code>JTextField</code>. <code>JtextField1</code> is used to update only uppercase <code>String</code>, <code>JTextField2</code> is used to update only numeric values; <code>Jtextfield3</code> is used to update email ID format. I am getting an error when I am calling from another class. I can't to call that <code>ClassB</code> method in <code>ClassA</code> <code>JTextField</code>. </p> <pre><code>import javax.swing.*; import java.awt.*; import java.awt.event.*; class sample { JLabel label1 = new JLabel("name"); JLabel label2 = new JLabel("reg.no"); JTextField text1 = new JTextField(10); JTextField text2 = new JTextField(10); JFrame fr = new JFrame(); public sample() { JPanel jp = new JPanel(new GridLayout(2, 2)); KeyListener textkey = new textListener(); text1.addKeyListener(textkey);//created a keylistener for text1 text2.addKeyListener(textkey);//created a keylistener for text2 jp.add(label1); jp.add(text1); jp.add(label2); jp.add(text2); fr.add(jp); fr.pack(); fr.setSize(430, 350); fr.setTitle("form1"); fr.setVisible(true); } class textListener implements KeyListener {//keyListener is implemented public void keyTyped(KeyEvent e) { } public void keyReleased(KeyEvent e) { } public void keyPressed(KeyEvent e) { JLabel label = new JLabel(); String value = text1.getText(); String value1 = text2.getText(); String keyString; int l = value.length(); if ((e.getKeyCode() &gt;= KeyEvent.VK_A &amp;&amp; e.getKeyCode() &lt;= KeyEvent.VK_Z) || (e.getKeyCode() == KeyEvent.VK_BACK_SPACE) || (e.getKeyCode() == KeyEvent.VK_CAPS_LOCK)) { text1.setEditable(true); } else { JOptionPane.showMessageDialog(label, "Enter Alpha", "InputError", JOptionPane.ERROR_MESSAGE); } } } public static void main(String ar[]) { new sample(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload