import java.awt.*; import java.awt.event.*; import java.io.*; class MyWindowDemo { private Frame f; private TextField tf; private Button but; private TextArea ta; MyWindowDemo() { init(); } public void init() { f=new Frame("my window"); f.setBounds(300,100,600,500); { f=new Frame("my window"); f.setBounds(300,100,600,500); f.setLayout(new FlowLayout()); tf=new TextField(60); but=new Button("转到"); ta=new TextArea(25,70); f.add(tf); f.add(but); f.add(ta); myEvent(); f.setVisible(true); } private void myEvent() { but.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String dirPath=tf.getText(); File dir=new File(dirPath); if(dir.exits()&&dir.isDirectory()) { ta.setText(""); String[] name=dir.list(); for(String name:names) { ta.append(name+"\r\n"); } } } }); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System. exit(0); } }); } public static void main(String[] args) { new MyWindowDemo(); } }
刹那烟华丶
相关分类