Java5

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+"\n";}
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("E:\\"));
main_text.setText(str);
}
catch (IllegalAccessException e) {
e.printStackTrace();
}
frame.setBounds(400,200,400,200);
frame.setVisible(true);

}
}

转载于:https://www.cnblogs.com/fanjiaming/p/5402620.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值