GUI(练习-列出指定目录内容)
2012-09-20 23:29
531 查看
/* * 程序头部注释开始 * 程序的版权和版本声明部分 * Copyright (c) 2011, 烟台大学计算机学院学生 * All rights reserved. * 文件名称:GUI(练习-列出指定目录内容) * 作 者:薛广晨 * 完成日期:2011 年 09 月 20 日 * 版 本号:x1.0 * 对任务及求解方法的描述部分 * 输入描述: * 问题描述: * 程序输出: * 程序头部的注释结束 */ package xue; import java.awt.*; import java.awt.event.*; import java.io.File; public class MyWindow { /** * @param args */ private Frame f; private TextField tf; private Button but; private TextArea ta; MyWindow() { init(); } public void init() { 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() { // TODO Auto-generated method stub but.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String dirPath = tf.getText(); File dir = new File(dirPath); if(dir.exists() && dir.isDirectory()) { ta.setText(""); String[] names = 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) { // TODO Auto-generated method stub new MyWindow(); } }
运行结果:
相关文章推荐
- GUI练习:列出指定目录内容
- GUI(练习-列出指定目录内容 )的升级版 有对话框Dialog
- Java-GUI(练习-列出指定目录内容)-(对话框Dialog)
- [javaSE] GUI(练习-列出指定目录内容)
- GUI练习——列出指定目录内容
- GUI练习——列出指定目录内容
- 25-GUI-08-GUI(练习-列出目录内容)
- JAVA GUI(列出指定目录内容)
- GUI——练习(列出制定目录内容)
- GUI初探--列出指定目录的内容
- 9.JAVA之GUI编程列出指定目录内容
- Test__GUI__列出指定目录内容
- 事件监听机制——列出指定目录内容、添加Dialog对话框
- java-列出指定目录的全部内容
- GUI列出目录内容,添加Dialog对话框
- 事件监听机制——列出指定目录内容、添加Dialog对话框
- 列出指定目录下文件或者文件夹,包含子目录的内容。
- Java基础-列出指定目录内容和对话框(Dialog)
- 代码训练营——File,列出指定目录下的所有内容
- File类,列出当前指定路径下的所有内容,目录中包含的目录不关心,递归打破肘挚,学习