[讨论][求助]请教一个程序!!
麻烦大家帮我看看这个程序为什么导入不了文件啊?在此先谢谢了!!import java.awt.*;
import java.awt.event.*;
import java.io.*;
class lianxi extends Frame
{
lianxi(String str)
{
super(str);
}
public static void main(String[] args)
{
final lianxi x=new lianxi("菜单窗口");
x.setSize(600,400);
x.setLocation(180,180);
MenuBar y=new MenuBar();
Menu z1=new Menu("File");
Menu z2=new Menu("Edit");
MenuItem v1=new MenuItem("New");
MenuItem v2=new MenuItem("Open");
final TextArea Te=new TextArea();
x.add(Te);
v2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
FileDialog F1=new FileDialog(x,"导入文件",FileDialog.LOAD);
F1.setVisible(true);
String str=F1.getFile();
if(str!=null)
{
try
{
FileInputStream F2=new FileInputStream(str);
byte[] a=new byte[10*1024];
int len=F2.read(a);
Te.append(new String(a,0,len));
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
});
MenuItem v3=new MenuItem("Save");
MenuItem v4=new MenuItem("Exit");
v4.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
});
MenuItem v5=new MenuItem("Copy");
MenuItem v6=new MenuItem("remove");
z1.add(v1);
z1.add(v2);
z1.add(v3);
z1.add(v4);
z2.add(v5);
z2.add(v6);
y.add(z1);
y.add(z2);
x.setMenuBar(y);
x.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
x.setVisible(true);
}
}