📄 roundgraph.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package studentscore;import java.awt.*;import javax.swing.*;/** * * @author Conupe Fox */public class RoundGraph extends JPanel{ private Result rs; public RoundGraph(Result rs){ this.rs = rs; } @Override protected void paintComponent(Graphics g){ super.paintComponent(g); //标题 g.setFont(new Font("黑体", 0, 18)); g.drawString("分数段分析饼图", 170, 50); //画圆 int startAngle = 0; int arcAngle = 0; int i = 0; String [] level = {"60以下" , "60-69" , "70-79" , "80-89" , "90以上"}; for(ColorEnum c : ColorEnum.values()){ startAngle += arcAngle; arcAngle = (int)(rs.getPercentage(i) * 360); g.setColor(c.getColor()); g.fillArc(50, 100, 200, 200, startAngle, arcAngle); g.fillRect(300, 100 + i * 50 , 20, 20); g.drawString(level[i] + ": " + String.valueOf(rs.getPercentage(i) * 100) + "%", 330, 110 + i * 50); i++; } } public static void main(String[] args){ JFrame frame = new JFrame(); frame.getContentPane().add(new RoundGraph(new Result())); frame.setVisible(true); frame.setSize(500, 400); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -