📄 chartframe.java
字号:
import java.awt.*;
import javax.swing.*;
import java.awt.Font;
import java.util.Random;
public class ChartFrame
extends JPanel {
private static final long serialVersionUID = 1L;
private static int numY = 10;
private static int numX = 4;
private static int height = 180;
private static int width = 200;
private static int x边距 = 50;
private static int y边距 = 10;
private static int labelHeight = 20;
private static int labelWidth = 40;
private String[] cardsCode;
public ChartFrame() throws Exception {
numX = CardList.getSize();
cardsCode = new String[numX];
for (int i = 0; i < numX; i++) {
cardsCode[i] = CardList.getCard(i).getId();
}
原点x = this.getX() + 50;
原点y = this.getY() + width - 10;
jbInit();
}
private static int 原点x;
private static int 原点y;
private int labelX;
private JLabel title = new JLabel("Cards Sold");
private Font font = new Font("Default", Font.PLAIN, 9);
public void paint(Graphics g) {
super.paint(g);
g.drawLine(getX() + x边距, getY() + y边距, 原点x, 原点y);
g.drawLine(原点x, 原点y, getX() + x边距 + width,
getY() + y边距 + height);
for (int i = 0; i < numX; i++) {
Random rand = new Random();
g.setColor(new Color(rand.nextInt()));
if (SaleList.contains(cardsCode[i])) {
g.fillRect(原点x + labelX * (1 + 3 * i), 原点y -
height * SaleList.getSaleQuantity(cardsCode[i]) / 100,
labelX * 2,
height * SaleList.getSaleQuantity(cardsCode[i]) / 100);
}
}
}
private void jbInit() throws Exception {
this.setLayout(null);
this.setVisible(true);
for (int i = 0; i <= numY; i++) {
Rectangle r = new Rectangle(x边距 - 22, (原点y - 10) - height / numY * i,
labelWidth, labelHeight);
JLabel num = createLabel(i * 10 + "", r);
this.add(num);
}
for (int i = 0; i < numX; i++) {
int n = 1;
if (numX != 0) {
n = numX * 3;
labelX = width/ n;
Rectangle r = new Rectangle(原点x + labelX * (1 + 3 * i), 原点y + 10,
labelX * 3, labelHeight);
JLabel num = createLabel(cardsCode[i], r);
num.setFont(font);
this.add(num);
}
else {
throw new Exception("没有贺卡");
}
}
title.setFont(new java.awt.Font("Default", Font.PLAIN, 9));
title.setBounds(new Rectangle(this.getX() + width / 2,
this.getY() + height + 50, 94, 22));
this.add(title);
}
/**
* createButton
* @param string String
* @param rectangle Rectangle
*/
private JLabel createLabel(String string, Rectangle rectangle) {
JLabel jb = new JLabel();
jb.setText(string);
jb.setBounds(rectangle);
return jb;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -