public void addEvent()
{
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent w)
{
System.exit(0);
}
});
d.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent w)
{
d.setVisible(false);
}
});
b1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent a)
{
d.setVisible(false);
}
});
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent a)
{
String dir = tf.getText();
//tf.setText("");
File fi = new File(dir);
if(fi.exists() && fi.isDirectory())
{
ta.setText("");//清空
String[] list = fi.list();
for(String l : list)
{
ta.append(l+"\r\n");
}
}
else
{
//f代表该对话框与那个窗体相关联
d =new Dialog(f,"错误提示",true);
b1 = new Button("确定");
String s = "请检查您输入的目录"+dir+"有误";
la = new Label(s);
d.setBounds(200,200,200,200);
d.setLayout(new FlowLayout());
d.add(la);
d.add(b1);
d.setVisible(true);
}
}
});
}
public static void main(String[] args)
{
new AwtFileList();
}
}