Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3.  
  4. public class Test1 {
  5. int x = 70;
  6. int y = 70;
  7.  
  8. public static void main (String[] args) {
  9. Test1 gui = new Test1 ();
  10. gui.go();
  11. }
  12. public void go() {
  13. JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  14. MyDrawPanel drawPanel = new MyDrawPanel();
  15. frame.getContentPane().add(drawPanel);
  16. frame.setSize(300,300);
  17. frame.setVisible(true);
  18.  
  19. for (int i = 0; i < 130; i++) {
  20. x++; y++;
  21. drawPanel.repaint();
  22. try { Thread.sleep(50);
  23. } catch(Exception ex) { } }
  24. }// close go() method
  25.  
  26. class MyDrawPanel extends JPanel {
  27. public void paintComponent(Graphics g) {
  28. g.setColor(Color.green);
  29. g.fillOval(x,y,40,40);
  30. }
  31. } // close inner class
  32. } // close outer class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement