我有一个gui类,它有三个不同的JButtons
链接到一个ActionListener
。Java动作监听器和JButtons
在ActionListener
类中,我希望这三个JButtons
之间的交互方式允许程序“记住”之前点击过哪个按钮。
例如:
- 如果Button1的点击 - >记住这一点,
- 然后,当按钮2被点击下一页:做一个动作相对于BUTTON1被点击。
换句话说,如果button1单击,现在在if子句内检查button2单击。
现在getActionCommand()
不允许我使用嵌套的if语句,因为它只检查当前点击的按钮并且没有“内存”。
public void actionPerformed(ActionEvent e){
if (Integer.parseInt(e.getActionCommand()) == 0){
System.out.println("This is Jug 0");
// wont be able to print the following
if (Integer.parseInt(e.getActionCommand()) == 1){
System.out.println("This is Jug 1 AFTER jug 0"); //I will never be able to print this
}
}
}
什么意思'被点击下一个'?同时允许他不允许检查他的电子邮件吗? –