所以这就是概念:简单地说,有一个带有"名称"作为值的文本框,我希望如果我单击文本框中的任何位置,"名称"值将消失.这就是我在我的代码中所做的:
JTextField t1 = new JTextField("Name", 10);
t1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent cl){
t1.setText(" ");
}
});
Run Code Online (Sandbox Code Playgroud)
没有语法错误,但是当我运行程序并单击文本框中的某个位置时,没有任何反应,值"名称"仍然存在
非常感谢任何帮助,谢谢!
bSub.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(t1.getText().equals("Name") || t2.getText().equals("Section") || t3.getText().equals("Age")){
JOptionPane.showMessageDialog(null, "Please fill in the incomplete fields");
}
//If the 'if statement' above is true, these code below will not execute
t8.setText(t1.getText() + " of " + t2.getText() + " -- " + t3.getText() + " years old");
t9.setText(t1.getText() + " of " + t2.getText() + " -- " + t3.getText() + " years old");
t10.setText(t1.getText() + " of " + t2.getText() + " -- " + t3.getText() + …Run Code Online (Sandbox Code Playgroud)