import java.awt.*;
import java.awt.event.*;
import java.io.File;
public class GUIDir {
private Frame f;
private TextField tf = new TextField(40);
private TextArea ta = new TextArea(30,40);
private Button bu = new Button("转到");
public GUIDir(){
f = new Frame("收索工具");
f.setBounds(100, 100, 400, 500);
f.addWindowListener(new WindowAdapter(){
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
Panel p = new Panel();
p.setLayout(new FlowLayout());
p.add(tf);
p.add(bu);
f.setLayout(new FlowLayout());
//f.add(new Button("转到"));
f.add(p);
f.add(ta);
listener();
//f.pack();
}
public void listener(){
bu.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
/*String text = tf.getText();
ta.append(text+"\r\n");
//
tf.setText("");
System.out.println("ok");*/
String dir = tf.getText();
File f = new File(dir);
if(f.exists()&&f.isDirectory()){
ta.setText("");
String[] names = f.list();
for(String name:names){
ta.append(name+"\r\n");
}
}
}});
}
public static void main(String[] args) {
new GUIDir();
}
}
|
|