用InputVerifier import java.awt.*;
import java.util.*;
import java.awt.event.*;
import javax.swing.*;
// This program demonstrates the use of the Swing InputVerifier class.
// It creates two text fields; the first of the text fields expects the
// string "pass" as input, and will allow focus to advance out of it
// only after that string is typed in by the user. class VerifierTest extends JFrame { public VerifierTest () {
JTextField tf;
tf = new JTextField ("TextField1");
getContentPane().add (tf, BorderLayout.NORTH);
tf.setInputVerifier(new PassVerifier()); tf = new JTextField ("TextField2");
getContentPane().add (tf, BorderLayout.SOUTH);
addWindowListener (new MyWAdapter ());
} public static void main (String [] args) {
Frame f = new VerifierTest ();
f.pack();
f.show();
} class MyWAdapter extends WindowAdapter { public void windowClosing(WindowEvent event) {
System.exit (0);
}
}
class PassVerifier extends InputVerifier { public boolean verify(JComponent input) {
JTextField tf = (JTextField) input;
String pass = tf.getText();
if (pass.equals("pass")) return true;
else return false;
}
}
}
import java.util.*;
import java.awt.event.*;
import javax.swing.*;
// This program demonstrates the use of the Swing InputVerifier class.
// It creates two text fields; the first of the text fields expects the
// string "pass" as input, and will allow focus to advance out of it
// only after that string is typed in by the user. class VerifierTest extends JFrame { public VerifierTest () {
JTextField tf;
tf = new JTextField ("TextField1");
getContentPane().add (tf, BorderLayout.NORTH);
tf.setInputVerifier(new PassVerifier()); tf = new JTextField ("TextField2");
getContentPane().add (tf, BorderLayout.SOUTH);
addWindowListener (new MyWAdapter ());
} public static void main (String [] args) {
Frame f = new VerifierTest ();
f.pack();
f.show();
} class MyWAdapter extends WindowAdapter { public void windowClosing(WindowEvent event) {
System.exit (0);
}
}
class PassVerifier extends InputVerifier { public boolean verify(JComponent input) {
JTextField tf = (JTextField) input;
String pass = tf.getText();
if (pass.equals("pass")) return true;
else return false;
}
}
}
解决方案 »
- Java 有官方的帮助网站吗(⊙_⊙?),类似 MSDN 那种!
- Excel的合并问题(如何把多个单Sheet的Excel合并成一个含有多Sheet的Excel中)?
- *********JAVA 自动更新 **************
- 求助,关于内部类,大侠帮忙啊
- JAVA的包定义后建立的文件夹位置,是不是和编译器有关?
- 关于线程的问题
- 将一个应用程序打包成jar??
- 用Swing,怎样设置整个Application的字体?
- is right or not? why?
- 初学线程,简单的计数程序,帮忙看看
- 请各位大虾帮我看一下,关于 全文搜索引擎 的问题(高分相求)。
- 扩展一个按钮,或者说扩展一个组件,需要铺盖什么方法,在线等候,谢谢
如果变换窗口/最小化, 此方法返回true. 就叫暂时的.
如果你在一个窗口中变化,就是 false.
不用我多说了吧 :)