3636import java .util .Scanner ;
3737import javax .swing .text .DefaultEditorKit ;
3838
39- public class UI extends JFrame implements ActionListener
40- {
41-
42-
39+ public class UI extends JFrame implements ActionListener {
4340 private static final long serialVersionUID = 1L ;
4441 private final Container container ;
4542 private final JTextArea textArea ;
@@ -94,10 +91,9 @@ public UI() {
9491 textArea .setTabSize (2 );
9592 textArea .setFont (new Font ("Century Gothic" , Font .BOLD , 12 ));
9693 textArea .setTabSize (2 );
97-
98-
99- /* SETTING BY DEFAULT WORD WRAP ENABLED OR TRUE*/
100- textArea .setLineWrap (true );
94+
95+ /* SETTING BY DEFAULT WORD WRAP ENABLED OR TRUE */
96+ textArea .setLineWrap (true );
10197
10298 // This is why we didn't have to worry about the size of the TextArea!
10399 getContentPane ().setLayout (new BorderLayout ()); // the BorderLayout bit makes it fill it automatically
@@ -153,15 +149,15 @@ public UI() {
153149 /*
154150 * Along with our "CTRL+F4" shortcut to close the window, we also have
155151 * the default closer, as stated at the beginning of this tutorial. this
156- * means that we actually have TWO shortcuts to close:
152+ * means that we actually have TWO shortcuts to close:
157153 * 1) the default close operation (example, Alt+F4 on Windows)
158154 * 2) CTRL+F4, which we are
159155 * about to define now: (this one will appear in the label).
160156 */
161157 close .setAccelerator (KeyStroke .getKeyStroke (KeyEvent .VK_Q , InputEvent .CTRL_MASK ));
162158 close .addActionListener (this );
163159 menuFile .add (close );
164-
160+
165161 // Select All Text
166162 selectAll = new JMenuItem (selectAllAction );
167163 selectAll .setText ("Select All" );
@@ -182,53 +178,34 @@ public UI() {
182178 cut .setToolTipText ("Cut" );
183179 cut .setAccelerator (KeyStroke .getKeyStroke (KeyEvent .VK_X , InputEvent .CTRL_MASK ));
184180 menuEdit .add (cut );
185-
186- //WordWrap
187-
181+
182+ // WordWrap
188183 wordWrap = new JMenuItem ();
189- wordWrap .setText ("Word Wrap" );
184+ wordWrap .setText ("Word Wrap" );
190185 wordWrap .setIcon (wordwrapIcon );
191186 wordWrap .setToolTipText ("Word Wrap" );
192-
193- //Short cut key or key stroke
187+
188+ //Short cut key or key stroke
194189 wordWrap .setAccelerator (KeyStroke .getKeyStroke (KeyEvent .VK_W , InputEvent .CTRL_MASK ));
195190 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-
191+
192+ /* CODE FOR WORD WRAP OPERATION
193+ * BY DEFAULT WORD WRAPPING IS ENABLED.
194+ */
195+ wordWrap .addActionListener (new ActionListener ()
196+ {
197+ public void actionPerformed (ActionEvent ev ) {
198+ // If wrapping is false then after clicking on menuitem the word wrapping will be enabled
199+ if (textArea .getLineWrap ()==false ) {
200+ /* Setting word wrapping to true */
201+ textArea .setLineWrap (true );
202+ } else {
203+ // else if wrapping is true then after clicking on menuitem the word wrapping will be disabled
204+ /* Setting word wrapping to false */
205+ textArea .setLineWrap (false );
206+ }
207+ }
208+ });
232209
233210 // Copy Text
234211 copy = new JMenuItem (new DefaultEditorKit .CopyAction ());
@@ -334,16 +311,9 @@ public void actionPerformed (ActionEvent e) {
334311
335312 // If the source was the "new" file option
336313 else if (e .getSource () == newFile || e .getSource () == newButton ) {
337- FEdit .clear (textArea );
338-
314+ FEdit .clear (textArea );
339315 }
340-
341-
342-
343-
344-
345-
346-
316+
347317 // If the source was the "open" option
348318 else if (e .getSource () == openFile || e .getSource () == openButton ) {
349319 JFileChooser open = new JFileChooser (); // open up a file chooser (a dialog for the user to browse files to open)
@@ -472,5 +442,4 @@ public void actionPerformed(ActionEvent e) {
472442 textArea .selectAll ();
473443 }
474444 }
475-
476445}
0 commit comments