Import Javax.swing.JScrollPane;PublicClass FileList extends jframe{PrivateStatic finalString Files_dir ="Audio";Private JList fileList;Public FileList () {Super"FileList");string[] FileNames = FindFiles (Files_dir,NULL); Makeframe (FileNames);TODO auto-generated Constructor stub}Privatevoid Makeframe (String[] autonames) {setdefaultcloseoperation (exit_on_close); JPanel ContentPane = (JPanel) getcontentpane (); FileList =New JList (Autonames); Filelist.setforeground (New Color (140,171,226)); Filelist.setbackground (New Color (0,0,0)); Filelist.setselectionbackground (New Color (97M49,134)); Filelist.setselectionforeground (New Color (140,171,226)); JScrollPane ScrollPane =New JScrollPane (fileList); Scrollpane.setcolumnheaderview (New JLabel ("Files list"); Contentpane.add (ScrollPane, Borderlayout.center); Pack ();Place this frame at the center of the screen and show Dimension d = Toolkit.getdefaulttoolkit (). Getscreensize (); SetLocation (d.width/2-getwidth ()/2, d.height/2-getheight ()/2); SetVisible (true);}PrivateString[] FindFiles (String DirName,String suffix) {File dir =New File (DirName);if (Dir.isdirectory ()) {string[] Allfiles = Dir.list ();if (suffix = =NULL) {return allfiles; }else {list<String> selected = new arraylist<string> (); for (string filename:allfiles) { if (filename.endswith (suffix)) {selected.add (filename);}} return Selected.toarray (new String[selected.size ()]); }} else {System.out.println ( "Error:" + dirName + " must be a directory "); return null;} /** * @param args */public static Span class= "hljs-built_in" >void Main (string[] args) {new FileList (); } }
Java Fifth time job