小问题,但不知道在哪里
import java.awt.*;
import java.awt.event.*;
import java.io.*;
class MyFrameDemo
{
MyFrameDemo()
{
init();
}
private Frame f;
private TextField tf;
private TextArea ta;
private Button but;
public void init()
{
f = new Frame("my frame");
tf = new TextField(60);
but = new Button("转到");
ta = new TextArea(25,70);
f.setBounds(300,100,600,500);
f.setLayout(new FlowLayout());
f.add(but);
f.add(tf);
f.add(ta);
myEvent();
f.setVisible(true);
}
public void myEvent()
{
but.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String dirPath = tf.getText();
File dir = new File(dirPath);
if(dir.exists() && dir.isDirectory())
{
String [] names = dir.list();
for (String name : names)
{
ta.append(name+"\r\n");
}
}
}
});
}
public static void main(String[] args)
{
new MyFrameDemo();
}
}