main8_1.java

来自「200多个自己编的java程序,大家可以学一下.」· Java 代码 · 共 94 行

JAVA
94
字号
import java.awt.*;
import java.awt.event.*;

public class Main8_1 implements MouseMotionListener,MouseListener,KeyListener
{
	Label statusBar=new Label();
	private Frame f;
	String ch="";
	private TextField tf;
  // there can be go or any name
	public void went()
	{
		f=new Frame("Example");
		f.add("South",statusBar);
		f.add("North",tf);
		f.addMouseMotionListener(this);
		f.addMouseListener(this);
		f.addKeyListener(this);
		f.setSize(600,800);
		f.show();
		
	}
	//implement interface method 
	public void mouseClicked(MouseEvent e){
		String s="the mouse Clicked";
		tf.setText(s);
		
		};
	public void mouseEntered(MouseEvent e){
		
		String s="the mouse enter";
		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 mouseDragged(MouseEvent e){
				int x=e.getX();
		int y=e.getY();
		String status="(x="+x+","+"y="+y+")"+ch;
		statusBar.setText(status);
		
		
	}
	
	
	public void mouseMoved(MouseEvent e){
				int x=e.getX();
		int y=e.getY();
		String status="(x="+x+","+"y="+y+")"+ch;
		statusBar.setText(status);
		
	}
	
	public void keyTyped(KeyEvent k){
		
	}
	public void keyPressed(KeyEvent k){
		int charcode=k.getKeyCode();
		ch="d";
		if(charcode==KeyEvent.VK_SHIFT)ch="D";
		if(charcode==KeyEvent.VK_CONTROL)ch="C";
		
	}
	
	public void keyReleased(KeyEvent k){
		ch="u";
		int charcode=k.getKeyCode();
		if(charcode==KeyEvent.VK_SHIFT)ch="U";
		
	}

	/**
	 * Method main
	 *
	 *
	 * @param args
	 *
	 */
	public static void main(String[] args) {
		// TODO: Add your code here
		
		Main8_1 mwin=new Main8_1();
		mwin.went();
	}



	
}

⌨️ 快捷键说明

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