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

     1 import javax.swing.*;
     2 import java.awt.*;
     3 import java.io.File;
     4 
     5 public class FileUtil extends JFrame{
     6 
     7     /**
     8      * @param args
     9      */
    10     
    11     public static String listDirectory(File dir) throws IllegalAccessException{
    12         if(!dir.exists()){
    13             throw new IllegalAccessException("目录"+dir+"不存在");
    14         }
    15         if(!dir.isDirectory()){//判断是不是目录
    16             throw new IllegalArgumentException(dir+"不是目录");
    17         }
    18         String[] fileName = dir.list();    
    19         String name ="";
    20         for(String a : fileName){
    21             name=name+a+"
    ";}
    22         return name;
    23         }
    24     
    25     public static void main(String[] args) {
    26         // TODO Auto-generated method stub
    27         JFrame frame=new JFrame();
    28         JPanel main_panel =new JPanel(new BorderLayout());
    29         JLabel label = new JLabel("FileList");
    30         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    31         //frame.setLayout(null);
    32         String[] itme =new String[]{"文件夹A","文件夹B"};
    33         JComboBox box=new JComboBox();
    34         for(int i=0;i<itme.length;i++){
    35             box.addItem(itme[i]);
    36         }
    37         box.setEnabled(true);
    38         box.setEditable(true);
    39         box.setMaximumRowCount(6);
    40         box.setBounds(230,30,130,25);
    41             
    42         frame.setBounds(400,300,400,200);
    43         frame.setVisible(true);
    44         JTextArea main_text =new JTextArea();
    45          main_text.setBackground(Color.red);
    46         JScrollPane AA=new JScrollPane();
    47         AA.setViewportView(main_text);
    48         main_text.setEnabled(false);
    49         main_panel.add(box,BorderLayout.NORTH);
    50         main_panel.add(AA,BorderLayout.CENTER);
    51         main_panel.add(label,BorderLayout.SOUTH);
    52         frame.add(main_panel);
    53         
    54         try {
    55             String str=FileUtil.listDirectory(new File("C:\Users\woshinibaba\Desktop\Java作业5\soundPlayer"));
    56             main_text.setText(str);
    57         }
    58         catch (IllegalAccessException e) {
    59             // TODO Auto-generated catch block
    60             e.printStackTrace();
    61         }
    62         
    63 
    64         
    65         frame.setBounds(400,200,200,200);
    66         frame.setVisible(true);
    67         
    68     
    69     }
    70 }

    
    
  • 相关阅读:
    匀速不间断旋转动画
    调用底层不能直接访问的类和方法
    当SD卡拔出时,返回首页,栈中的activity都要清除,只留下首页的activity
    Android 视频播放器切换到下个视频时残留上个视频画面的解决办法
    监听SD卡状态
    Android之SeekBar定制
    setRequestedOrientation设置屏幕方向
    【初级算法】15. 有效的字母异位词
    【初级算法】14. 字符串中的第一个唯一字符
    【初级算法】13. 颠倒整数
  • 原文地址:https://www.cnblogs.com/lkh960317/p/5401381.html
Copyright © 2011-2022 走看看