是什么原因呢(内存??)

changzz 2004-07-01 08:47:19
大家看看这段程序

import java.applet.Applet;

import java.awt.Graphics;

import javax.print.*;

import javax.print.attribute.*;

import javax.print.attribute.standard.*;

import java.io.*;



public class PrintFileTest extends Applet {

private String TMP_FILE="C:\\pics\\map20.jpg";



public void init() {



}



public void start() {

printMap();

}



public void stop() {



}



public void destroy() {



}



public void paint(Graphics g) {

//Draw a Rectangle around the applet's display area.

// g.drawRect(0, 0, size().width - 1, size().height - 1);



//Draw the current string inside the rectangle.

// g.drawString(buffer.toString(), 5, 15);

}



public void printMap(){

String filename = TMP_FILE;

PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();



DocFlavor flavor = DocFlavor.INPUT_STREAM.JPEG;



PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras);

PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();

PrintService service = ServiceUI.printDialog(null, 200, 200,printService, defaultService, flavor, pras);

if (service != null) {

try

{



DocPrintJob job = service.createPrintJob();

FileInputStream fis = new FileInputStream(filename);

DocAttributeSet das = new HashDocAttributeSet();



Doc doc = new SimpleDoc(fis, flavor, das);

// PageFormat format = job.pageDialog(attributes);

job.print(doc, pras);

}

catch(Exception e)

{

e.printStackTrace();

}

}

}

}

这个段程序为什么当图片很大的时侯就出现内存溢出(outofmemoryerror)???appletviewer -Xmx512m -Xms512m PrintFileTest 这样就可以解决!
请问还有没有其他的方法!因为这是在IE上运行的程序,不应该在DOS下面运行!
用代码在程序里面入如何实现???我需要看哪方面的资料呢!!请大家多多指点:)
小弟在这里先谢谢了。。。。
...全文
111 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
changzz 2004-07-02
  • 打赏
  • 举报
回复
up真的没有高手
changzz 2004-07-01
  • 打赏
  • 举报
回复
我把printMap()解释一下

public void printMap() {
//String filename = TMP_FILE;
//获取HTML中的APPLET中的param
String filename = getParameter("Filepath"); //获取HTML文件中的URL路径
//////
String str;
//构建打印请求属性集
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
//设置打印格式,
DocFlavor flavor = DocFlavor.INPUT_STREAM.JPEG;
//查找所有的可用打印服务
PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor,
pras);
//定位默认的打印服务
PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
//显示打印对话框
PrintService service = ServiceUI.printDialog(null, 200, 200, printService,
defaultService, flavor, pras);
if (service != null) {
try {

DocPrintJob job = service.createPrintJob();//创建打印作业
FileInputStream fis = new FileInputStream(filename);//构造待打印的文件流
DocAttributeSet das = new HashDocAttributeSet();

Doc doc = new SimpleDoc(fis, flavor, das);//建立打印文件格式
// PageFormat format = job.pageDialog(attributes);
job.print(doc, pras);//进行文件的打印
}
catch (Exception e) {
e.printStackTrace();
}

}
}

//
public void paint(Graphics g) {
//Draw a Rectangle around the applet's display area.
g.drawRect(0, 0, size().width - 1, size().height - 1);

//Draw the current string inside the rectangle.
//g.drawString("buffer.toString()", 5, 15);

}

}
jackal81 2004-07-01
  • 打赏
  • 举报
回复
up
smallcosmos 2004-07-01
  • 打赏
  • 举报
回复
来加入了
yf2004 2004-07-01
  • 打赏
  • 举报
回复
为了我们的JAVA能不断提高 ,让我们一起努力到"JAVA田地"中.
那里有很多高手乐意帮忙.也有刚出道的少年. QQ群 号码:4025186
ecaol 2004-07-01
  • 打赏
  • 举报
回复
UP
ShaNiu 2004-07-01
  • 打赏
  • 举报
回复
自己再顶

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧