首页 > 代码库 > 练习.鼠标控制小球
练习.鼠标控制小球
1 package com.java7mousecontrolmyball.main; 2 import java.awt.Frame; 3 import java.awt.Graphics; 4 import java.awt.Panel; 5 import java.awt.event.MouseEvent; 6 import java.awt.event.MouseMotionListener; 7 8 public class MouseControlMyBall { 9 public static void main(String[] args) {10 Frame w = new Frame();11 w.setSize(300, 400);12 13 MyPanel mp = new MyPanel();14 w.add(mp);15 16 w.addMouseMotionListener(mp);17 mp.addMouseMotionListener(mp);18 19 w.show();20 }21 }22 23 class MyPanel extends Panel implements Runnable , MouseMotionListener {24 int x = 30;25 int y = 30;26 public void paint(Graphics g){27 g.fillOval(x, y, 30, 30);28 }29 @Override30 public void mouseDragged(MouseEvent arg0) {31 x = arg0.getX();32 y = arg0.getY();33 // System.out.println(x);34 // System.out.println(y);35 repaint();36 }37 @Override38 public void mouseMoved(MouseEvent arg0) {39 // System.out.println(arg0);40 }41 @Override42 public void run() {43 // TODO Auto-generated method stub44 45 }46 }
练习.鼠标控制小球
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。