⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chap12-6.txt

📁 JAVA 学习资源
💻 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 + -