Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4. /**
  5. * @(#)BallPanel.java
  6. *
  7. *
  8. * @author
  9. * @version 1.00 2011/5/11
  10. */
  11.  
  12.  
  13. public class BallPanel extends JPanel implements MouseMotionListener {
  14.  
  15. static int x = 10;
  16. static int y = 10;
  17.  
  18. public BallPanel() {
  19.  
  20. setBackground(Color.black);
  21.  
  22. addMouseMotionListener(this);
  23. }
  24.  
  25. public void paintComponent(Graphics g){
  26.  
  27. super.paintComponent(g);
  28. g.setColor(Color.orange);
  29.  
  30. g.fillOval(x-10, y-10, 20, 20);
  31. }
  32.  
  33.  
  34.  
  35. public void mouseDragged(MouseEvent event){
  36. x = event.getX();
  37. y = event.getY();
  38.  
  39. repaint();
  40. }
  41.  
  42. public void mouseMoved(MouseEvent event){
  43. }
  44. }
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63. import java.awt.*;
  64. import javax.swing.*;
  65. /**
  66. * @(#)MovingBall.java
  67. *
  68. * MovingBall application
  69. *
  70. * @author cemo
  71. * @version 1.00 2011/5/11
  72. */
  73.  
  74. public class MovingBall {
  75.  
  76. public static void main(String[] args) {
  77.  
  78. JFrame frame = new JFrame("ayy");
  79.  
  80. BallPanel panel = new BallPanel();
  81.  
  82. frame.getContentPane().add(panel);
  83.  
  84.  
  85. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  86. frame.setBounds(200,200, 500, 500);
  87. frame.setBackground(Color.white);
  88. frame.setVisible(true);
  89.  
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement