如果您试图让同一个事件执行两个操作,那么您可以尝试以下操作:
int choice = 0;
public void actionPerformed(ActionEvent ev){
if ( choice == 0 ) {
String whatever = tf.getText();
if(whatever.equalsIgnoreCase("good"){
inout.append("blahh");
...
choice++;
}// end first action
else if ( choice == 1 ) {
//Second action
//Your code for what happens the second time would go here
choice++;
} else {
//you can do this forever
}
}
作为一个新程序员,你应该明白为什么会这样:
代码有无穷无尽的可能性。通过看到这一点,您应该注意到您可以将许多循环、开关和其他您在此之前使用过的语句结合起来。在这种情况下,我将做出一个条件选择,以更改单击 JButton 时发生的情况。
当您变得更好时,您将了解线程和事件,它们本质上是 Java 中内置的线程,您将能够做更多的事情。
继续努力,永远不要放弃一个难题:D。