⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arc2d.jsp

📁 提供 精通Java Web动态图表编程 一书的源代码, 大家赶快下载呀
💻 JSP
字号:
<!--
	Fig. 7.5_08: Arc2D.jsp
	功能: Arc2D.Double 示例
-->
<%@ page language="java" contentType="image/png;charset=GB2312"
	import="java.awt.*"
	import="javax.imageio.*"
	import="java.awt.geom.*"
	import="java.awt.image.*"
%>

<%
// 清空缓冲区
response.reset();

// 注意这里的MIME类型
response.setContentType("image/png");

// 创建一个 500X375 的图像
int width = 500, height = 375;

BufferedImage image = new BufferedImage(width, height,
  BufferedImage.TYPE_INT_RGB);

Graphics2D g2d = image.createGraphics();

// 填充背景
g2d.setColor(Color.WHITE);
g2d.fillRect(0, 0, width, height);

Rectangle2D.Double rect = new Rectangle2D.Double();
Ellipse2D.Double ellipse = new Ellipse2D.Double();
Arc2D.Double arc2d = new Arc2D.Double();

double startAngle = 45.0, arcAngle = 270.0;
double rectWidth = 160.0, rectHeight = 120.0;
Point2D.Double p2d = new Point2D.Double(5.0, 20.0);
int arcType;

float[] dashes = { 4.f };
BasicStroke bs = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, 
	BasicStroke.JOIN_ROUND, 10, dashes, 0);
g2d.setStroke(bs);

for (int i = 0; i <= 2; i++)
{
	if (i == 0)
		arcType = Arc2D.PIE;
	else if (i == 1)
		arcType = Arc2D.CHORD;
	else
		arcType = Arc2D.OPEN;
	
	// 绘制圆弧外切矩形
	rect.setRect(i * (rectWidth + p2d.x), i* ( p2d.y + rectHeight/2), 
		rectWidth, rectHeight);
	g2d.setPaint(Color.GRAY);
	g2d.draw(rect);

	// 描绘圆弧所在的椭圆轮廓	
    ellipse = new Ellipse2D.Double(i * (rectWidth + p2d.x), 
		i* ( p2d.y + rectHeight/2), rectWidth, rectHeight);
	g2d.setPaint(Color.BLUE);
	g2d.draw(ellipse);
	
	// 填充圆弧
	g2d.setPaint(Color.YELLOW);
	arc2d.setArc( i * (rectWidth + p2d.x), i* ( p2d.y + rectHeight/2), 
		rectWidth, rectHeight, startAngle, arcAngle, arcType);
	g2d.fill(arc2d);
	
	// 描绘圆弧轮廓
	g2d.setStroke(new BasicStroke(2.0f));
	g2d.setPaint(Color.RED);
	g2d.draw(arc2d);

	// 重设笔划
	g2d.setStroke(bs);
}

// 部署图形
g2d.dispose();

// 利用ImageIO类的write方法对图像进行编码
ServletOutputStream sos = response.getOutputStream();
ImageIO.write(image, "PNG", sos);
sos.close();
%>

<%
/**************************************************************************
 * (C) Copyright 2004-2005 by Jingkui Zhong(钟京馗) and Huan Tang(唐桓).  *
 * All Rights Reserved.                                                   *
 *                                                                        *
 * DISCLAIMER: The authors of this code have used their                   *
 * best efforts in preparing the code. These efforts include the          *
 * development, research, and testing of the theories and programs        *
 * to determine their effectiveness. The authors and publisher make       *
 * no warranty of any kind, expressed or implied, with regard to these    *
 * programs or to the documentation contained in these codes. The authors *
 * shall not be liable in any event for incidental or consequential       *
 * damages in connection with, or arising out of, the furnishing,         *
 * performance, or use of these programs.                                 *
 **************************************************************************/
%>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -