1 30 31 package com.jgoodies.animation.components; 32 33 import java.awt.*; 34 35 import javax.swing.JComponent ; 36 37 43 public final class CircleComponent extends JComponent { 44 45 private Point center; 46 private int radius; 47 private Color color; 48 49 52 public CircleComponent() { 53 center = new Point(0, 0); 54 radius = 30; 55 color = Color.black; 56 } 57 58 public void setCenter(Point p) { 59 this.center = p; 60 } 61 62 public void setRadius(int radius) { 63 this.radius = radius; 64 } 65 66 public void setColor(Color color) { 67 this.color = color; 68 } 69 70 78 public void setBounds(int x, int y, int w, int h) { 79 super.setBounds(x, y, w, h); 80 setCenter(new Point(x + w / 2, y + h / 2)); 81 } 82 83 89 public void paintComponent(Graphics g) { 90 Graphics2D g2 = (Graphics2D) g; 91 92 int diameter = radius * 2; 93 g2.setRenderingHint( 94 RenderingHints.KEY_ANTIALIASING, 95 RenderingHints.VALUE_ANTIALIAS_ON); 96 g.setColor(color); 97 g2.setStroke(new BasicStroke(4)); 98 g2.drawOval(center.x - radius, center.y - radius, diameter, diameter); 99 } 100 101 } | Popular Tags |