@@ -11,10 +11,11 @@ public class TextEditor extends JFrame implements ActionListener {
1111
1212static JTextArea textarea ;
1313JMenuBar menuBar ;
14- JMenu file ,edit ;
15- JMenuItem jNew ,jOpen ,jSave ,jSaveas ,jExit ,jUndo ,jRedo ,jCut ,jCopy ,jPaste ,jSelect ,jSelectAll ;
14+ JMenu file ,edit , format ;
15+ JMenuItem jNew ,jOpen ,jSave ,jSaveas ,jExit ,jUndo ,jRedo ,jCut ,jCopy ,jPaste ,jSelect ,jSelectAll , jBackColor , jFontColor ;
1616Image icon ;
1717String fileName ,findText ,fileContent ;
18+ JCheckBoxMenuItem jWordWrap ;
1819JFileChooser fileChooser ;
1920JToolBar toolBar ;
2021UndoManager un ;
@@ -40,6 +41,8 @@ public TextEditor() {
4041menuBar .add (file );
4142edit =new JMenu ("Edit" );
4243menuBar .add (edit );
44+ format =new JMenu ("Format" );
45+ menuBar .add (format );
4346
4447jNew =new JMenuItem ("New" );
4548jOpen =new JMenuItem ("Open" );
@@ -87,6 +90,21 @@ public TextEditor() {
8790jPaste .addActionListener (this );
8891jSelectAll .addActionListener (this );
8992
93+ jWordWrap =new JCheckBoxMenuItem ("Word Wrap" ,true );
94+ jFontColor =new JMenuItem ("Font Color" );
95+ jBackColor =new JMenuItem ("Background Color" );
96+
97+ format .add (jWordWrap );
98+ format .add (jFontColor );
99+ format .add (jBackColor );
100+
101+ jWordWrap .setActionCommand ("wrap" );
102+ jWordWrap .addActionListener (this );
103+ jFontColor .setActionCommand ("fontcolor" );
104+ jFontColor .addActionListener (this );
105+ jBackColor .setActionCommand ("backcolor" );
106+ jBackColor .addActionListener (this );
107+
90108textarea .getDocument ().addUndoableEditListener (new UndoableEditListener () {
91109public void undoableEditHappened (UndoableEditEvent e ) {
92110un .addEdit (e .getEdit ());
@@ -160,6 +178,24 @@ public void actionPerformed(ActionEvent e) {
160178case "Exit" :
161179exitFile ();
162180break ;
181+ case "wrap" :
182+ if (jWordWrap .isSelected ()) {
183+ textarea .setLineWrap (true );
184+ textarea .setWrapStyleWord (true );
185+ jWordWrap .setText ("Word Wrap" );
186+ }
187+ else {
188+ textarea .setLineWrap (false );
189+ textarea .setWrapStyleWord (false );
190+ jWordWrap .setText ("Word Wrap" );
191+ }
192+ break ;
193+ case "fontcolor" :
194+ Color c =JColorChooser .showDialog (this ,"Select Font Color" ,Color .black );
195+ textarea .setForeground (c );
196+ break ;
197+ case "backcolor" :
198+ break ;
163199default :
164200break ;
165201 }