Java 如何判断是否对if语句执行了actionevent
我需要知道是否执行了特定的操作事件,因为在if语句中,我将执行另一个操作,但这取决于已执行的操作事件Java 如何判断是否对if语句执行了actionevent,java,if-statement,awt,actionevent,Java,If Statement,Awt,Actionevent,我需要知道是否执行了特定的操作事件,因为在if语句中,我将执行另一个操作,但这取决于已执行的操作事件 xButton9.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent x9) { xButton9.setVisible(false); oButton9.setVisible(false);
xButton9.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent x9) {
xButton9.setVisible(false);
oButton9.setVisible(false);
nine.repaint();
nine.add(xlabel);
}
} );
oButton9.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent o9) {
xButton9.setVisible(false);
oButton9.setVisible(false);
nine.repaint();
nine.add(olabel);
}
} );
if (ActionEvent 09 has been performed) {
do this stuff
}
您需要在
actionPerformed()
方法中处理该问题,同时仍有对o9
的引用
oButton9.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent o9) {
xButton9.setVisible(false);
oButton9.setVisible(false);
nine.repaint();
nine.add(olabel);
// whatever else happens when oButton9 is clicked
}
} );
但是,当点击obbutton9时会发生什么情况取决于之前是否点击过其他按钮,是否有一种方法可以编写一个if语句来检查obbutton9的可见性,因为actionevent中的可见性设置为false?我明白了,您必须自己跟踪按钮状态(即哪些已经被按下)在你们班。