📄 mousexy.java
字号:
//==============================================================
// MouseXY.java - Demonstrates old style AWT handleEvent() method
//
// Java学习源代码检索系统 Ver 1.0 20031015 免费正式版
// 版权所有: 中国IT认证实验室(www.ChinaITLab.com)
// 程序制作: ChinaITLab网校教研中心
// 主页地址: www.ChinaITLab.com 中国IT认证实验室
// 论坛地址: bbs.chinaitlab.com
// 电子邮件: Java@ChinaITLab.com
//==============================================================
import java.applet.*;
import java.awt.*;
public class MouseXY extends Applet {
String location; // String for X=0 Y=0 display
// Initialize applet variables and window
public void init() {
setBackground(Color.yellow);
resize(200, 100);
location = new String("Move mouse inside window");
}
// Paint the location string inside window
public void paint(Graphics g) {
g.drawString(location, 10, 10);
}
// Create the location string from x and y
public void makeString(int x, int y) {
location = new String(
" X=" + String.valueOf(x) +
" Y=" + String.valueOf(y) );
}
// Handle all events for this applet
public boolean handleEvent(Event evt) {
boolean eventHandled = false;
switch (evt.id) {
case Event.MOUSE_DOWN:
case Event.MOUSE_UP:
case Event.MOUSE_DRAG:
case Event.MOUSE_ENTER:
case Event.MOUSE_MOVE: {
makeString(evt.x, evt.y);
repaint();
eventHandled = true;
break;
}
case Event.MOUSE_EXIT: {
location = new String("Move mouse inside window");
repaint();
eventHandled = true;
}
}
if (eventHandled)
return true;
else
return super.handleEvent(evt);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -