zoukankan      html  css  js  c++  java
  • 第五次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();
    }

    }

    }

  • 相关阅读:
    asp.net[web.config] httphandlers 与实现自由定义访问地址
    Web.config配置文件详解
    ASP.NET十分有用的页面间传值方法(转)
    web.config中authorization下的location中的path的设置 (转)
    基于FormsAuthentication的用户、角色身份认证(转)
    FormsAuthentication.RedirectFromLoginPage 登录
    php代码审计-下载站系统Simple Down v5.5.1 xss跨站漏洞分析
    创建二维码生成器
    更新自制入库价格(结账)
    常用的系统存储过程
  • 原文地址:https://www.cnblogs.com/liuyajuan/p/5397187.html
Copyright © 2011-2022 走看看