import java
import java
import javax
public class MoveMessageDemo extends JFrame {
public MoveMessageDemo() {
MoveMessagePanelNew p = new MoveMessagePanelNew(
getContentPane()
getContentPane()
}
/** Main method */
public static void main(String[] args) {
MoveMessageDemo frame = new MoveMessageDemo();
frame
frame
frame
frame
}
}
// MoveMessagePanel draws a message
class MoveMessagePanel implements MouseMotionListener {
public void mouseMoved(MouseEvent e) {
}
/** Handle mouse dragged event */
public void mouseDragged(MouseEvent e) { //鼠標按鍵在組件上按下並拖動時調用
// Get the new location and repaint the screen
System
System
}
}
// MoveMessagePanelNew draws a message
class MoveMessagePanelNew extends JPanel implements MouseMotionListener {
private String message =
private int x =
private int y =
public MoveMessagePanelNew(String s) {
message = s;
this
}
public void mouseMoved(MouseEvent e) {
}
public void mouseDragged(MouseEvent e) {
// Get the new location and repaint the screen
x = e
y = e
repaint();
}
protected void paintComponent(Graphics g) {
super
g
}
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/25637.html