Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- /**
- * @(#)BallPanel.java
- *
- *
- * @author
- * @version 1.00 2011/5/11
- */
- public class BallPanel extends JPanel implements MouseMotionListener {
- static int x = 10;
- static int y = 10;
- public BallPanel() {
- setBackground(Color.black);
- addMouseMotionListener(this);
- }
- public void paintComponent(Graphics g){
- super.paintComponent(g);
- g.setColor(Color.orange);
- g.fillOval(x-10, y-10, 20, 20);
- }
- public void mouseDragged(MouseEvent event){
- x = event.getX();
- y = event.getY();
- repaint();
- }
- public void mouseMoved(MouseEvent event){
- }
- }
- import java.awt.*;
- import javax.swing.*;
- /**
- * @(#)MovingBall.java
- *
- * MovingBall application
- *
- * @author cemo
- * @version 1.00 2011/5/11
- */
- public class MovingBall {
- public static void main(String[] args) {
- JFrame frame = new JFrame("ayy");
- BallPanel panel = new BallPanel();
- frame.getContentPane().add(panel);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setBounds(200,200, 500, 500);
- frame.setBackground(Color.white);
- frame.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement