好的,所以每个文本字段都是动作侦听器。我做了很多测试,发现添加动作监听器不是问题。问题出在下面的代码中,因为对于前四个文本字段,显示了 hello 窗口,但没有显示 ok。但在底部,会弹出 ok 窗口和 hello 窗口。我做错了什么?
public class handler implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
if (event.getSource() == text)
{
JOptionPane.showMessageDialog(null, "ok");
}
else if (event.getSource() == text1)
{
JOptionPane.showMessageDialog(null, "ok");
}
else if (event.getSource() == text2)
{
JOptionPane.showMessageDialog(null, "ok");
}
else if (event.getSource() == text3)
{
JOptionPane.showMessageDialog(null, "ok");
}
else if (event.getSource() == text4)
{
JOptionPane.showMessageDialog(null, "ok");
}
JOptionPane.showMessageDialog(null, "hello");
}
}