package chapter15;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Graphics;
@SuppressWarnings("serial")
public class DrawArcs extends JFrame{
public DrawArcs(){
setTitle("drawarcs");
add(new ArcsPanel());
}
public static void main(String[] args) {
DrawArcs frame = new DrawArcs();
//frame.setTitle("asd");
frame.setLocationRelativeTo(null);
//frame.pack();
frame.setSize(250,300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
@SuppressWarnings("serial")
class ArcsPanel extends JPanel{
protected void paintComponent(Graphics g) {
super.paintComponent(g);
int xCenter = getWidth()/2;
int yCenter = getHeight()/2;
int radius = (int)(Math.min(getWidth(), getHeight())*0.4);//控制半径
int x = xCenter - radius;
int y = yCenter - radius;
g.fillArc(x, y, 2*radius, 2*radius, 0, 30);
g.fillArc(x, y, 2*radius, 2*radius, 90, 30);
g.fillArc(x, y, 2*radius, 2*radius, 180, 30);
g.fillArc(x, y, 2*radius, 2*radius, 270, 30);
}
}