日期:2014-05-20 浏览次数:20705 次
import java.awt.BasicStroke; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JPanel; import org.omg.CORBA.PUBLIC_MEMBER; public class Circle extends JPanel{ private int value; public Circle(){ } public Circle(int value){ this.value = value; } public int getValue(){ return value; } public void setValue(int value){ this.value = value; //System.out.print(value); repaint(); } protected void paintComponent(Graphics g){ super.paintComponent(g); int clockRadius = (int)(Math.min(getWidth(), getHeight())*0.8*0.5); int xCenter = getWidth()/2; int yCenter = getHeight()/2; g.setColor(Color.RED); g.drawOval(xCenter-clockRadius, yCenter-clockRadius, 2*clockRadius, 2*clockRadius); //System.out.print(value); int line1 = (int)(clockRadius); int line1X = (int) (xCenter-clockRadius*Math.cos(value*(2*Math.PI/60))); int line1Y = yCenter+value; g.drawLine(xCenter, yCenter, line1X, line1Y); } public Dimension getPreferredSize() { return new Dimension(100,100); } }