Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java GUI 设计  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Applet 显示多幅图片,内存溢出错误!!
rizard



发贴: 0
积分: 0
于 2003-11-03 20:41 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
这是一个显示多幅(10幅以上)图片的Applet。为何在程序中,有的图片有时显示不了,还出现内存溢出错误(outOfmemory)呢?
望高手能答复!!!!!(急需)
package proj_mediatracker;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.awt.image.*;

public class MyApplet
extends Applet
implements Runnable {
private boolean isStandalone = false;
int imgWidth = 100;
int imgHeight = 75;
Image[] imgs;
Image pic;
int picID;
MediaTracker tracker;
Thread loadingThread;
//Get a parameter value
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}

//Construct the applet
public MyApplet() {
}

//Initialize the applet
public void init() {
imgs = new Image[16];
tracker = new MediaTracker(this);
for (int i = 0; i < imgs.length; i++) {
imgs[i] = this.getImage(getCodeBase(),"./imgs/" + i + ".jpg");
tracker.addImage(imgs[i], i);
}
loadingThread = new Thread(this);
loadingThread.start();
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}

public void run() {
try {
tracker.waitForAll();
}
catch (InterruptedException e) {
System.out.println("InterruptedException occurred");
return;
}
repaint();
}

public void paint(Graphics g) {
Graphics2D g2D=(Graphics2D) g;//强制转换
BufferedImage bimage = (BufferedImage)this.createImage(this.getWidth(),this.getHeight());
for(int i = 0; i < imgs.length*4; i++)
{
bimage.createGraphics().drawImage(this.imgs[i % 16],i * imgWidth % 800,i * imgWidth / 800 % 600 * imgHeight,imgWidth,imgHeight,this);
g2D.drawImage(bimage,0,0,this);
bimage.flush();
}
}
public void update(Graphics g){
paintPresent;
}

//Component initialization
private void jbInit() throws Exception {
}

//Get Applet information
public String getAppletInfo() {
return "Applet Information";
}

//Get parameter info
public String[][] getParameterInfo() {
return null;
}
}


rizard edited on 2003-11-03 20:45


话题树型展开
人气 标题 作者 字数 发贴时间
10554 Applet 显示多幅图片,内存溢出错误!! rizard 2173 2003-11-03 20:41

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923