import
java.awt.*;
import
java.awt.event.*;
public
class
MouseInput
extends
Core implements
KeyListener, MouseMotionListener, MouseListener, MouseWheelListener {
public
static
void
main(String[] args) {
new
MouseInput().run();
}
private
String mess
= "";
//init
public
void
init() {
super.init();
Window
w = s.getFullScreenWindow();
w.addMouseListener(this);
→
當鼠標點擊
w.addMouseMotionListener(this);
→
當鼠標拖動和移動
w.addMouseWheelListener(this);
→
內置鼠標的方法
w.addKeyListener(this);
}
//繪製方法
public
synchronized
void
draw(Graphics2D g) {
Window
w = s.getFullScreenWindow();
g.setColor(w.getBackground());
g.fillRect(0,
0, s.getWidth(),
s.getHeight());
g.setColor(w.getForeground());
g.drawString(mess,
30, 30);
}
//鼠標監聽器
public
void
mousePressed(MouseEvent e) {
mess
= "You
pressed down the mouse";
}
public
void
mouseReleased(MouseEvent e) {
mess
= "You
released the mouse";
}
public
void mouseClicked(MouseEvent e) {}
public
void mouseEntered(MouseEvent e) {}
public
void mouseExited(MouseEvent e) {}
}
沒有留言:
張貼留言