• 第五次java作业


    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.io.File;

    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;


    public class FileUtils {
    /**
    * 列出指定文件夹(目录)中的所有文件或目录的名称
    * @param dir File类型 指定的文件夹(目录)
    * @return
    * @throws IllegalAccessException
    */
    public static String listDirectory(File dir) throws IllegalAccessException{
    //判断dir所关联的文件和目录是否存在
    if(!dir.exists()){
    //如果不存在,那么抛出异常
    throw new IllegalAccessException("目录" + dir + "不存在。");
    }
    //判断dir所关联的是否是一个目录
    if(!dir.isDirectory()){
    throw new IllegalAccessException(dir + "不是目录");
    }
    /*用传递进来 的File对象dir调用list()方法获得
    * 当前目录(dir)下的所有文件和文件夹的名称。
    */
    String[] files = dir.list();
    String m ="";
    for(String a : files){
    m=m+a+" ";}
    return m;
    }
    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    JFrame frame=new JFrame();
    JPanel main_panel =new JPanel(new BorderLayout());//面板
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //frame.setLayout(null);

    //设置组合框
    String[] itme = {".png","ico"};
    JComboBox frm=new JComboBox(itme);
    frm.setEnabled(true);
    frm.setEditable(true);
    frm.setMaximumRowCount(5);
    frm.setBounds(230,30,130,25);

    frame.setBounds(400,200,350,400);
    frame.setVisible(true);
    JTextArea main_text =new JTextArea();
    main_text.setBackground(Color.BLACK);
    JScrollPane z=new JScrollPane();
    z.setViewportView(main_text);
    main_text.setEnabled(false);
    main_panel.add(frm,BorderLayout.NORTH);
    main_panel.add(z,BorderLayout.CENTER);
    frame.add(main_panel);

    try {
    String str = FileUtils.listDirectory(new File("D:\$_OUTDIR\Skin"));
    main_text.setText(str);
    } catch (IllegalAccessException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    }

    }

  • 相关阅读:
    6 【程序6 最大公约数和最小公倍数】
    5 【程序5 判断分数等级】
    4 【程序4 分解质因数】
    3 【程序3 水仙花数】
    2【程序2 输出素数】
    1 【程序1 不死神兔】
    终极解决傻X阿里钱盾新手开店及老卖家复核身份证照片模糊无法对焦问题
    struct和typedef struct彻底明白了
    CentOS 6.5 编译安装 LNMP环境
    Another MySQL daemon already running with the same unix socket
  • 原文地址:https://www.cnblogs.com/liuyajuan/p/5397187.html
Copyright © 2020-2023  润新知