3636import java .util .Scanner ;
3737import javax .swing .text .DefaultEditorKit ;
3838
39- public class UI extends JFrame implements ActionListener {
39+ public class UI extends JFrame implements ActionListener
40+ {
41+
4042
4143 private static final long serialVersionUID = 1L ;
4244 private final Container container ;
4345 private final JTextArea textArea ;
4446 private final JMenuBar menuBar ;
4547 private final JMenu menuFile , menuEdit , menuFind , menuAbout ;
4648 private final JMenuItem newFile , openFile , saveFile , close , cut , copy , paste , clearFile , selectAll , quickFind ,
47- aboutMe , aboutSoftware ;
49+ aboutMe , aboutSoftware , wordWrap ;
4850 private final JToolBar mainToolbar ;
4951 JButton newButton , openButton , saveButton , clearButton , quickButton , aboutMeButton , aboutButton , closeButton ,
5052 spaceButton1 , spaceButton2 ;
@@ -62,6 +64,7 @@ public class UI extends JFrame implements ActionListener {
6264 private final ImageIcon copyIcon = new ImageIcon ("icons/copy.png" );
6365 private final ImageIcon pasteIcon = new ImageIcon ("icons/paste.png" );
6466 private final ImageIcon selectAllIcon = new ImageIcon ("icons/selectall.png" );
67+ private final ImageIcon wordwrapIcon = new ImageIcon ("icons/wordwrap.png" );
6568
6669 // setup icons - Search Menu
6770 private final ImageIcon searchIcon = new ImageIcon ("icons/search.png" );
@@ -91,6 +94,10 @@ public UI() {
9194 textArea .setTabSize (2 );
9295 textArea .setFont (new Font ("Century Gothic" , Font .BOLD , 12 ));
9396 textArea .setTabSize (2 );
97+
98+
99+ /* SETTING BY DEFAULT WORD WRAP ENABLED OR TRUE*/
100+ textArea .setLineWrap (true );
94101
95102 // This is why we didn't have to worry about the size of the TextArea!
96103 getContentPane ().setLayout (new BorderLayout ()); // the BorderLayout bit makes it fill it automatically
@@ -175,6 +182,53 @@ public UI() {
175182 cut .setToolTipText ("Cut" );
176183 cut .setAccelerator (KeyStroke .getKeyStroke (KeyEvent .VK_X , InputEvent .CTRL_MASK ));
177184 menuEdit .add (cut );
185+
186+ //WordWrap
187+
188+ wordWrap = new JMenuItem ();
189+ wordWrap .setText ("Word Wrap" );
190+ wordWrap .setIcon (wordwrapIcon );
191+ wordWrap .setToolTipText ("Word Wrap" );
192+
193+ //Short cut key or key stroke
194+ wordWrap .setAccelerator (KeyStroke .getKeyStroke (KeyEvent .VK_W , InputEvent .CTRL_MASK ));
195+ menuEdit .add (wordWrap );
196+
197+
198+
199+ /* CODE FOR WORD WRAP OPERATION
200+
201+ START WORDWRAP OPERATION
202+
203+ BY DEFAULT WORD WRAPPING IS ENABLED.
204+
205+ */
206+
207+ wordWrap .addActionListener (new ActionListener ()
208+ {
209+ public void actionPerformed (ActionEvent ev )
210+ {
211+ // If wrapping is false then after clicking on menuitem the word wrapping will be enabled
212+ if (textArea .getLineWrap ()==false )
213+ {
214+
215+ /*Setting word wrapping to true*/
216+ textArea .setLineWrap (true );
217+
218+ }
219+
220+ // else if wrapping is true then after clicking on menuitem the word wrapping will be disabled
221+ else
222+ {
223+ /*Setting word wrapping to false*/
224+ textArea .setLineWrap (false );
225+ }
226+ }
227+ });
228+
229+
230+ //END OF THE WORDWRAP OPERATION
231+
178232
179233 // Copy Text
180234 copy = new JMenuItem (new DefaultEditorKit .CopyAction ());
@@ -280,8 +334,16 @@ public void actionPerformed (ActionEvent e) {
280334
281335 // If the source was the "new" file option
282336 else if (e .getSource () == newFile || e .getSource () == newButton ) {
283- FEdit .clear (textArea );
337+ FEdit .clear (textArea );
338+
284339 }
340+
341+
342+
343+
344+
345+
346+
285347 // If the source was the "open" option
286348 else if (e .getSource () == openFile || e .getSource () == openButton ) {
287349 JFileChooser open = new JFileChooser (); // open up a file chooser (a dialog for the user to browse files to open)
0 commit comments