Import javax.swing.*; import java.awt.*; import Java.io.File; Public classWork extends jframe{/** * @param args*/ Public StaticString listdirectory (File dir) throws illegalaccessexception{if(!dir.exists ()) { Throw NewIllegalaccessexception ("Catalogue"+dir+"does not exist"); } if(!dir.isdirectory ()) {//Judging is not a directory Throw NewIllegalArgumentException (dir+"not a directory"); } string[] FileName=dir.list (); String name=""; for(String a:filename) {name=name+a+"\ n";} returnname; } Public Static voidMain (string[] args) {//TODO auto-generated Method StubJFrame frame=NewJFrame (); JPanel Main_panel=NewJPanel (NewBorderLayout ()); Frame.setdefaultcloseoperation (Jframe.exit_on_close); //frame.setlayout (null);string[] Itme =Newstring[]{"","2"}; JComboBox Box=NewJComboBox (); for(intI=0; i<itme.length;i++) {Box.additem (itme[i]); } box.setenabled (true); Box.seteditable (true); Box.setmaximumrowcount (6); Box.setbounds ( the, -, the, -); Frame.setbounds ( -, -, -, $); Frame.setvisible (true); JTextArea Main_text=NewJTextArea (); Main_text.setbackground (Color.Black); JScrollPane AA=NewJScrollPane (); 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=work.listdirectory (NewFile ("D:\\soundplayer")); Main_text.settext (str); } Catch(illegalaccessexception e) {//TODO auto-generated Catch blockE.printstacktrace (); } frame.setbounds ( -, $, -, $); Frame.setvisible (true); }}
Displays the file under the specified path to the text box, and the program adds a combo box and a background color. Through this assignment, I mastered the operation of reading files from disk.
Java Fifth time job