0

actionPerformedイベントメソッドを一度だけ使用したいだけです。例: 1 つのテキストフィールドから 2 つの値を取得しようとしています。

public void actionPerformed(ActionEvent ev){
     String whatever = tf.getText();
     if(whatever.equalsIgnoreCase("good"){
     inout.append("blahh");
     //and then I'm trying to get a new value from the user without it resetting.
}
4

1 に答える 1

0

同じイベントに 2 つのアクションを実行させようとしている場合は、次の方法を試すことができます。

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.

于 2013-07-30T00:55:02.573 に答える