重新开贴来问这个问题:
我有一堆别人写的applet,主要完成了画图的功能(折线图等)。这些图会显示在调用applet的html页面中。
但是现在我希望尽可能有效的利用这些已有的类,画图,并把图像保存成文件。这个工作我希望在服务器端完成,并把绘制好的图像(例如.jpg文件)直接返回给用户。我之前发贴,别人告诉我说可以用JFrame,在JFrame中嵌入applet来使用applet.我使用一个简单的applet尝试了一下,是可以的。
但是由于现有的那些applet需要传入一些参数,并根据这些参数来绘图,我就不知道怎么样在给applet参数。我知道,在html中嵌入applet 时,是使用这样的语句来传参数的:
<PARAM NAME=xAxisStart VALUE= '0' >
<PARAM NAME=xAxisEnd VALUE= '100' >但是对于在JFrame中使用applet的情况,怎么传参数给applet呢?请指教!
另附简单的尝试程序如下:() Applet applet = new myApplet();
JFrame frame = new JFrame("Applet1c");
frame.getContentPane().add(applet);
frame.setSize(200,200);
applet.init();
applet.start();
frame.setVisible(true);
Rectangle bounds = applet.getBounds();
java.awt.image.BufferedImage image = new java.awt.image.BufferedImage(bounds.width, bounds.height, java.awt.image.BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
g.setColor(Color.white);
applet.paintComponents(g);
File fd = new File("d:\\a.jpg");
try{
FileOutputStream fos = new FileOutputStream(fd);
BufferedOutputStream bos = new BufferedOutputStream(fos);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bos);
encoder.encode(image);
bos.close();
}catch(Exception e)
{
e.printStackTrace();
}
我有一堆别人写的applet,主要完成了画图的功能(折线图等)。这些图会显示在调用applet的html页面中。
但是现在我希望尽可能有效的利用这些已有的类,画图,并把图像保存成文件。这个工作我希望在服务器端完成,并把绘制好的图像(例如.jpg文件)直接返回给用户。我之前发贴,别人告诉我说可以用JFrame,在JFrame中嵌入applet来使用applet.我使用一个简单的applet尝试了一下,是可以的。
但是由于现有的那些applet需要传入一些参数,并根据这些参数来绘图,我就不知道怎么样在给applet参数。我知道,在html中嵌入applet 时,是使用这样的语句来传参数的:
<PARAM NAME=xAxisStart VALUE= '0' >
<PARAM NAME=xAxisEnd VALUE= '100' >但是对于在JFrame中使用applet的情况,怎么传参数给applet呢?请指教!
另附简单的尝试程序如下:() Applet applet = new myApplet();
JFrame frame = new JFrame("Applet1c");
frame.getContentPane().add(applet);
frame.setSize(200,200);
applet.init();
applet.start();
frame.setVisible(true);
Rectangle bounds = applet.getBounds();
java.awt.image.BufferedImage image = new java.awt.image.BufferedImage(bounds.width, bounds.height, java.awt.image.BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
g.setColor(Color.white);
applet.paintComponents(g);
File fd = new File("d:\\a.jpg");
try{
FileOutputStream fos = new FileOutputStream(fd);
BufferedOutputStream bos = new BufferedOutputStream(fos);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bos);
encoder.encode(image);
bos.close();
}catch(Exception e)
{
e.printStackTrace();
}
楼主【cappuccino_zhou】截止到2008-07-30 16:55:16的历史汇总数据(不包括此帖):
发帖的总数量:13 发帖的总分数:230 每贴平均分数:17
回帖的总数量:8 得分贴总数量:0 回帖的得分率:0%
结贴的总数量:12 结贴的总分数:210
无满意结贴数:3 无满意结贴分:60
未结的帖子数:1 未结的总分数:20
结贴的百分比:92.31 % 结分的百分比:91.30 %
无满意结贴率:25.00 % 无满意结分率:28.57 %
值得尊敬
取消马甲机器人,请点这里:http://www.java2000.net/mycsdn/robotStop.jsp?usern=cappuccino_zhou