zoukankan      html  css  js  c++  java
  • 第五次作业(2)

    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Container;
    import java.awt.event.ActionEvent;
    import java.io.File;
    import java.util.ArrayList;
    import java.util.List;

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

    public class FileUtils extends JFrame{

    /**
     * @param args
     */
     
    public static String listDirectory(File dir) throws IllegalAccessException{
        if(!dir.exists()){
            throw new IllegalAccessException("目录"+dir+"不存在");
        }
        if(!dir.isDirectory()){//判断是不是目录
            throw new IllegalArgumentException(dir+"不是目录");
        }
        String[] fileName = dir.list();   
        String name ="";
        for(String a : fileName){
            name=name+a+"
    ";}
        return name;
        }
     
    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 =new String[]{"all",".wav",".au"};
        JComboBox box=new JComboBox();
        for(int i=0;i<itme.length;i++){
            box.addItem(itme[i]);
        }
        box.setEnabled(true);
        box.setEditable(true);
        box.setMaximumRowCount(6);
        box.setBounds(230,30,130,25);
        frame.setBounds(400,300,400,200);
        frame.setVisible(true);
        JTextArea main_text =new JTextArea();
         main_text.setBackground(Color.BLACK);
        JScrollPane AA=new JScrollPane();
        AA.setViewportView(main_text);
        main_text.setEnabled(false);
        main_panel.add(box,BorderLayout.NORTH);
        main_panel.add(AA,BorderLayout.CENTER);
        frame.add(main_panel);
         
        try {
            String str=FileUtils.listDirectory(new File("C:\Users\lenovo\Desktop\Java作业5\soundPlayer"));
            main_text.setText(str);
        }
        catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }      frame.setBounds(400,200,400,200);
        frame.setVisible(true);
    }
    

    }

  • 相关阅读:
    linq中的AsEnumerable()方法
    c# 一个匿名对象中包含多个子对象的处理方式
    jenkins的安装与启动
    牛客网-2018年湘潭大学程序设计竞赛-F
    poj-1149(最大流)
    hdu-2255(带权二分图)
    bzoj-1191(二分图最大匹配)
    codevs2822
    hdu 5652(并查集)
    hdu—3861(tarjan+二分图)
  • 原文地址:https://www.cnblogs.com/humeiling/p/5402497.html
Copyright © 2011-2022 走看看