Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.edfmedia;
- import java.awt.BorderLayout;
- import java.awt.Color;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.util.concurrent.Executors;
- import java.util.concurrent.ScheduledExecutorService;
- import java.util.concurrent.TimeUnit;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- class DrawCircle extends JPanel{
- class Raza {
- int value = 50;
- public int getValue() {
- return value;
- }
- public void setValue(int value) {
- this.value = value;
- }
- public void add(int value) {
- this.value += value;
- }
- }
- private Raza raza = new Raza();
- public DrawCircle() {
- // setBackground(Color.green);
- setOpaque(true);
- final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
- scheduler.scheduleAtFixedRate(new Runnable() {
- @Override
- public void run() {
- if (raza.getValue() < 100) {
- raza.add(5);
- repaint();
- }
- }
- }, 0, 1, TimeUnit.SECONDS);
- }
- @Override
- public void paint(Graphics g) {
- super.paint(g);
- g.setColor(new Color(0, 255,0));
- g.drawOval(100, 100, 2 * raza.getValue(), 2 * raza.getValue());
- }
- @Override
- public Dimension getPreferredSize() {
- return new Dimension(100, 100);
- }
- public static void main(String[] args) {
- JFrame frame = new JFrame();
- frame.setPreferredSize(new Dimension(400, 400));
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.add(new DrawCircle(), BorderLayout.CENTER);
- frame.pack();
- frame.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement