为什么提示框会出现两次?
//ListDemo.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ListDemo extends JFrame implements FocusListener {
TextField txtInput1 = new TextField();
TextField txtInput2 = new TextField();
List lst = new List();
JLabel lbl = new JLabel("Sperator");
JButton btn = new JButton("Add");
JPanel plst = new JPanel();
static Boolean show = false;
public ListDemo(){
Container con = getContentPane();
setLayout(new BorderLayout());
con.add("North",plst);
con.add("Center",lst);
con.add("South",btn);
plst.setLayout(new GridLayout(3,1));
plst.add(txtInput1);
plst.add(txtInput2);
plst.add(lbl);
txtInput1.addFocusListener(this);
txtInput2.addFocusListener(this);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setVisible(true);
}
public static void main(String [] args){
new ListDemo();
}
public void focusLost(FocusEvent fe){
if (((TextField)fe.getSource()).getText().trim().equals("")){
System.out.println(show);
System.out.println(((TextField)fe.getSource()).getName());
show =!show;
if (show){
((TextField)fe.getSource()).requestFocus();
JOptionPane.showMessageDialog(null,"请输入内容","ERROR",JOptionPane.ERROR_MESSAGE);
}
//show =!show;
}
}
public void focusGained(FocusEvent fe){
}
}
问题点数:10、回复次数:2Top
1 楼norwolfli(烟灰)回复于 2006-03-03 12:38:34 得分 0
只有一个啊!Top
2 楼yoshubom(五月书.D.店)回复于 2006-03-03 12:43:50 得分 0
如果从一个文本框移动到另一个文本框的时候出现两个。如何限制它只出现一个?Top




