当前位置: 技术问答>java相关
如何在APPLET里做个饼形图,或是坐标图?
来源: 互联网 发布时间:2017-03-27
本文导语: 如何在APPLET里做个饼形图,或是坐标图 能举个例子吗,非常感到感谢 | import java.util.*; import java.awt.*; import java.applet.Applet; public class PieChart extends Applet { int Width, Height; String...
如何在APPLET里做个饼形图,或是坐标图 能举个例子吗,非常感到感谢
|
import java.util.*;
import java.awt.*;
import java.applet.Applet;
public class PieChart extends Applet {
int Width, Height;
String title;
Hashtable colors;
public void init() {
double value;
/* Get parameters */
String at = getParameter("width");
Width = (at != null) ? Integer.valueOf(at).intValue() : 100;
at = getParameter("height");
Height = (at != null) ? Integer.valueOf(at).intValue() : 100;
if ( Height 0 ) {
c.addSlice(value, col );
legend.addSlice( col, ""+j );
}
j++;
}
add("North", new Label( title, Label.CENTER ) );
add("South", legend );
add("Center", c);
}
public void setColors() {
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);
}
public Color getColor( String colorstr ) {
return (Color)colors.get( colorstr );
}
}
class PieLegend extends Canvas {
int Width, Height, numSlices=0;
int MaxSlices = 20;
Color colors[] = new Color[20];
String labels[] = new String[20];
Font font;
FontMetrics fm;
public PieLegend(int width, int height) {
font = new Font("Courier", Font.PLAIN, 12 );
fm = getFontMetrics(font);
Width = width;
Height = height;
resize( Width, Height );
}
public void addSlice( Color color, String text ) {
colors[numSlices] = color;
labels[numSlices] = text;
numSlices++;
}
public void paint(Graphics g) {
int blocksize, strwid, strht, left, i;
blocksize = Width/numSlices;
strht = fm.getAscent()+1;
for (i=0, left=0; i
import java.awt.*;
import java.applet.Applet;
public class PieChart extends Applet {
int Width, Height;
String title;
Hashtable colors;
public void init() {
double value;
/* Get parameters */
String at = getParameter("width");
Width = (at != null) ? Integer.valueOf(at).intValue() : 100;
at = getParameter("height");
Height = (at != null) ? Integer.valueOf(at).intValue() : 100;
if ( Height 0 ) {
c.addSlice(value, col );
legend.addSlice( col, ""+j );
}
j++;
}
add("North", new Label( title, Label.CENTER ) );
add("South", legend );
add("Center", c);
}
public void setColors() {
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);
}
public Color getColor( String colorstr ) {
return (Color)colors.get( colorstr );
}
}
class PieLegend extends Canvas {
int Width, Height, numSlices=0;
int MaxSlices = 20;
Color colors[] = new Color[20];
String labels[] = new String[20];
Font font;
FontMetrics fm;
public PieLegend(int width, int height) {
font = new Font("Courier", Font.PLAIN, 12 );
fm = getFontMetrics(font);
Width = width;
Height = height;
resize( Width, Height );
}
public void addSlice( Color color, String text ) {
colors[numSlices] = color;
labels[numSlices] = text;
numSlices++;
}
public void paint(Graphics g) {
int blocksize, strwid, strht, left, i;
blocksize = Width/numSlices;
strht = fm.getAscent()+1;
for (i=0, left=0; i
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
站内导航:
特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!