Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

inputverifier - work with JOptionPane?  RSS feed

 
Arthur Gober
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to get the inputverifier class to work with JOptionPane class. In the small pgm below,when I comment out the lines of JOptionPane, all works well. But when not, it goes whacky. Any suggestions would be appreciated.
Thank you.

import java.awt.*;
import java.util.*;
import java.awt.event.*;
import javax.swing.*;
class tstvrfy extends JFrame
{
JTextField tf1,tf2;
tstvrfy()
{
tf1 = new JTextField("Type \"pass\" here.");
getContentPane().add(tf1,BorderLayout.NORTH);
tf1.setInputVerifier(new passverifier());
tf2 = new JTextField("textfld2");
getContentPane().add(tf2,BorderLayout.SOUTH);
WindowListener l = new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
};
addWindowListener(l);
}
class passverifier extends InputVerifier
{
public boolean verify(JComponent input)
{
JTextField tf = (JTextField) input;
System.out.println("tf="+tf.getText());
tf2.setText("typed "+tf.getText());

if ("pass".equals(tf.getText())) return true;
else
{
JOptionPane.showMessageDialog(tstvrfy.this,"Not a Valid entry",
"Invalid entry",JOptionPane.ERROR_MESSAGE);
return false;
}
}
}
public static void main (String[] args)
{
tstvrfy f = new tstvrfy();
f.pack();
f.setVisible(true);
}
}
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!