zoukankan      html  css  js  c++  java
  • Java第五次实验

    import javax.swing.*;
    import java.awt.*;
    import java.io.File;
    
    public class ListFilesUI extends JFrame{
    
        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) {
            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",".doc"};
            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=ListFilesUI.listDirectory(new File("C:\Users\Administrator\Desktop\Java作业5"));
                main_text.setText(str);
            }
            catch (IllegalAccessException e) {
                e.printStackTrace();
            }
            frame.setBounds(400,200,400,200);
            frame.setVisible(true);
    
        }
    }

    结果截图:

  • 相关阅读:
    Linux基础知识
    前端性能优化篇
    placeholder兼容ie8,9
    阻止事件冒泡 和 阻止事件默认行为
    DOM对象加载完成后再执行操作
    cs3完成的钟表
    常见前端算法面试题
    苹果手机浏览器$(document).on(“click”,function(){})点击无效的问题
    JQuery $(function(){})和$(document).ready(function(){})
    css3 pointer-events:none 允许点击穿透
  • 原文地址:https://www.cnblogs.com/gentleman-g/p/5396738.html
Copyright © 2011-2022 走看看