📄 rectgraph.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package studentscore;import java.awt.Color;import java.awt.Font;import java.awt.Graphics;import javax.swing.*;/** * * @author Conupe Fox */public class RectGraph extends JPanel{ private Result rs; public RectGraph(Result rs){ this.rs = rs; } @Override protected void paintComponent(Graphics g){ super.paintComponent(g); //标题 g.setFont(new Font("黑体", 0, 18)); g.drawString("分数段分析柱状图", 170, 50); //y轴 g.drawLine(50, 50, 50, 250); //y轴箭头 g.drawLine(50, 50, 40, 60); g.drawLine(50, 50, 60, 60); //x轴 g.drawLine(50, 250, 450, 250); //x轴箭头 g.drawLine(450, 250, 440, 240); g.drawLine(450, 250, 440, 260); //横坐标 g.drawString("60以下", 60, 280); g.drawString("60-69", 130, 280); g.drawString("70-79", 200, 280); g.drawString("80-89", 270, 280); g.drawString("90以上", 340, 280); //标签 g.drawString("人数", 10, 80); g.drawString("分数段", 420, 280); //每人占的像素 int px = 200 / (rs.getMaxScoreList() + 1); //画图形 int i = 0; int x = 60; for(ColorEnum c : ColorEnum.values()){ g.setColor(c.getColor()); g.fillRect(x, 250 - px * rs.getScoreList(i), 40, px * rs.getScoreList(i)); g.drawString(String.valueOf(rs.getScoreList(i)), x + 20, 250 - px * rs.getScoreList(i) - 20); i++; x += 70; } } public static void main(String[] args){ JFrame frame = new JFrame(); frame.getContentPane().add(new RectGraph(new Result())); frame.setVisible(true); frame.setSize(500, 400); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -