Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mkyong;
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.Timer;
- public class CircleClass extends JPanel {
- private static final long serialVersionUID = 3725359877575347978L;
- public static int x;
- public static int y;
- public static int w = 50;
- public static int h = 50;
- //public int delay = 10; //in miliseconds
- public void paintComponent(Graphics g) {
- super.paintComponent(g);
- //calculate the center of the circles
- x = getWidth()/2-w/2;
- y = getHeight()/2-h/2;
- g.setColor(Color.white);
- g.fillOval(x,y,w,h);
- //free the graphics context again
- g.dispose();
- }
- public static void main (String [] arg){
- CircleClass circle = new CircleClass();
- JFrame frame = new JFrame();
- frame.getContentPane().setBackground(Color.black);
- frame.add(circle);
- circle.setOpaque(false);
- frame.setSize(400,400);
- frame.setVisible(true);
- while (true)
- {
- for (int i=0; i<150; i++){
- h++;
- w++;
- circle.repaint();
- try {
- Thread.sleep(15);
- }catch(Exception ex){}
- }
- for (int j=150; j>0; j--){
- h--;
- w--;
- circle.repaint();
- try {
- Thread.sleep(15);
- }catch(Exception ex){}
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement