为什么把APPLET 存为 a.jpeg,a.jpeg什么都没有???急!!!!

xiaoxiao_xiao 2002-01-23 10:07:02
为什么把APPLET 存为 a.jpeg 时 打开a.jpeg什么都没有,还有我该怎么样设置时applet有权限许可才能写文件


import java.applet.Applet;
import java.awt.image.BufferedImage;
import java.io.*;
import com.sun.media.jai.codec.*;
import com.sun.media.jai.codecimpl.*;
import java.awt.*;
import java.awt.event.*;


public class HelloWorldApplet extends Applet {
Button button1 = new Button();
BufferedImage bi=new BufferedImage(200,100,BufferedImage.TYPE_INT_RGB);

public void paint(Graphics g) {
Graphics bg=bi.createGraphics();

System.out.print("op");
bg.drawString("Hello world!", 50, 25);
g.drawImage(bi,0,0,this);
}

public static void saveImage(BufferedImage img, File f) throws Exception{
ImageEncoder enc = getImageEncoder(f);
if(enc == null) {
return; //ups...
}
enc.encode(img.getData(), img.getColorModel());
enc.getOutputStream().close();
}

public static ImageEncoder getImageEncoder(File f)
throws Exception {

ImageEncodeParam encodeParam = null;
String type = null;
String name = f.getName();
System.out.println(name);
String ext;
int dotIndex = name.lastIndexOf('.');
if ( dotIndex == -1 ¦¦ dotIndex == name.length()-1 ) ext = "";
else ext = name.substring(dotIndex+1).toLowerCase();
System.out.println(ext);
if(ext.equals("jpeg") ¦¦ ext.equals("jpg")) {
type = "JPEG";
encodeParam = new JPEGEncodeParam();
((JPEGEncodeParam)encodeParam).setQuality(1F);
}
else if (ext.equals("tiff") ¦¦ ext.equals("tif")) {
type = "TIFF";
encodeParam = new TIFFEncodeParam();
((TIFFEncodeParam)encodeParam).setCompression(TIFFEncodeParam.COMPRESSION_NONE);
}
else if(ext.equals("bmp")) {
type = "BMP";
encodeParam = new BMPEncodeParam();
}
else if(ext.equals("png")) {
type = "PNG";
encodeParam = new PNGEncodeParam.Palette();
((PNGEncodeParam.Palette)encodeParam).setBitDepth(2);
}
else if(ext.equals("gif")) {
System.out.println("oK");
throw new Exception( "Gif file format is not yet supported !");
}
else {
throw new Exception( "Unknown extension: " + ext);
}
return ImageCodec.createImageEncoder(type, new FileOutputStream(f),encodeParam);

}

public HelloWorldApplet() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
button1.setLabel("button1");
button1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
button1_actionPerformed(e);
}
});
this.add(button1, null);
}

void button1_actionPerformed(ActionEvent e) {
String s="classes/a.jpeg";
File f=new File(s);
HelloWorldApplet hwa=new HelloWorldApplet();
System.out.print(s);
try
{
hwa.saveImage(bi, f);
}
catch(Exception ee){
System.out.println(e.toString());}
}

}


...全文
117 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
luckysym 2002-01-24
  • 打赏
  • 举报
回复
applet 是程序,不是图片,On, My God
xiaoxiao_xiao 2002-01-24
  • 打赏
  • 举报
回复
上面的兄弟,我的applet肯定是切入网页中的呀,而且我是要把
我所画的applet存为图片即BufferedImage存为图片

xiaoxiao_xiao 2002-01-24
  • 打赏
  • 举报
回复
上面的兄弟,我的applet肯定是切入网页中的呀,而且我是要把
我所画的applet存为图片即BufferedImage存为图片
elucyfa 2002-01-23
  • 打赏
  • 举报
回复
大哥,要存成.java然后用编译器编译成class文件才行,或者写上
<applet code=yourclassname.class weight=200 hight=100>
</applet>
存成html文件,调用
肖尧19 2002-01-23
  • 打赏
  • 举报
回复
*

23,407

社区成员

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

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