?? circlegraph.java
字號:
package Course;
import javax.swing.JPanel;
import java.awt.Graphics;
import java.awt.Dimension;
import java.awt.Color;
import java.math.*;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class CircleGraph extends JPanel{
double[] Score={1,61,70,80,90};
public CircleGraph() {
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public CircleGraph(double[] Score) {
this.Score=Score;
}
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
int[] a={0,0,0,0,0};
for(int i=0;i<Score.length;i++)
{
if(Score[i]<60)a[0]++;
else if((Score[i]>=60)&&(Score[i]<70))a[1]++;
else if((Score[i]>=70)&&(Score[i]<80))a[2]++;
else if((Score[i]>=80)&&(Score[i]<90))a[3]++;
else a[4]++;
}
double[] k=new double[5];
k[0]=(double)a[0]/(Score.length);
k[1]=(double)a[1]/(Score.length);
k[2]=(double)a[2]/(Score.length);
k[3]=(double)a[3]/(Score.length);
k[4]=(double)a[4]/(Score.length);
g.setColor(Color.blue);
g.fillArc(10,30,getHeight()*3/4,getHeight()*3/4,0,(int)(360*k[0]));
g.fillRect(260,110,20,20);
g.setColor(Color.pink);
g.fillArc(10,30,getHeight()*3/4,getHeight()*3/4,(int)(360*k[0]),(int)(360*k[1]));
g.fillRect(260,135,20,20);
g.setColor(Color.gray);
g.fillArc(10,30,getHeight()*3/4,getHeight()*3/4,(int)(360*k[0])+(int)(360*k[1]),(int)(360*k[2]));
g.fillRect(260,160,20,20);
g.setColor(Color.magenta);
g.fillArc(10,30,getHeight()*3/4,getHeight()*3/4,(int)(360*k[0])+(int)(360*k[1])+(int)(360*k[2]),0+(int)(360*k[3]));
g.fillRect(260,185,20,20);
g.setColor(Color.DARK_GRAY);
g.fillArc(10,30,getHeight()*3/4,getHeight()*3/4,(int)(360*k[0])+(int)(360*k[1])+(int)(360*k[2])+0+(int)(360*k[3]),0+(int)(360*k[4]));
g.fillRect(260,210,20,20);
g.setColor(Color.BLACK);
g.drawRect(258,105,170,130);
g.drawString(":x < 60",280,125);
g.drawString(":60 >=x< 70",280,150);
g.drawString(":70 >=x< 80",280,175);
g.drawString(":80 >=x< 90",280,200);
g.drawString(":90 >=x< 100",280,225);
g.drawString(a[0]+"人 "+(double)((int)(k[0]*10000))/100+"%",360,125);
g.drawString(a[1]+"人 "+(double)((int)(k[1]*10000))/100+"%",360,150);
g.drawString(a[2]+"人 "+(double)((int)(k[2]*10000))/100+"%",360,175);
g.drawString(a[3]+"人 "+(double)((int)(k[3]*10000))/100+"%",360,200);
g.drawString(a[4]+"人 "+(double)((int)(k[4]*10000))/100+"%",360,225);
}
public Dimension getPreferredSize()
{
return new Dimension(400,400);
}
private void jbInit() throws Exception {
this.setLayout(null);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -