/ ** *
Title: p> *
Description: p> *
Copyright: Copyright (c) 2003 p> *
Company: p> * @ Author not attributable * @version 1.0 * / import java.awt. *; import java.awt.event. *; import javax.swing. *; import javax.swing.event. *; import java.io. *;
public class tj {String title = "ERROR MESSAGE"; int type = JOptionPane.ERROR_MESSAGE; public tj () {final JFrame frame = new JFrame ( "My Edit"); final JTextArea text = new JTextArea (); frame.setSize ( 600, 500); frame.addwindowlistener (new windowadapter () {public void window {system.exit (0);}}); jPanel panel = new jPanel (); panel.setLayout (New GridLayout (1, 1)); Panel.Add (new jscrollpane (text)); frame.getContentPane (). Add (panel); jMenuBar mbar = new jmenubar (); frame.setjmenubar; jMenu jfile = new jmenu ("file" ); JMenu jedit = new jMenu ("edit"); jMenu jhelp = new jMenu ("help"); mbar.add (jed); mbar.add (jhelp); jmenuitem jnew = new jmenuitem ("New"); jnew.addactionListener (new actionListener () {public void actionPerformed (ActionEvent E) {text.setText (");}}); JNEW.SETMNEMONIC ('n'); jnew.setAccelerator (Keystroke. GetKeystroke ('n' , Java.awt.Event.CTRL_MASK, true)); JMenuItem jopen = new JMenuItem ( "Open"); jopen.addActionListener (new ActionListener () {public void actionPerformed (ActionEvent e) {JFileChooser openfile = new JFileChooser (); openfile .setDialogTitle ( "open file"); openfile.setApproveButtonText ( "open"); openfile.showOpenDialog (frame); File file = openfile.getSelectedFile (); FileInputStream inputfile = null; String message = "The file not Found"; try {INPUTFILE =
new FileInputStream (file);} catch (FileNotFoundException fe) {JOptionPane.showMessageDialog (frame, message, title, type);} int readbytes; String message1 = "read file error"; try {while ((readbytes = inputfile.read ( )))))! = - 1) {text.Append (String.Valueof ((char) readbytes);}}}}} catch (ooException ooe) {JOPANE.SHOWMESSAGEDIALOG (Frame, Message1, Title, Type);} String CloseMessage = "Close stream error "; try {inputfile.close ();} catch (IOException ioe) {JOptionPane.showMessageDialog (frame, closemessage, title, type);}}}); jopen.setMnemonic ( 'O'); jopen.setAccelerator ( Keystroke.getKeystroke ('o', java.awt.event.ctrl_mask, true); JMenuItem JSAV e = new JMenuItem ( "Save"); jsave.addActionListener (new ActionListener () {public void actionPerformed (ActionEvent e) {JFileChooser savefile = new JFileChooser (); savefile.setApproveButtonText ( "save"); savefile.setDialogTitle ( "save file "); savefile.showSaveDialog (frame); File filesa = savefile.getSelectedFile (); String messagef =" File not Found "; FileOutputStream outputfile = null; try {outputfile = new FileOutputStream (filesa);
} Catch (FileNotFoundException fe) {JOptionPane.showMessageDialog (frame, messagef, title, type);} String filecontent = text.getText (); String wrmessage = "write error"; try {outputfile.write (filecontent.getBytes ()) ;} catch (IOException ioe) {JOptionPane.showMessageDialog (frame, wrmessage, title, type);} String cmessage = "close stream error"; try {outputfile.close ();} catch (IOException ioe) {JOptionPane.showMessageDialog ( Frame, CMessage, Title, Type);}}}); jsave.setmnemonic ('s'); jsave.setkeystroke ('s', java.awt.event.ctrl_mask, true); jMenuItem jquite = NEW JMENUITEM ("QUITE"); jquite.addActionListener (new activityListener () {public void actionPerformed (ActionEvent E) {system.exit (0); }}); Jquite.setmnemonic ('q'); jquite.setAccelerator (keyStroke.getKeystroke ('q', java.awt.event.ctrl_mask, true); jFind = new jMenuitem ("find"); jfind. addActionListener (new ActionListener () {public void actionPerformed (ActionEvent e) {}}); jfind.setMnemonic ( 'F'); jfind.setAccelerator (KeyStroke.getKeyStroke ( 'F', java.awt.Event.CTRL_MASK, true) ); JMenuItem JCUT = New Jmenuitem ("CUT"); JCUT.ADDACTIONListener (New ActionListener () {public void ActionPerformed (ActionEvent E) {text.cut ();}}; JCUT.SETMNEMONIC ('c');