【发布时间】:2016-10-11 19:14:10
【问题描述】:
我有一个 gui 类,它有三个不同的 JButtons 链接到一个 ActionListener。
在ActionListener 类中,我希望在这三个JButtons 之间进行交互,以使程序能够“记住”之前单击了哪个按钮。
例如:
- 如果 button1 被点击 --> 记住这一点,
- 然后当 button2 被点击时:做一个相对于 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
}
}
}
【问题讨论】:
-
gets clicked next是什么意思?是否允许他同时不允许查看他的电子邮件?
标签: java swing jbutton actionlistener actionevent