1

thread.start()私のメインプログラムから呼び出すと、メソッドrun()は次のようにスレッドで呼び出されます:

public class ServerThread implements Runnable {

        public void run() {
        //executable code
        }

        public void myMethod() {
        //code to hopefully respond to a button press in main class.
        }
}

myMethodメイン クラスから既存のスレッドを呼び出す必要があります。しかし、私が理解しているように、これは使用できませんRunnable。それを行う他の方法はありますか?

4

2 に答える 2

3

これはうまくいくはずです:

ServerThread st = new ServerThread();
new Thread(st).start();
st.myMethod();
于 2013-02-28T12:27:32.927 に答える
0

クラスを変更します。

public class ServerThread implements Runnable, ActionListener {

        public void run() {
        //executable code


        }

        void buttonPressed(ActionEvent ae){

      // your event handling code
    }

}

フレームワーク固有のリスナー クラスとイベント ハンドラーに変更ActionListenerします。buttonPressed()

于 2013-02-28T12:25:52.663 に答える