36
36
import java .util .Scanner ;
37
37
import javax .swing .text .DefaultEditorKit ;
38
38
39
- public class UI extends JFrame implements ActionListener
40
- {
41
-
42
-
39
+ public class UI extends JFrame implements ActionListener {
43
40
private static final long serialVersionUID = 1L ;
44
41
private final Container container ;
45
42
private final JTextArea textArea ;
@@ -94,10 +91,9 @@ public UI() {
94
91
textArea .setTabSize (2 );
95
92
textArea .setFont (new Font ("Century Gothic" , Font .BOLD , 12 ));
96
93
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 );
101
97
102
98
// This is why we didn't have to worry about the size of the TextArea!
103
99
getContentPane ().setLayout (new BorderLayout ()); // the BorderLayout bit makes it fill it automatically
@@ -153,15 +149,15 @@ public UI() {
153
149
/*
154
150
* Along with our "CTRL+F4" shortcut to close the window, we also have
155
151
* 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:
157
153
* 1) the default close operation (example, Alt+F4 on Windows)
158
154
* 2) CTRL+F4, which we are
159
155
* about to define now: (this one will appear in the label).
160
156
*/
161
157
close .setAccelerator (KeyStroke .getKeyStroke (KeyEvent .VK_Q , InputEvent .CTRL_MASK ));
162
158
close .addActionListener (this );
163
159
menuFile .add (close );
164
-
160
+
165
161
// Select All Text
166
162
selectAll = new JMenuItem (selectAllAction );
167
163
selectAll .setText ("Select All" );
@@ -182,53 +178,34 @@ public UI() {
182
178
cut .setToolTipText ("Cut" );
183
179
cut .setAccelerator (KeyStroke .getKeyStroke (KeyEvent .VK_X , InputEvent .CTRL_MASK ));
184
180
menuEdit .add (cut );
185
-
186
- //WordWrap
187
-
181
+
182
+ // WordWrap
188
183
wordWrap = new JMenuItem ();
189
- wordWrap .setText ("Word Wrap" );
184
+ wordWrap .setText ("Word Wrap" );
190
185
wordWrap .setIcon (wordwrapIcon );
191
186
wordWrap .setToolTipText ("Word Wrap" );
192
-
193
- //Short cut key or key stroke
187
+
188
+ //Short cut key or key stroke
194
189
wordWrap .setAccelerator (KeyStroke .getKeyStroke (KeyEvent .VK_W , InputEvent .CTRL_MASK ));
195
190
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
+ });
232
209
233
210
// Copy Text
234
211
copy = new JMenuItem (new DefaultEditorKit .CopyAction ());
@@ -334,16 +311,9 @@ public void actionPerformed (ActionEvent e) {
334
311
335
312
// If the source was the "new" file option
336
313
else if (e .getSource () == newFile || e .getSource () == newButton ) {
337
- FEdit .clear (textArea );
338
-
314
+ FEdit .clear (textArea );
339
315
}
340
-
341
-
342
-
343
-
344
-
345
-
346
-
316
+
347
317
// If the source was the "open" option
348
318
else if (e .getSource () == openFile || e .getSource () == openButton ) {
349
319
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) {
472
442
textArea .selectAll ();
473
443
}
474
444
}
475
-
476
445
}
0 commit comments