?? chart.src
字號:
} else if (rs.equals("gray")) {
colors[i] = Color.gray;
} else if (rs.equals("darkGray")) {
colors[i] = Color.darkGray;
} else {
colors[i] = Color.gray;
}
} else {
colors[i] = Color.gray;
}
}
switch (orientation) {
case VERTICAL:
default:
barWidth = maxLabelWidth;
resize(Math.max(columns * (barWidth + barSpacing),
titleFontMetrics.stringWidth(title)) +
titleFont.getSize() + 5,
(max * scale) + (2 * titleFont.getSize()) + 5 + titleFont.getSize());
break;
case HORIZONTAL:
barWidth = titleFont.getSize();
resize(Math.max((max * scale) + titleFontMetrics.stringWidth("" + max),
titleFontMetrics.stringWidth(title)) + maxLabelWidth + 5,
(columns * (barWidth + barSpacing)) + titleFont.getSize() + 10);
break;
}
}
public synchronized void paint(Graphics g) {
int i, j;
int cx, cy;
char l[] = new char[1];
// draw the title centered at the bottom of the bar graph
g.setColor(Color.black);
i = titleFontMetrics.stringWidth(title);
g.setFont(titleFont);
g.drawString(title, Math.max((size().width - i)/2, 0),
size().height - titleFontMetrics.getDescent());
for (i=0; i < columns; i++) {
switch (orientation) {
case VERTICAL:
default:
// set the next X coordinate to account for the label
// being wider than the bar size().width.
cx = (Math.max((barWidth + barSpacing),maxLabelWidth) * i) +
barSpacing;
// center the bar chart
cx += Math.max((size().width - (columns *
(barWidth + (2 * barSpacing))))/2,0);
// set the next Y coordinate to account for the size().height
// of the bar as well as the title and labels painted
// at the bottom of the chart.
cy = size().height - (values[i] * scale) - 1 - (2 * titleFont.getSize());
// draw the label
g.setColor(Color.black);
g.drawString((String)labels[i], cx,
size().height - titleFont.getSize() - titleFontMetrics.getDescent());
// draw the shadow bar
if (colors[i] == Color.black) {
g.setColor(Color.gray);
}
g.fillRect(cx + 5, cy - 3, barWidth, (values[i] * scale));
// draw the bar with the specified color
g.setColor((Color)(colors[i]));
switch (styles[i]) {
case SOLID:
default:
g.fillRect(cx, cy, barWidth, (values[i] * scale));
break;
case STRIPED:
{
int steps = (values[i] * scale) / 2;
int ys;
for (j=0; j < steps; j++) {
ys = cy + (2 * j);
g.drawLine(cx, ys, cx + barWidth, ys);
}
}
break;
}
g.drawString("" + values[i],
cx,
cy - titleFontMetrics.getDescent());
break;
case HORIZONTAL:
// set the Y coordinate
cy = ((barWidth + barSpacing) * i) + barSpacing;
// set the X coordinate to be the size().width of the widest
// label
cx = maxLabelWidth + 1;
cx += Math.max((size().width - (maxLabelWidth + 1 +
titleFontMetrics.stringWidth("" +
max) +
(max * scale))) / 2, 0);
// draw the labels and the shadow
g.setColor(Color.black);
g.drawString((String)labels[i], cx - maxLabelWidth - 1,
cy + titleFontMetrics.getAscent());
if (colors[i] == Color.black) {
g.setColor(Color.gray);
}
g.fillRect(cx + 3,
cy + 5,
(values[i] * scale),
barWidth);
// draw the bar in the current color
g.setColor((Color)(colors[i]));
switch (styles[i]) {
case SOLID:
default:
g.fillRect(cx,
cy,
(values[i] * scale),
barWidth);
break;
case STRIPED:
{
int steps = (values[i] * scale) / 2;
int ys;
for (j=0; j < steps; j++) {
ys = cx + (2 * j);
g.drawLine(ys, cy, ys, cy + barWidth);
}
}
break;
}
g.drawString("" + values[i],
cx + (values[i] * scale) + 3,
cy + titleFontMetrics.getAscent());
break;
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -