JAVA's fifth job and java's fifth job
If you do not understand it, please refer to the import java. awt. color; import java. awt. borderLayout; import java. io. file; import java. awt. container; import java. awt. event. actionEvent; import java. util. arrayList; import java. util. list; import javax. swing. JComboBox; import javax. swing. JFrame; import javax. swing. JLabel; import javax. swing. JList; import javax. swing. JPanel; import javax. swing. JScrollPane; import javax. swing. JTextArea; public class Fil EUtils extends JFrame {/*** list all files or directories in the specified folder (directory) * @ param dri File-type specified folder (directory) * @ throws IllegalAccessException */public static String listDirectory (File dir) throws IllegalAccessException {if (! Dir. exists () {throw new IllegalAccessException ("directory" + dir + "does not exist");} // determine whether the associated files and directories under dir exist if (! Dir. isDirectory () {// if no exception is thrown, throw new IllegalAccessException (dir + "not a directory");} String [] fileName = dir. list (); String name = ""; for (String a: fileName) {name = name + a + "\ n" ;}return name ;} /*** @ param args */public static void main (String [] args) {// TODO Auto-generated method stub JFrame frame = new JFrame (); JPanel main_panel = new JPanel (new BorderLayout (); frame. setdefaclocloseoperation (JFrame. EXIT_ON_CLOSE); // frame. setLayout (null); String [] itme = new String [] {". jpg ",". zip ",". 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 = FileUtils. listDirectory (new File ("C: \ Users \ Administrator \ Desktop \ Java job 5 \ soundPlayer \ audio"); main_text.setText (str );} catch (IllegalAccessException e) {// TODO Auto-generated catch block e. printStackTrace ();} frame. setBounds (300,400,300,400); frame. setVisible (true );}}