mousemove.java

来自「有关java的源程序,为讲授java程序设计课程使用」· Java 代码 · 共 61 行

JAVA
61
字号
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class MouseMove extends Applet implements Runnable,MouseMotionListener
{	Thread myThread;
	List ConsumeList=new List();
        List ProduceList=new List();
	int x,y;
	public void init()
	{	
		ConsumeList.resize(size().width/4,size().height);
		ProduceList.resize(size().width/4,size().height);

		setLayout(new BorderLayout());
		add("East",ConsumeList);
		add("West",ProduceList);

                addMouseMotionListener(this);

		if(myThread ==null)
		{	
		   myThread=new Thread(this);
		   myThread.start();
		}
	}
        public void mouseDragged(MouseEvent evt)
        {
	}
        public synchronized void run()
	{	while(myThread ==Thread.currentThread())
		{	ConsumeList.addItem("Consume"+"("+x+","+y+")");
			try
			{wait();
			}
			catch(Exception e)
			{	System.out.println(e);
			}
		}
	}
        public synchronized void mouseMoved(MouseEvent evt)
        {
                this.x=evt.getX();
                this.y=evt.getY();
		ProduceList.addItem("Produce"+"("+x+","+y+")");
		notify();
        }
/*
	public void run()
	{	while(myThread ==Thread.currentThread())
		{	ConsumeList.addItem("Consume"+"("+x+","+y+")");
		}
	}
        public void mouseMoved(MouseEvent evt)
        {       this.x=evt.getX();
                this.y=evt.getY();
		ProduceList.addItem("Produce"+"("+x+","+y+")");
		notify();
        }
*/
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?