首页 新闻 搜索 专区 学院

java mouseClicked 无响应

0
悬赏园豆:5 [已关闭问题] 关闭于 2014-11-19 20:05
 1 /*
 2 鼠标单击面板,在单击处画一个圆
 3 */
 4 import java.awt.*;
 5 import java.awt.event.*;
 6 import javax.swing.*;
 7 
 8 
 9 public class MouseMessage extends JFrame
10 {
11     public MouseMessage()
12     {
13         MousePanel p = new MousePanel();
14         add(p);
15     }
16     
17     public static void main(String[] args)
18     {
19         MouseMessage frame = new MouseMessage();
20         frame.setTitle("show");
21         frame.setSize(240,480);
22         frame.setLocationRelativeTo(null);
23         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
24         frame.setVisible(true);
25     }
26     
27 }
28 
29 //面板类
30 class MousePanel extends JPanel
31 {
32     private int x = 0,y = 0;
33     public MousePanel()
34     {
35         addMouseMotionListener(new MouseMotionAdapter()
36         {
37             public void mouseClicked(MouseEvent e)
38             {
39                 x = e.getX();
40                 y = e.getY();
41                 //repaint();
42             }
43         });
44     }
45     protected void paintComponent(Graphics g)
46     {
47         super.paintComponent(g);
48         g.setColor(Color.RED);
49         g.fillOval(x,y,10,10);
50     }
51 }
zd_Ran的主页 zd_Ran | 初学一级 | 园豆:102
提问于:2014-11-01 19:36
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册