Java 编程基础实验四 JavaApplet:绘制饼形图 实验四JavaApplet:绘制饼形图
import java.awt.*;
import java.awt.Graphics;
import java.sql.*;
import java.applet.Applet;
public class TestPic extends Applet
{
//设置成员变量,将读取的员工类别和员工数量放到数组中
String empType[]=new String[12];;
int num[]=new int[12];
public void init()
{ //初始化数组 }
public void paint(Graphics g)
{
CarryOutPic(g); } //画图
public void CarryOutPic(Graphics myG)
{ //绘画图形中指定的位置,以指定的字体,表示为图标
Font f=new Font("宋体",Font.PLAIN,15);
myG.setFont(f);
myG.drawString("XX公司XX产品2007年销售情况一览表",5,20);
Point myRec = new Point(515, 30);
Point myDec = new Point(540, 40);
Point myTxt = new Point(580, 40);
Font f1=new Font("宋体",Font.PLAIN,9);
myG.drawString("单位:万件",525, 22);
for (int i = 0; i <empType.length; i++)
{ myG.setColor( GetColor(i));
myG.fillRect(myRec.x, myRec.y, 20, 10);
myG.setColor(Color.black);
myG.drawRect(myRec.x, myRec.y, 20, 10);
myG.drawString(empType[i],myDec.x,myDec.y);
//绘制小方块右边的文字
spring framework表达式assignmyG.String(num[i]),myTxt.x,myTxt.y);
myRec.y += 15;
myDec.y += 15;
myTxt.y += 15; }
//从数组中取得数据得到数据值大小,绘制扇形
int Total = 0;
int CurrentAngle = 0;
int StartAngle = 0;
for (int i = 0; i < num.length; i++)
{
Total += num[i]; }
for (int i = 0; i < num.length; i++) {
/
/绘制扇形角度
if (i == num.length - 1) {
CurrentAngle = 360 - StartAngle;
} else {
int Temp = num[i];
CurrentAngle = (Temp * 360) / Total; }
myG.drawArc(100, 40, 250, 250, StartAngle, CurrentAngle);
//用指定的颜填充扇形
myG.setColor( GetColor(i));
myG.fillArc( 100, 40, 250, 250, StartAngle, CurrentAngle);
StartAngle += CurrentAngle; }
myG.setColor(Color.black);
myG.drawRect(1,1,598,298);
} //设置颜
public Color GetColor(int i)
{ Color myColor;
switch (i) {
case 0:
myColor = Color.black;
return myColor;
case 1:
myColor = d;
return myColor;
case 2:
myColor = llow;
return myColor;
………….//设置12
default:
myColor = ;
return myColor; } } }
html>
<head>
</head>
<body bgcolor="000000">
<center>
<applet
code = "TestPic.class"
width = "600"
height = "300"
>
</applet>
</center>
</body>
</html>
文件复制
import java.io.*;
class Fuzhi
{
public static void main(String args[])
{
int count;
byte b[]=new byte[1024];
FileInputStream fis;
FileOutputStream fos;
try{fis=new FileInputStream("D:\\java\\a.txt");
}catch(FileNotFoundException e){
System.out.println("文件没有被到!");
return;}
try{fos=new FileOutputStream("D:\\java\\b.doc");
}catch(FileNotFoundException e){
System.out.println("
文件没有被写入!");
return;
}catch(ArrayIndexOutOfBoundsException e){
System.out.println();
return;}
try{while((ad(b,0,1024))!=-1){
fos.write(b,0,count);}
}catch(IOException e){
System.out.println("Error:"+e);
return;}
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。