开发工具:
文件大小: 1mb
下载次数: 0
上传时间: 2009-06-27
详细说明: 其中一个小程序; package org.zhq426; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JDialog; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.geom.*; pu blic class DrawState extends JDialog { int result[] = { }; private String[] title = { "优秀", "良好", "中等", "及格", "不及格" }; private Color[] color = { Color.blue, new Color(255, 92, 0), new Color(255, 0, 30), new Color(0, 255, 30), new Color(255, 0, 240), Color.cyan }; public static void main(String args[]) { try { DrawState dialog = new DrawState(); dialog.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); dialog.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } public DrawState() { super(); setBounds(100, 100, 500, 375); // } public DrawState(int result[]){ super(); this.result=result; setBounds(100, 100, 500, 375); } private int statStyle = 1; public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Dimension dim = this.getSize(); g2.setColor(Color.white); g2.fillRect(0, 0, dim.width, dim.height); int total = result[result.length - 1]; int begTangle = 0; int endTangle = 0; g2.setColor(Color.black); int pointx = dim.width / 2;// 圆心x int pointy = dim.height / 2;// 圆心y int r = 150;// 半径 long[] pointsx = new long[result.length - 1]; long[] pointsy = new long[result.length - 1]; pointsx[0] = pointx + r; pointsy[0] = pointy; for (int i = 1; i < result.length - 1; i++) { if (i >= 6) { g2.setColor(color[i % 6]); } else { g2.setColor(color[i]); } if (result[i] > 0) { int percent = Math.round((result[i] * 100f) / total); // round()返回最接近参数的int值 endTangle = Math.round(percent * 360f / 100f); title[i] = title[i] + "(" + percent + "%)"; g2.fillArc(pointx - r, pointy - r, 2 * r, 2 * r, begTangle, endTangle); // 新中心点 pointsx[i] = Math.round(Math.cos(Math.toRadians (begTangle + endTangle * 0.5)) * r + pointx); pointsy[i] = Math.round(pointy - Math.sin(Math.toRadians (begTangle + endTangle * 0.5)) * r); // 延长点 long pointsxEx = Math.round(Math.cos(Math.toRadians (begTangle + endTangle * 0.5)) * (r + 50) + pointx); long pointsyEx = Math.round(pointy - Math.sin(Math.toRadians (begTangle + endTangle * 0.5)) * (r + 50)); g2.setColor(Color.black); g2.draw(new Line2D.Double(pointsx[i], pointsy[i], pointsxEx, pointsyEx)); // 画文本框 g2.setColor(new Color(251, 249, 206)); if (((int) pointsxEx) < pointx) { g2.fillRect((int) pointsxEx - 110, (int) pointsyEx - 10, 110, 20); g2.setColor(Color.black); g2.drawString(title[i], (int) pointsxEx - 110, (int) pointsyEx + 5); } else { g2.fillRect((int) pointsxEx, (int) pointsyEx - 10, 110, 20); g2.setColor(Color.black); g2.drawString(title[i], (int) pointsxEx, (int) pointsyEx + 5); } begTangle = begTangle + endTangle; } } } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.