鼠标进入窗口时响应mouseEntered事件让线程停止(暂停)
鼠标离开窗口时响应mouseExited时间让线程启动 (恢复)

解决方案 »

  1.   

    private void jbInit() throws Exception {
        this.setBackground(Color.white);
        this.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        this.addMouseListener(new java.awt.event.MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            this_mouseClicked(e);
          }
          public void mouseEntered(MouseEvent e) {
            this_mouseEntered(e);
          }
          public void mouseExited(MouseEvent e) {
            this_mouseExited(e);
          }
        });
      }
      
    void this_mouseEntered(MouseEvent e) {
        //imgStop=1;
        try {
          thisThread.wait();
        }
        catch (Exception ex) {    }
      }  void this_mouseExited(MouseEvent e) {
        //imgStop=0;
        try {
          thisThread.start();
        }
        catch (Exception ex) {    }
      }不行啊
      

  2.   

    Component组件中的方法,绝大多数都是单线程的。因此,用线程来控制图片的翻转与否,是不现实的。建议你在mouse的方法中,直接对图片进行控制。
      

  3.   

    我是小应用程序,我启动了一个线程来翻转图片,我想在鼠标事件中控制线程的运作,但是好像不行。thisThread是控制图片运行的线程。在this_mouseEntered暂停线程。在this_mouseExited启动线程。但是实际效果是鼠标进入图片区域,图片仍然翻动,不会停止。我想有谁指出我的错误。还有在jb中指出线程的stop()方法已经不推荐使用了,我用过stop()代替wait(),也不行。
      

  4.   

    void this_mouseExited(MouseEvent e) {
        //imgStop=0;
        try {
          thisThread.start();  改成thisThread.nodify();  this is ok.
        }
        catch (Exception ex) {    }
      }
      

  5.   

    在线程里设置标记,
    通过线程方法修改此标记,
    发现该停止时就wait(),
    再在线程中增加唤醒方法来唤醒线程,如:
    public void go() {
        synchronized(this){
          this.notify();
        }
      }
      

  6.   

    你应该先去看看有关线程的概念:
    1、程序启动就开始你的线程。
    2、在线程中设置是否继续运行的标志位。
    3、通过你的两个事件改变标志位。
    4、现在每次mouseExited会启动一次thisThread.start()。
    5、wait()用法不是这样的。这么简单的线程根本用不到wait
      

  7.   

    start()只能运行一次,应该用wait()在run()的循环内调用wait(),
    线程方法来notify()唤醒!