class1.java

来自「矩阵乘法的计算程序」· Java 代码 · 共 64 行

JAVA
64
字号
import java.awt.*;
import java.awt.event.*;
class TwoListen implements MouseMotionListener,MouseListener, WindowListener{
private Frame f;
 private TextField tf;

	void go(){
		f=new Frame("Two listeners example");
		f.add(new Label("Click and drag the mouse"),"North");
		tf=new TextField(30);
		f.add(tf,"South");
		f.addMouseMotionListener(this);
		f.addMouseListener(this);
		f.addWindowListener (this );
		f.setSize(300,200);
		f.setVisible(true);
	}
	public void mouseDragged(MouseEvent e){
		String s="Mouse dragging:x="+e.getX()+"Y="+e.getY();
		tf.setText(s);
	}
	public void mouseMoved(MouseEvent e){}
	public void mouseClicked(MouseEvent e){}
	
	public void mouseEntered(MouseEvent e){
	String s="The mouse entered";
		tf.setText(s);
	}

	public void mouseExited(MouseEvent e){
	String s="The mouse has left the building";
		tf.setText(s);
	}
	
	public void mousePressed(MouseEvent e){}
	public void mouseReleased(MouseEvent e){}


	public void windowClosing(WindowEvent e){
		System.exit(1);
	};
	
	public void windowOpened(WindowEvent e){}
	public void windowIconified(WindowEvent e){}
	public void windowDeiconified(WindowEvent e){}
	
	public void windowClosed(WindowEvent e){}
	
	public void windowActivated(WindowEvent e){}
	
	public void windowDeactivated(WindowEvent e){}
	
}

public class Class1
{
	
	public static void main (String[] args)
	{
		TwoListen two=new TwoListen();
		two.go();
	}
}

⌨️ 快捷键说明

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