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

    作业一:

    文件显示列表框。

    增加了下拉式组合框,text区域设置颜色为红色。

     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 }

    代码效果:

    作业2 :

  • 相关阅读:
    HDU 1358 Period (KMP)
    POJ 1042 Gone Fishing
    Csharp,Javascript 获取显示器的大小的几种方式
    css text 自动换行的实现方法 Internet Explorer,Firefox,Opera,Safar
    Dynamic Fonts动态设置字体大小存入Cookie
    CSS Image Rollovers翻转效果Image Sprites图片精灵
    CSS three column layout
    css 自定义字体 Internet Explorer,Firefox,Opera,Safari
    颜色选择器 Color Picker,Internet Explorer,Firefox,Opera,Safar
    CSS TextShadow in Safari, Opera, Firefox and more
  • 原文地址:https://www.cnblogs.com/wawawaawa/p/5396725.html
Copyright © 2011-2022 走看看