JSP中生成图形 例子
来源:互联网 发布:免费手机导航软件排名 编辑:程序博客网 时间:2024/05/14 08:16
在JSP中生成柱形图形的例子:
1。图形生成处理类<ChartGraphics>:
package graphics;
import java.awt.image.BufferedImage;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import com.sun.image.codec.jpeg.ImageFormatException;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
import com.sun.image.codec.jpeg.JPEGCodec;
import java.awt.Graphics;
import java.awt.Color;
public class ChartGraphics {
BufferedImage image;
public void createImage(String fileLocation)
{
try {
FileOutputStream fos = new FileOutputStream(fileLocation);
BufferedOutputStream bos = new BufferedOutputStream(fos);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bos);
try {
encoder.encode(image);
bos.close();
} catch (ImageFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void graphicGenernal(int h1,int h2,int h3,int h4,int h5)
{
int x = 10;
int imageHight = 300;
int imageWidth = 300;
int columnHight = 200;
int columnWidth = 30;
ChartGraphics graphics = new ChartGraphics();
graphics.image = new BufferedImage(imageWidth,imageHight,BufferedImage.TYPE_INT_RGB);
Graphics graphic = graphics.image.getGraphics();
graphic.setColor(Color.BLUE);
graphic.fillRect(0, 0, imageWidth, imageHight);
graphic.setColor(Color.RED);
graphic.drawRect(1*x+1*columnWidth, columnHight-h1, columnWidth, h1);
graphic.drawRect(2*x+2*columnWidth, columnHight-h2, columnWidth, h2);
graphic.drawRect(3*x+3*columnWidth columnHight-h3, columnWidth, h3);
graphic.drawRect(4*x+4*columnWidth, columnHight-h4, columnWidth, h4);
graphic.drawRect(5*x+5*columnWidth, columnHight-h5, columnWidth, h5);
graphics.createImage("c://2.jpg");
}
}
2。显示数据获取<GetData.java>:
package graphics;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
public class GetData {
int hight[] = new int[5];
public int[] getArrayList()
{
try {
RandomAccessFile rf = new RandomAccessFile("c://1.txt","r");
for(int i=0;i<5;i++)
{
try {
hight[i] = Integer.parseInt(rf.readLine());
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return hight;
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}
3。显示图形JSP页面<index.jsp>:
<%@ page language="java" import="java.util.*" pageEncoding="Shift_JIS"%>
<%@ page import="graphics.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<jsp:useBean id="chartGraphics" class="graphics.ChartGraphics"/>
<jsp:useBean id="getData" class="graphics.GetData"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index2.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
int d[] = new int[5];
d = getData.getArrayList();
chartGraphics.graphicGenernal(d[0],d[1],d[2],d[3],d[4]);
%>
<img src="c://2.jpg"></img>
</body>
</html>
4。数据文件<c://1.txt>:
12
56
89
23
90
56
78
- JSP中生成图形 例子
- Android中特殊图形的生成例子
- JSP 利用 JFreechart直接生成报表图形的例子
- jsp中生成图形验证码
- JFreeChart 生成图形 例子
- 在JSP中生成验证码图片的例子
- 在JSP中生成验证码图片的例子
- jsp中生成图形验证码 方法2利用在servlet里面来生成验证码
- 无错版JSP生成图形验证码
- jsp中生成随机数
- JSP动态生成XML、json例子
- 在ASP.NET中动态生成图形
- java 中生成图形验证码
- java 中生成图形验证码
- java 中生成图形验证码
- 在ASP.NET中动态生成图形
- JSP中生成验证码
- JSP中动态生成表格
- 优化Linux 系统服务来提高引导速度
- 深入理解Linux守护进程
- 限制键盘输入
- 教你怎么破解linux的root密码(图教)
- 病毒传播惊现新模式 黑客借力打力病毒威力激增
- JSP中生成图形 例子
- RPM 大全 (转)
- Linux系统管理命令---Linux 入门常用命令 (9)
- 数据库分页语句
- 修改Grub让多系统和平共处!
- 项目完成了,经理对我的总结还回复了
- 给甜心丫丫的代码!
- 国内软件外包竞争分析
- Linux备份与压缩命令---Linux 入门常用命令 (5)