?? chap12-6.txt
字號:
// 程序12-6
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class testEventMouse extends subJFrame {
int xValue,yValue; // 保留鼠標位置( X,Y )
public testEventMouse( ){ // 構造函數
super("testEventMouse"); // 調用subJFrame類中的構造函數
// 請注意下列匿名類的定義
// 定義一個匿名類實現MouseMotionListener接口
addMouseMotionListener(
new MouseMotionListener( ){
public void mouseDragged( MouseEvent e ){
xValue=e.getX( );
yValue=e.getY( );
repaint( ); // 調用paint( )方法
}
public void mouseMoved( MouseEvent e ){
// 必須覆蓋該方法
}
}
);
setSize(300,150);
show( );
}
public void paint(Graphics g){
// super.paint(g); // 不能調用父類中的repaint( )方法
g.fillOval(xValue,yValue,4,4); // 畫圓
}
public static void main(String args[ ]){
testEventMouse obj=new testEventMouse( );
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -