📄 starondot.java
字号:
import javax.swing.*;import java.awt.*;/** StarOnDotSupplier Class * Author: David D. Riley * Date: April, 2004 * * Class Invariant * This class draws a filled circle in the background color * with a 5-pointed star inscribed within the circle and * using the foreground color. This minimum of getWidth() * and getHeight() is used for the dot's diameter. */public class StarOnDot extends JComponent { public StarOnDot() { super(); } public void paint(Graphics g) { double diameter = getWidth(); if (getHeight() < diameter) diameter = getHeight(); // draw the filled circle g.setColor( getBackground() ); g.fillOval(0, 0, (int)diameter-1, (int)diameter-1); /* Draw the 5-pointed star using points at the following degree * measurements (270 degrees would be the top apex of the star): * 54, 126, 198, 270, and 342 degrees */ g.setColor( getForeground() ); g.drawLine( (int)(diameter/2+Math.cos(Math.toRadians(54))*diameter/2), (int)(diameter/2+Math.sin(Math.toRadians(54))*diameter/2), (int)(diameter/2+Math.cos(Math.toRadians(198))*diameter/2), (int)(diameter/2+Math.sin(Math.toRadians(198))*diameter/2) ); g.drawLine( (int)(diameter/2+Math.cos(Math.toRadians(126))*diameter/2), (int)(diameter/2+Math.sin(Math.toRadians(126))*diameter/2), (int)(diameter/2+Math.cos(Math.toRadians(270))*diameter/2), (int)(diameter/2+Math.sin(Math.toRadians(270))*diameter/2) ); g.drawLine( (int)(diameter/2+Math.cos(Math.toRadians(198))*diameter/2), (int)(diameter/2+Math.sin(Math.toRadians(198))*diameter/2), (int)(diameter/2+Math.cos(Math.toRadians(342))*diameter/2), (int)(diameter/2+Math.sin(Math.toRadians(342))*diameter/2) ); g.drawLine( (int)(diameter/2+Math.cos(Math.toRadians(270))*diameter/2), (int)(diameter/2+Math.sin(Math.toRadians(270))*diameter/2), (int)(diameter/2+Math.cos(Math.toRadians(54))*diameter/2), (int)(diameter/2+Math.sin(Math.toRadians(54))*diameter/2) ); g.drawLine( (int)(diameter/2+Math.cos(Math.toRadians(342))*diameter/2), (int)(diameter/2+Math.sin(Math.toRadians(342))*diameter/2), (int)(diameter/2+Math.cos(Math.toRadians(126))*diameter/2), (int)(diameter/2+Math.sin(Math.toRadians(126))*diameter/2) ); paintChildren(g); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -