Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. package com.mkyong;
  2. import java.awt.Color;
  3. import java.awt.Graphics;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6.  
  7. import javax.swing.JFrame;
  8. import javax.swing.JPanel;
  9. import javax.swing.Timer;
  10.  
  11.  
  12. public class CircleClass extends JPanel {
  13.  
  14. private static final long serialVersionUID = 3725359877575347978L;
  15.  
  16. public static int x;
  17.  
  18. public static int y;
  19.  
  20. public static int w = 50;
  21. public static int h = 50;
  22.  
  23. //public int delay = 10; //in miliseconds
  24.  
  25.  
  26.  
  27. public void paintComponent(Graphics g) {
  28.  
  29. super.paintComponent(g);
  30. //calculate the center of the circles
  31. x = getWidth()/2-w/2;
  32. y = getHeight()/2-h/2;
  33.  
  34.  
  35. g.setColor(Color.white);
  36. g.fillOval(x,y,w,h);
  37.  
  38. //free the graphics context again
  39. g.dispose();
  40. }
  41.  
  42.  
  43.  
  44.  
  45. public static void main (String [] arg){
  46.  
  47. CircleClass circle = new CircleClass();
  48. JFrame frame = new JFrame();
  49. frame.getContentPane().setBackground(Color.black);
  50. frame.add(circle);
  51. circle.setOpaque(false);
  52. frame.setSize(400,400);
  53. frame.setVisible(true);
  54.  
  55.  
  56.  
  57. while (true)
  58. {
  59. for (int i=0; i<150; i++){
  60. h++;
  61. w++;
  62. circle.repaint();
  63. try {
  64. Thread.sleep(15);
  65. }catch(Exception ex){}
  66. }
  67.  
  68. for (int j=150; j>0; j--){
  69. h--;
  70. w--;
  71. circle.repaint();
  72. try {
  73. Thread.sleep(15);
  74. }catch(Exception ex){}
  75. }
  76. }
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement