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

    import java.awt.;
    import java.io.File;
    import java.util.ArrayList;
    import java.util.List;
    import javax.swing.
    ;

    public class sq extends JFrame {
    private static final String music = "file";
    private JFrame frame;
    private JList fileList;

    public sq() {

    String[] FileNames = findFiles(music, null);
    makeFrame(FileNames);
    frame.pack();
    frame.setVisible(true);
    frame.setSize(250, 380);
    frame.setLocation(550, 400);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    private String[] findFiles(String dirName, String suffix) {
    File dir = new File(dirName);
    //判断Dir是否为目录
    if (dir.isDirectory()) {
    String[] allFiles = dir.list();
    if (suffix == null) {
    return allFiles;
    } else {
    //获得目录下的文件并输出
    List selected = new ArrayList();
    for (String filename : allFiles) {
    if (filename.endsWith(suffix)) {
    selected.add(filename);
    }
    }
    return selected.toArray(new String[selected.size()]);
    }
    } else {
    System.out.println("Error: " + dirName + " must be a directory");
    return null;
    }
    }

    private void makeFrame(String[] audioFiles) {

    frame = new JFrame();
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    JPanel contentPane = (JPanel) getContentPane();

    contentPane.setLayout(new BorderLayout(8, 8));

    JPanel leftPane = new JPanel();
    {
    leftPane.setLayout(new BorderLayout(8, 8));

    fileList = new JList(audioFiles);
    fileList.setForeground(new Color(120,135, 226));
    fileList.setBackground(new Color(0, 0, 0));
    fileList.setSelectionBackground(new Color(80, 15, 226));
    fileList.setSelectionForeground(new Color(140, 171, 226));
    JScrollPane scrollPane = new JScrollPane(fileList);
    scrollPane.setColumnHeaderView(new JLabel("files list"));
    leftPane.add(scrollPane, BorderLayout.CENTER);
    }
    contentPane.add(leftPane, BorderLayout.CENTER);
    frame.add(contentPane);
    }

    public static void main(String[] args) {
    // TODO Auto-generated method stub
    new sq();

    }

    }

  • 相关阅读:
    “人工智能”前景:只有人工,没有智能
    google scholar vs baidu scholar-what is your problem
    springSecurity使用
    springMVC中的HttpSession与Model
    mybatis关于Criteria的一点小坑。。。
    MyBatis的Mapper接口以及Example的实例函数及详解
    被springSecurity坑哭的一天
    Mybatis-Generator
    Redis五种数据类型应用场景
    springboot_自动配置原理
  • 原文地址:https://www.cnblogs.com/sunqian2016/p/5402777.html
Copyright © 2011-2022 走看看