📄 main8_1.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -