Guest User

Untitled

a guest
Feb 25th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. public class Tester {
  2. public static void main(String[] args) {
  3. Frame frame = new Frame();
  4. frame.start();
  5. }
  6. }
  7. class Frame {
  8. private JFrame frame;
  9. private Paint oval;
  10. private int x,y;
  11. Frame(){
  12. x = y = 120;
  13. frame = new JFrame();
  14. oval = new Paint();
  15. }
  16. public void start() {
  17. frame.getContentPane().add(oval);
  18. frame.setSize(700, 700);
  19. frame.setVisible(true);
  20.  
  21. for(int count = 0;count <400;count++) {
  22. x++;
  23. y++;
  24. oval.repaint();
  25.  
  26. try {
  27. Thread.sleep(25);
  28. } catch (Exception ex) {
  29.  
  30. }
  31. }
  32. }
  33. class Paint extends JPanel {
  34. public void paintComponent(Graphics g) {
  35. g.setColor(Color.WHITE);
  36. g.fillRect(0, 0, this.getWidth(), this.getHeight());
  37. g.setColor(Color.ORANGE);
  38. g.fillOval(x,y, 100, 100);
  39. }
  40. }
  41. }
  42.  
  43. g.setColor(Color.WHITE);
  44. g.fillRect(0, 0, this.getWidth(), this.getHeight());
  45.  
  46. public class Tester {
  47. public static void main(String[] args) {
  48. Frame frame = new Frame();
  49. frame.start();
  50. }
  51. }
  52. class Frame {
  53. private JFrame frame;
  54. private Paint oval;
  55. private int x,y;
  56. Frame() {
  57. x = y = 120;
  58. frame = new JFrame();
  59. oval = new Paint();
  60. }
  61. public void start() {
  62. frame.getContentPane().add(oval);
  63. frame.setSize(700, 700);
  64. frame.setVisible(true);
  65.  
  66. for (int count = 0;count <400;count++) {
  67. x++;
  68. y++;
  69. **frame.repaint();**
  70.  
  71. try {
  72. Thread.sleep(25);
  73. } catch (Exception ex) {
  74.  
  75. }
  76. }
  77. }
  78. class Paint extends JPanel {
  79. public void paintComponent(Graphics g) {
  80. g.setColor(Color.ORANGE);
  81. g.fillOval(x,y, 100, 100);
  82. }
  83. }
  84. }
  85.  
  86. public void paintComponent(Graphics g){
  87. super.paintComponent(g); // <<<
  88. g.setColor(Color.ORANGE);
  89. g.fillOval(x,y, 100, 100);
  90. }
Add Comment
Please, Sign In to add comment