2

私はメイン アプリケーションである JFrame を持っています。アプリケーションはRobotクラスを介してマウスを動かします。拡張するクラスを実行してThread、事前定義されたマウス移動イベントのリストを開始、一時停止、および停止できるようにしたいと考えています。また、メインの JFrames テキスト領域に書き込み、何が起こっているかをユーザーに知らせることもできます。

現在、マウスの動きの無限ループでスレッドを開始し、ループ全体でメインテキスト領域を更新しています。それはうまくいきましたが、Netbeans でアプリケーションを書き直し始めた後、JFrames の設計に使用したデザイナーは、スレッド MouseMover の実行中にテキストを更新しないスイング テキスト領域を使用していると思います。

クラスをそのように定義しました

public class MouseMover extends Thread 
{

    MainView theApp;

    public void run()
    {
        try 
        {
            rob = new Robot();
        } 
        catch (AWTException e1) {mainView.newStatusLine("The Robot could not be created");return;}


        while(true) {}
    }

    public void setApp(MainView view)
    {
        theApp = view;

    public void doIt()
    {     
        while(true){
        // move mouse around screen
        rob.mouseMove(0, 100);
        theApp.statusTextArea.setText("moved the mouse");
        }
    }
}

そして、私はスレッドをそのように定義します

public class MainView extends javax.swing.JFrame 
{
       static MouseMover mover;

       public MainView() 
       {
          mover = new MouseMover();
       }

       public void on_goBtn()
       {
           mover.doIt();
       }
 }

I have been told when asking similar questions I am starting the thread wrong, I am trying to fix it now and add some more functionality. So how do I properly start the MouseMover thread so my JFrame stays responsive while the thread can also write to its text area? And the kicker, how might I be able to "pause" the doIt() method of MouseMover?

4

3 に答える 3

2

それはうまくいきましたが、Netbeans でアプリケーションを書き直し始めた後、JFrames の設計に使用したデザイナーは、スレッド MouseMover の実行中にテキストを更新しないスイング テキスト領域を使用していると思います。

于 2013-08-15T08:12:55.050 に答える
1

thread.start実際にスレッドを生成し、オーバーライドされたメソッドを呼び出して並列実行を開始する、コードの最初のものが欠けているようrunです。

于 2013-08-15T07:41:37.017 に答える