最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- Draw a pie chart
时间:2022-07-02 17:24:23 编辑:袖梨 来源:一聚教程网
import java.util.*;
import java.awt.*;
import java.applet.Applet;
public class Graph extends Applet {
int depth, radius;
public void init() {
float value;
String at = getParameter("width");
radius = (at != null) ? Integer.valueOf(at).intValue() : 100;
at = getParameter("depth");
depth = (at != null) ? Integer.valueOf(at).intValue() : 20;
at = getParameter("values");
PieChartCanvas c = new PieChartCanvas(radius, depth);
setLayout(new BorderLayout());
// Create Hashtable to map color name (String) to Color type
Hashtable colors = new Hashtable();
colors.put("green", Color.green);
colors.put("red", Color.red);
colors.put("blue", Color.blue);
colors.put("yellow", Color.yellow);
colors.put("magenta", Color.magenta);
colors.put("cyan", Color.cyan);
colors.put("orange", Color.orange);
colors.put("pink", Color.pink);
colors.put("white", Color.white);
colors.put("black", Color.black);
// "value-color,value-color,..."
StringTokenizer t = new StringTokenizer(at, ",");
String s;
int i;
while (t.hasMoreTokens()) {
s = t.nextToken();
i = s.indexOf('-');
value = Float.valueOf(s.substring(0, i)).floatValue();
import java.awt.*;
import java.applet.Applet;
public class Graph extends Applet {
int depth, radius;
public void init() {
float value;
String at = getParameter("width");
radius = (at != null) ? Integer.valueOf(at).intValue() : 100;
at = getParameter("depth");
depth = (at != null) ? Integer.valueOf(at).intValue() : 20;
at = getParameter("values");
PieChartCanvas c = new PieChartCanvas(radius, depth);
setLayout(new BorderLayout());
// Create Hashtable to map color name (String) to Color type
Hashtable colors = new Hashtable();
colors.put("green", Color.green);
colors.put("red", Color.red);
colors.put("blue", Color.blue);
colors.put("yellow", Color.yellow);
colors.put("magenta", Color.magenta);
colors.put("cyan", Color.cyan);
colors.put("orange", Color.orange);
colors.put("pink", Color.pink);
colors.put("white", Color.white);
colors.put("black", Color.black);
// "value-color,value-color,..."
StringTokenizer t = new StringTokenizer(at, ",");
String s;
int i;
while (t.hasMoreTokens()) {
s = t.nextToken();
i = s.indexOf('-');
value = Float.valueOf(s.substring(0, i)).floatValue();
相关文章
- 《潜行者2:切尔诺贝利之心》借刀杀人成就攻略分享 11-21
- 《潜行者2:切尔诺贝利之心》游戏保存方法介绍 11-21
- 《潜行者2:切尔诺贝利之心》游戏支线任务作用介绍 11-21
- 《潜行者2:切尔诺贝利之心》异常现象特点介绍 11-21
- 《潜行者2:切尔诺贝利之心》随机事件避免原因介绍 11-21
- 《潜行者2:切尔诺贝利之心》随机事件应对方法推荐 11-21