Notepad's open save function is used to Jfilechoser
1 PackageMyNote;2 3 Importjava.awt.BorderLayout;4 Importjava.awt.event.ActionEvent;5 ImportJava.awt.event.ActionListener;6 ImportJava.io.*;7 8 Importjavax.swing.*;9 Ten Public classMyNoteextendsJFrameImplementsactionlistener{ One A /** - * @paramargs - */ the JTextArea JTA; - JScrollPane jsp; - - JMenuBar JMB; + JMenu JM; - JMenuItem jmi1,jmi2; + Public Static voidMain (string[] args) { A //TODO auto-generated Method Stub atMyNote MN =Newmynote (); - } - - PublicMyNote () { -JTA =NewJTextArea (); -JSP =NewJScrollPane (JTA); inJMB =NewJMenuBar (); -JM =NewJMenu ("File"); toJMI1 =NewJMenuItem ("Open"); +Jmi2 =NewJMenuItem ("Save"); -Jmi1.addactionlistener ( This); theJmi1.setactioncommand ("Open"); *Jmi2.addactionlistener ( This); $Jmi2.setactioncommand ("Save");Panax Notoginseng - This. Setjmenubar (JMB); the Jm.add (JMI1); + Jm.add (jmi2); A Jmb.add (JM); the + This. Add (JSP); - This. SetSize (400,300); $ This. setvisible (true); $ This. Setdefaultcloseoperation (jframe.exit_on_close); - } - the @Override - Public voidactionperformed (ActionEvent e) {Wuyi //TODO auto-generated Method Stub the if(E.getactioncommand (). Equals ("open")){ -System.out.println ("Open"); WuJFileChooser FC =NewJFileChooser ("DD"); -Fc.setdialogtitle ("Please select"); AboutFc.showopendialog (NULL); $Fc.setvisible (true); - -String s =fc.getselectedfile (). GetAbsolutePath (); - System.out.print (s); A +FileReader FR =NULL; theBufferedReader br=NULL; -String str = ""; $String str1 = ""; the the Try { theFR =NewFileReader (s); theBR =NewBufferedReader (FR); - in intN=0; the while((Str=br.readline ())! =NULL){ thestr1 = str1+str+ "\ r \ n"; About } the}Catch(Exception E1) { the //TODO auto-generated Catch block the e1.printstacktrace (); +}finally{ - Try { the br.close ();Bayi}Catch(IOException E1) { the //TODO auto-generated Catch block the e1.printstacktrace (); - } - } the the Jta.settext (str1); the the } - } the}
Interface Programming File IO monitoring