永发信息网

请使用-Xlint:unchecked 重新编译? JAVA

答案:1  悬赏:0  手机版
解决时间 2021-05-01 06:18

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();
c.addSlice(value, (Color)colors.get(s.substring(i + 1)));
}

resize(c.getMinimumSize().width, c.getMinimumSize().height);
add("Center", c);
}
}

class PieChartCanvas extends Canvas {

final double aspectFudge = 2.5;
int radius, depth, called = 1, numSlices = 0;
float total = 0, value[] = new float[10];
Color color[] = new Color[10];
Graphics offGraphics;
Image gfxBuff;

public PieChartCanvas(int radius, int depth) {
this.value = value;
this.color = color;
this.radius = radius;
this.depth = depth;
}

public void paint(Graphics g) {
int startAngle;
float angle;
Dimension d = getSize();

if(gfxBuff == null) {
gfxBuff = createImage(d.width, d.height);
offGraphics = gfxBuff.getGraphics();
offGraphics.setColor(getBackground());
offGraphics.fillRect(0, 0, d.width, d.height);
}

// do the 3d effect
for(int x = depth; x >= 1; x--) {
startAngle = -45;
for(int i = 0; i < numSlices; i++) {
offGraphics.setColor(color[i].darker());
angle = Math.round(360 * (value[i] / total));
offGraphics.fillArc(0, x, radius, (int)(radius / aspectFudge),
startAngle, (int)angle);
startAngle += angle;
}
}

// draw the pie slice
startAngle = -45;
for(int i = 0; i < numSlices; i++) {
offGraphics.setColor(color[i]);
angle = Math.round(360 * (value[i] / total));
offGraphics.fillArc(0, 0, radius, (int)(radius / aspectFudge),
startAngle, (int)angle);
startAngle += angle;
}
g.drawImage(gfxBuff, 0, 0, null);
}

public void addSlice(float value, Color color) {
this.value[numSlices] = value;
this.color[numSlices++] = color;
total += value;
}

public Dimension getPreferredSize() {
return getMinimumSize();
}

public Dimension getMinimumSize() {
return new Dimension(radius, (int)((radius / aspectFudge) + depth));
}
}

编译后出现下面语句:

--------------------配置: <默认>--------------------
注意:C:\Graph.java 使用了未经检查或不安全的操作。
注意:要了解详细信息,请使用 -Xlint:unchecked 重新编译。

处理已完成。

最佳答案

只是有警告而已


我替你修改好了,自己看看不同


import java.util.*;
import java.awt.*;
import java.applet.Applet;


public class Graph extends Applet {


private static final long serialVersionUID = 1L;
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<String, Color> colors = new Hashtable<String, Color>();
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();
c.addSlice(value, (Color)colors.get(s.substring(i + 1)));
}


resize(c.getMinimumSize().width, c.getMinimumSize().height);
add("Center", c);
}
}


class PieChartCanvas extends Canvas {

private static final long serialVersionUID = 1L;

final double aspectFudge = 2.5;
int radius, depth, called = 1, numSlices = 0;
float total = 0, value[] = new float[10];
Color color[] = new Color[10];
Graphics offGraphics;
Image gfxBuff;


public PieChartCanvas(int radius, int depth) {
this.radius = radius;
this.depth = depth;
}


public void paint(Graphics g) {
int startAngle;
float angle;
Dimension d = getSize();


if(gfxBuff == null) {
gfxBuff = createImage(d.width, d.height);
offGraphics = gfxBuff.getGraphics();
offGraphics.setColor(getBackground());
offGraphics.fillRect(0, 0, d.width, d.height);
}


// do the 3d effect
for(int x = depth; x >= 1; x--) {
startAngle = -45;
for(int i = 0; i < numSlices; i++) {
offGraphics.setColor(color[i].darker());
angle = Math.round(360 * (value[i] / total));
offGraphics.fillArc(0, x, radius, (int)(radius / aspectFudge),
startAngle, (int)angle);
startAngle += angle;
}
}


// draw the pie slice
startAngle = -45;
for(int i = 0; i < numSlices; i++) {
offGraphics.setColor(color[i]);
angle = Math.round(360 * (value[i] / total));
offGraphics.fillArc(0, 0, radius, (int)(radius / aspectFudge),
startAngle, (int)angle);
startAngle += angle;
}
g.drawImage(gfxBuff, 0, 0, null);
}


public void addSlice(float value, Color color) {
this.value[numSlices] = value;
this.color[numSlices++] = color;
total += value;
}


public Dimension getPreferredSize() {
return getMinimumSize();
}


public Dimension getMinimumSize() {
return new Dimension(radius, (int)((radius / aspectFudge) + depth));
}
}


我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
四川内江是个什么地方啊
泗阳海天塑业有限公司我想知道这个在什么地方
石家庄和平西路80号中兴商务楼怎么走?
班主任考核评语怎么写,怎样评估教师教学信息
小天鹅洗衣机七公斤家电下乡那款的型号是什么
卖车不过户写手续行吗?
41级召唤师 不知道用什么武器好 请大家帮帮手
假如现在让你捡到10块钱你会怎么做?
电脑进入正在启动windows后就没有反应了,怎
过腰长发丸子头
处对象就得要东西吗?
笔记本cpuT2330 pm965芯片组 升级内存问题
农历1987年7月初九亥时出生的星座 幸运数字和
http://v.youku.com/v_show/id_XMTI2MDYxMzAw
为什么我用手机开通QQ会员却被冻结,然后会员
推荐资讯
AEATC原生态农业在哪里啊,我有事要去这个地
自制去角质???
福源酒家地址在什么地方,想过去办事
电话线接路由器可以无限上网吗
6个月的狗突然吐然后就不吃饭是怎么回事啊
谁能帮我解道数学题
我想买部六合千元左右的,首先是能学习打字拼
伤口有化脓现象能涂茶油吗
红花被折后会是个什么..?
大坪掌地址在哪,我要去那里办事
scsi命令失败
superjunior四周年常州有应援会吗?
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?