Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. package com.edfmedia;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.Color;
  5. import java.awt.Dimension;
  6. import java.awt.Graphics;
  7. import java.util.concurrent.Executors;
  8. import java.util.concurrent.ScheduledExecutorService;
  9. import java.util.concurrent.TimeUnit;
  10.  
  11. import javax.swing.JFrame;
  12. import javax.swing.JPanel;
  13.  
  14.  
  15. class DrawCircle extends JPanel{
  16.  
  17. class Raza {
  18. int value = 50;
  19.  
  20. public int getValue() {
  21. return value;
  22. }
  23.  
  24. public void setValue(int value) {
  25. this.value = value;
  26. }
  27.  
  28. public void add(int value) {
  29. this.value += value;
  30. }
  31. }
  32.  
  33. private Raza raza = new Raza();
  34.  
  35. public DrawCircle() {
  36. // setBackground(Color.green);
  37. setOpaque(true);
  38. final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
  39. scheduler.scheduleAtFixedRate(new Runnable() {
  40. @Override
  41. public void run() {
  42. if (raza.getValue() < 100) {
  43. raza.add(5);
  44. repaint();
  45. }
  46. }
  47. }, 0, 1, TimeUnit.SECONDS);
  48.  
  49. }
  50.  
  51. @Override
  52. public void paint(Graphics g) {
  53. super.paint(g);
  54. g.setColor(new Color(0, 255,0));
  55. g.drawOval(100, 100, 2 * raza.getValue(), 2 * raza.getValue());
  56. }
  57.  
  58. @Override
  59. public Dimension getPreferredSize() {
  60. return new Dimension(100, 100);
  61. }
  62.  
  63. public static void main(String[] args) {
  64. JFrame frame = new JFrame();
  65. frame.setPreferredSize(new Dimension(400, 400));
  66. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  67.  
  68. frame.add(new DrawCircle(), BorderLayout.CENTER);
  69.  
  70. frame.pack();
  71. frame.setVisible(true);
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement