家居吧台设计:java程序解释

来源:百度文库 编辑:高考问答 时间:2024/04/28 20:00:12
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.io.*;
import java.lang.*;
import java.net.URL;

public class Chart extends java.applet.Applet {
static final int VERTICAL = 0;
static final int HORIZONTAL = 1;

static final int SOLID = 0;
static final int STRIPED = 1;

int orientation;
String title;
Font titleFont;
FontMetrics titleFontMetrics;
int titleHeight = 15;
int columns;
int values[];
Object colors[];
Object labels[];
int styles[];
int scale = 10;
int maxLabelWidth = 0;
int barWidth;
int barSpacing = 10;
int max = 0;

public synchronized void init() {
String rs;

titleFont = new java.awt.Font("Courier", Font.BOLD, 12);
titleFontMetrics = getFontMetrics(titleFont);
title = getParameter("title");

if (title == null) {
title = "Chart";
}
rs = getParameter("columns");
if (rs == null) {
columns = 5;
} else {
columns = Integer.parseInt(rs);
}
rs = getParameter("scale");
if (rs == null) {
scale = 10;
} else {
scale = Integer.parseInt(rs);
}

rs = getParameter("orientation");
if (rs == null) {
orientation = VERTICAL;
} else if (rs.toLowerCase().equals("vertical")) {
orientation = VERTICAL;
} else if (rs.toLowerCase().equals("horizontal")) {
orientation = HORIZONTAL;
} else {
orientation = VERTICAL;
}
values = new int[columns];
colors = new Color[columns];
labels = new String[columns];
styles = new int[columns];
for (int i=0; i < columns; i++) {
// parse the value for this column
rs = getParameter("C" + (i+1));
if (rs != null) {
try {
values[i] = Integer.parseInt(rs);
} catch (NumberFormatException e) {
values[i] = 0;
}
}
if (values[i] > max) {
max = values[i];
}

// parse the label for this column
rs = getParameter("C" + (i+1) + "_label");
labels[i] = (rs == null) ? "" : rs;
maxLabelWidth = Math.max(titleFontMetrics.stringWidth((String)(labels[i])),
maxLabelWidth);
// parse the bar style
rs = getParameter("C" + (i+1) + "_style");
if (rs == null || rs.toLowerCase().equals("solid")) {
styles[i] = SOLID;
} else if (rs.toLowerCase().equals("striped")) {
styles[i] = STRIPED;
} else {
styles[i] = SOLID;
}
// parse the color attribute for this column
rs = getParameter("C" + (i+1) + "_color");

其实,你更应该去专业网站的bbs,比如水木,那里高手很多。