?? drawarcdemo.java
字號:
import javax.swing.*;
import java.awt.Graphics;
import java.awt.Color;
public class DrawArcDemo extends JFrame {
public DrawArcDemo() {
super("繪制圓弧");
this.getContentPane().add(new ArcPanel());
setSize(300,300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
DrawArcDemo frame = new DrawArcDemo();
frame.show();
}
}
class ArcPanel extends JPanel{
public void paintComponent(Graphics g) {
int arcArray[]={30,45,60,90,135};//圓弧的角度
int start=0;//用于計算圓弧的起始角
Color colorArray[]={Color.green,Color.red,Color.blue,Color.yellow,Color.orange};
//繪制正方形外框
g.drawRect(getSize().width/2-100,getSize().height/2-100,200,200);
for(int i=0;i<arcArray.length;i++){
g.setColor(colorArray[i]);//設置填充顏色
g.fillArc(getSize().width/2-100,getSize().height/2-100,200,200,
start,arcArray[i]);
start+=arcArray[i];//計算新的起始角
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -