Job One:
The file displays a list box.
The drop-down combo box is added, and the text locale color is red.
1Import javax.swing.*;2Import java.awt.*;3 import Java.io.File;4 5 Public classFileutil extends jframe{6 7 /**8 * @param args9 */Ten One Public StaticString listdirectory (File dir) throws illegalaccessexception{ A if(!dir.exists ()) { - Throw NewIllegalaccessexception ("Catalogue"+dir+"does not exist"); - } the 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";} A returnname; at } - - Public Static voidMain (string[] args) { - //TODO auto-generated Method Stub -JFrame frame=NewJFrame (); -JPanel Main_panel =NewJPanel (NewBorderLayout ()); inJLabel label =NewJLabel ("FileList"); - frame.setdefaultcloseoperation (jframe.exit_on_close); to //frame.setlayout (null); +string[] Itme =Newstring[]{"Folder A","folder B"}; -JComboBox box=NewJComboBox (); the for(intI=0; i<itme.length;i++){ * Box.additem (Itme[i]); $ }Panax NotoginsengBox.setenabled (true); -Box.seteditable (true); theBox.setmaximumrowcount (6); +Box.setbounds ( the, -, the, -); A theFrame.setbounds ( -, -, -, $); +Frame.setvisible (true); -JTextArea Main_text =NewJTextArea (); $ Main_text.setbackground (color.red); $JScrollPane aa=NewJScrollPane (); - Aa.setviewportview (main_text); -Main_text.setenabled (false); the Main_panel.add (Box,borderlayout.north); - Main_panel.add (aa,borderlayout.center);Wuyi Main_panel.add (Label,borderlayout.south); the Frame.add (main_panel); - Wu Try { -String Str=fileutil.listdirectory (NewFile ("C:\\users\\woshinibaba\\desktop\\java Job 5\\soundplayer")); About Main_text.settext (str); $ } - Catch(illegalaccessexception e) { - //TODO auto-generated Catch block - e.printstacktrace (); A } + the - $Frame.setbounds ( -, $, $, $); theFrame.setvisible (true); the the the } -}
Code effects:
Job 2:
Fifth time Java Job