关于如何使用getImage方法???
写了一个小程序使用FileDialog对话框打开用户指定的gif图像文件,却发现总是编译不过去,好像是getImage方法中的参数不对,不知道如何修改???请指教!!!
import java.applet.Applet;
import java.awt.event.*;
import java.awt.*;
public class ShowGIF
{
public static void main(String args[])
{
new FileFrame();
}
}
class FileFrame extends Frame implements ActionListener
{
Button open,quit;
FileDialog fd;
Label prompt;
Image myImage;
FileFrame()
{
super("获取并显示gif图像文件:");
open=new Button("打开");
quit=new Button("关闭");
prompt=new Label("请按打开按钮指定欲打开gif图片按钮的地址:");
open.addActionListener(this);
quit.addActionListener(this);
setLayout(new FlowLayout());
add(prompt);
add(open);
add(quit);
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand()=="打开")
{
fd=new FileDialog(this,"打开文件",FileDialog.LOAD);
fd.setDirectory("d:\\temp");//设置文件对话框的基础目录
fd.show();//弹出并显示文件对话框,程序暂停直至用户选定一文件
try{
myImage=getImage(fd.getDirectory(),fd.getFile());//出错!!!是不是参数fd.getDirectory()不对?
repaint();
}
catch(IOException ioe)
{
System.err.println(ioe.toString());
}
}
if(e.getActionCommand()=="关闭")
{
dispose();
System.exit(0);
}
}
public void paint(Graphics g)
{
g.drawImage(myImage,10,10,this);
}
}
j2sdk1.4.1中的调试信息:
G:\My Works\Programs\Java\ShowGIF.java:41: cannot resolve symbol
symbol : method getImage (java.lang.String,java.lang.String)
location: class FileFrame
myImage=getImage(fd.getDirectory(),fd.getFile());//出错!!!是不是参数fd.getDirectory()不对?
^
G:\My Works\Programs\Java\ShowGIF.java:44: cannot resolve symbol
symbol : class IOException
location: class FileFrame
catch(IOException ioe)
^
2 errors