package com.aa; import java.awt.Color; import java.awt.Graphics; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; //内部类,和接口的实现 import javax.swing.*; //现在实现用鼠标点击一下,画一个圆 class Circle extends JFrame { int x, y; public Circle() { ini(); this.setVisible(true); this.setSize(400, 400); this.setDefaultCloseOperation(3); } public void paint(Graphics g) { g.setColor(Color.red); // g.fillOval(x, y, 23, 23); g.drawOval(x, y, 32, 32); } void ini() { this.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent m) { x = m.getPoint().x; y = m.getPoint().y; repaint();// 重画 } });// 匿名类写法 } } public class LEI {// 主类是作为测试类 public static void main(String[] args) { Circle c = new Circle(); } }