-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextMaster.java
More file actions
731 lines (623 loc) · 19.3 KB
/
TextMaster.java
File metadata and controls
731 lines (623 loc) · 19.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
//THE IMPORTED LIBRARIES
import javax.swing.*;
import javax.swing.undo.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.util.*;
import javax.swing.text.*;
import java.text.*;
public class TextMaster extends JFrame implements ActionListener
{
public static TextMaster e;
//DECLARATION OF ALL THE VARIABLES USED IN THIS APPLICATION
JTextArea text = new JTextArea(0,0);
JScrollPane scroll = new JScrollPane(text);
JMenuBar mb=new JMenuBar();
JMenu FILE = new JMenu("File");
JMenu EDIT = new JMenu("Edit");
JMenu SEARCH = new JMenu("Search");
JMenu HELP = new JMenu("Help");
JMenuItem NEWFILE = new JMenuItem("New");
JMenuItem OPENFILE = new JMenuItem("Open...");
JMenuItem SAVEFILE = new JMenuItem("Save");
JMenuItem SAVEASFILE = new JMenuItem("Save As...");
JMenuItem EXITFILE = new JMenuItem("Exit");
JMenuItem CUTEDIT = new JMenuItem("Cut");
JMenuItem COPYEDIT = new JMenuItem("Copy");
JMenuItem PASTEDIT = new JMenuItem("Paste");
JMenuItem DELETEDIT = new JMenuItem("Delete");
JMenuItem SELECTEDIT = new JMenuItem("Select All");
JMenuItem TIMEDIT = new JMenuItem("Time/Date");
JCheckBoxMenuItem WORDEDIT = new JCheckBoxMenuItem("Word Wrap");
JMenuItem FONTEDIT = new JMenuItem("Set Font...");
JMenuItem FINDSEARCH = new JMenuItem("Find");
JMenuItem FINDNEXTSEARCH = new JMenuItem("Find Next");
JMenuItem ABOUTHELP = new JMenuItem("About");
JPopupMenu POPUP = new JPopupMenu();
JMenuItem CUTPOPUP = new JMenuItem("Cut");
JMenuItem COPYPOPUP = new JMenuItem("Copy");
JMenuItem PASTEPOPUP = new JMenuItem("Paste");
JMenuItem DELETEPOPUP = new JMenuItem("Delete");
JMenuItem SELECTPOPUP = new JMenuItem("Select All");
UndoManager undo = new UndoManager();
UndoAction undoAction = new UndoAction();
boolean opened = false;
String wholeText,findString,filename = null;
int ind = 0;
//CLASS FOR HANDLING UNDO MENU OPTION OF EDIT AND POPUP MENU
class UndoAction extends AbstractAction
{
public UndoAction()
{
super("Undo");
}
public void actionPerformed(ActionEvent e)
{
try
{
undo.undo();
}
catch (CannotUndoException ex)
{
System.out.println("Unable to undo: " + ex);
ex.printStackTrace();
}
update();
}
protected void update()
{
if(undo.canUndo())
{
setEnabled(true);
putValue("Undo", undo.getUndoPresentationName());
}
else
{
setEnabled(false);
putValue(Action.NAME, "Undo");
}
}
}
//DEFAULT CONSTRUCTOR OF THE TextMaster CLASS
public TextMaster()
{
//SETING DEFAULT TITLE OF THE FRAME
setTitle("Untitled");
//SETTING DEFAULT SIZE OF THE FRAME
setSize(600,400);
//MAKING THE FRAME VISIBLE
setVisible(true);
//SETTING WORD WRAP TO TRUE AS DEFAULT
text.setLineWrap(true);
//SETTING THE DEFAULT STATE OF WORDWRAP MENU OPTION IN EDIT MENU
WORDEDIT.setState(true);
//SETTING THE LAYOUT OF THE FRAME
getContentPane().setLayout(new BorderLayout());
//ADDS THE SCROLLPANE CONTAINING THE TEXTAREA TO THE CONTAINER
getContentPane().add(scroll, BorderLayout.CENTER);
//ADDING THE MAIN MENUBAR TO THE FRAME
setJMenuBar(mb);
//ADDING MENUS TO THE MAIN MENUBAR
mb.add(FILE);
mb.add(EDIT);
mb.add(SEARCH);
mb.add(HELP);
//ADDING MENUITEMS TO THE FILE MENU
FILE.add(NEWFILE);
FILE.add(OPENFILE);
FILE.add(SAVEFILE);
FILE.add(SAVEASFILE);
FILE.addSeparator();
FILE.add(EXITFILE);
//ADDING MENUITEMS TO THE EDIT MENU
EDIT.add(undoAction);
EDIT.add(CUTEDIT);
EDIT.add(COPYEDIT);
EDIT.add(PASTEDIT);
EDIT.add(DELETEDIT);
EDIT.addSeparator();
EDIT.add(SELECTEDIT);
EDIT.add(TIMEDIT);
EDIT.addSeparator();
EDIT.add(WORDEDIT);
EDIT.add(FONTEDIT);
//ADDING MENUITEMS TO THE SEARCH MENU
SEARCH.add(FINDSEARCH);
SEARCH.add(FINDNEXTSEARCH);
//ADDING MENUITEM TO THE HELP MENU
HELP.add(ABOUTHELP);
//ADDING MENUITEMS TO THE POPUPMENU
POPUP.add(undoAction);
POPUP.addSeparator();
POPUP.add(CUTPOPUP);
POPUP.add(COPYPOPUP);
POPUP.add(PASTEPOPUP);
POPUP.add(DELETEPOPUP);
POPUP.addSeparator();
POPUP.add(SELECTPOPUP);
//SETTING SHORTCUT KEYS OF MENUS IN THE MAIN MENUBAR
FILE.setMnemonic(KeyEvent.VK_F);
EDIT.setMnemonic(KeyEvent.VK_E);
SEARCH.setMnemonic(KeyEvent.VK_S);
HELP.setMnemonic(KeyEvent.VK_H);
//SETTING SHORTCUT KEYS OF MENUITEMS IN THE FILE MENU
NEWFILE.setMnemonic(KeyEvent.VK_N);
OPENFILE.setMnemonic(KeyEvent.VK_O);
SAVEFILE.setMnemonic(KeyEvent.VK_S);
SAVEASFILE.setMnemonic(KeyEvent.VK_A);
EXITFILE.setMnemonic(KeyEvent.VK_X);
//SETTING SHORTCUT KEYS OF MENUITEMS IN THE EDIT MENU
CUTEDIT.setMnemonic(KeyEvent.VK_T);
COPYEDIT.setMnemonic(KeyEvent.VK_C);
PASTEDIT.setMnemonic(KeyEvent.VK_P);
DELETEDIT.setMnemonic(KeyEvent.VK_L);
SELECTEDIT.setMnemonic(KeyEvent.VK_A);
TIMEDIT.setMnemonic(KeyEvent.VK_D);
WORDEDIT.setMnemonic(KeyEvent.VK_W);
FONTEDIT.setMnemonic(KeyEvent.VK_F);
//SETTING SHORTCUT KEYS OF MENUITEMS IN THE SEARCH MENU
FINDSEARCH.setMnemonic(KeyEvent.VK_F);
FINDNEXTSEARCH.setMnemonic(KeyEvent.VK_N);
//SETTING SHORTCUT KEYS OF MENUITEM IN THE HELP MENU
ABOUTHELP.setMnemonic(KeyEvent.VK_A);
//SETTING SHORTCUT KEYS OF MENUITEMS IN THE POPUPMENU
CUTPOPUP.setMnemonic(KeyEvent.VK_T);
COPYPOPUP.setMnemonic(KeyEvent.VK_C);
PASTEPOPUP.setMnemonic(KeyEvent.VK_P);
DELETEPOPUP.setMnemonic(KeyEvent.VK_D);
SELECTPOPUP.setMnemonic(KeyEvent.VK_A);
//SETTING ACCELERATOR KEYS OF SOME MENUITEMS IN THE EDIT MENU
CUTEDIT.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,ActionEvent.CTRL_MASK));
COPYEDIT.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,ActionEvent.CTRL_MASK));
PASTEDIT.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,ActionEvent.CTRL_MASK));
//ADDING LISTENERS TO THE MENUITEMS IN FILE MENU
NEWFILE.addActionListener(this);
OPENFILE.addActionListener(this);
SAVEFILE.addActionListener(this);
SAVEASFILE.addActionListener(this);
EXITFILE.addActionListener(this);
//ADDING LISTENERS TO THE MENUITEMS IN EDIT MENU
text.getDocument().addUndoableEditListener(new UndoListener());
CUTEDIT.addActionListener(this);
COPYEDIT.addActionListener(this);
PASTEDIT.addActionListener(this);
DELETEDIT.addActionListener(this);
SELECTEDIT.addActionListener(this);
TIMEDIT.addActionListener(this);
WORDEDIT.addActionListener(this);
FONTEDIT.addActionListener(this);
//ADDING LISTENERS TO THE MENUITEMS IN SEARCH MENU
FINDSEARCH.addActionListener(this);
FINDNEXTSEARCH.addActionListener(this);
//ADDING LISTENERS TO THE MENUITEM IN HELP MENU
ABOUTHELP.addActionListener(this);
//ADDING LISTENERS TO THE MENUITEMS IN POPUPMENU
CUTPOPUP.addActionListener(this);
COPYPOPUP.addActionListener(this);
PASTEPOPUP.addActionListener(this);
DELETEPOPUP.addActionListener(this);
SELECTPOPUP.addActionListener(this);
//ADDING MOUSELISTENER TO RIGHT CLICK FOR THE POPUPLISTENER
text.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
if (e.isPopupTrigger())
{
POPUP.show(e.getComponent(),e.getX(), e.getY());
}
}
public void mouseReleased(MouseEvent e)
{
if (e.isPopupTrigger())
{
POPUP.show(e.getComponent(),e.getX(), e.getY());
}
}
});
//ADDING WINDOWLISTENER TO HANDLE CLOSE WINDOW EVENT
/* addWindowListener( new WindowAdapter()
{ public void windowClosing(WindowEvent evt)
{
int response = JOptionPane.showConfirmDialog(null, "Do you really want to quit?");
System.out.println("Inside Window Listener");
switch (response)
{
case 0:
{
dispose();
break; }
case 2:
{
//TextMaster x = new TextMaster();
System.out.println("Inside 2");
e=new TextMaster();
e.setVisible(true);
break;}
}
System.out.println("response is :="+response);
}
} ); */
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
exitApln();
}
});
}
//HANDLING ALL EVENTS OF THE TEXT EDITOR
public void actionPerformed(ActionEvent e)
{
//ACTION FOR NEW MENU OPTION OF FILE MENU
if (e.getSource()==NEWFILE)
{
newfile();
}
//ACTION FOR OPEN MENU OPTION OF FILE MENU
if (e.getSource()==OPENFILE)
{
open();
}
//ACTION FOR SAVE MENU OPTION OF FILE MENU
if (e.getSource()==SAVEFILE)
{
save();
}
//ACTION FOR SAVEAS MENU OPTION OF FILE MENU
if (e.getSource()==SAVEASFILE)
{
opened=false;
save();
}
//ACTION FOR EXIT MENU OPTION OF FILE MENU
if (e.getSource()==EXITFILE)
{
exitApln();
}
//ACTION FOR CUT MENU OPTION OF EDIT MENU AND POPUPMENU
if ((e.getSource()==CUTEDIT)||(e.getSource()==CUTPOPUP))
{
text.cut();
}
//ACTION FOR COPY MENU OPTION OF EDIT MENU AND POPUPMENU
if ((e.getSource()==COPYEDIT)||(e.getSource()==COPYPOPUP))
{
text.copy();
}
//ACTION FOR PASTE MENU OPTION OF EDIT MENU AND POPUPMENU
if ((e.getSource()==PASTEDIT)||(e.getSource()==PASTEPOPUP))
{
text.paste();
}
//ACTION FOR DELETE MENU OPTION OF EDIT MENU AND POPUPMENU
if ((e.getSource()==DELETEDIT)||(e.getSource()==DELETEPOPUP))
{
text.replaceSelection(null);
}
//ACTION FOR SELECTALL MENU OPTION OF EDIT MENU AND POPUPMENU
if ((e.getSource()==SELECTEDIT)||(e.getSource()==SELECTPOPUP))
{
text.selectAll();
}
//ACTION FOR TIME/DATE MENU OPTION OF EDIT MENU
if (e.getSource()==TIMEDIT)
{
Date currDate;
String dd;
currDate = new java.util.Date();
dd=currDate.toString();
text.insert(dd,text.getCaretPosition());
}
//ACTION FOR WORD WRAP MENU OPTION OF EDIT MENU
if (e.getSource()==WORDEDIT)
{
if(WORDEDIT.isSelected())
text.setLineWrap(true);
else
text.setLineWrap(false);
}
//ACTION FOR SET FONT MENU OPTION OF EDIT MENU
if (e.getSource()==FONTEDIT)
{
fontDialogBox fontS = new fontDialogBox();
}
//ACTION FOR FIND MENU OPTION OF SEARCH MENU
if (e.getSource()==FINDSEARCH)
{
wholeText=text.getText();
findString =JOptionPane.showInputDialog(null, "Find What", "Find",
JOptionPane.INFORMATION_MESSAGE);
ind = wholeText.indexOf(findString,0);
text.setCaretPosition(ind);
text.setSelectionStart(ind);
text.setSelectionEnd(ind+findString.length());
}
//ACTION FOR FIND NEXT MENU OPTION OF SEARCH MENU
if (e.getSource()==FINDNEXTSEARCH)
{
wholeText= text.getText();
findString = JOptionPane.showInputDialog(null, "Find What","Find Next",
JOptionPane.INFORMATION_MESSAGE);
ind = wholeText.indexOf(findString, text.getCaretPosition());
text.setCaretPosition(ind);
text.setSelectionStart(ind);
text.setSelectionEnd(ind+findString.length());
}
//ACTION FOR ABOUT MENU OPTION OF HELP MENU
if (e.getSource()==ABOUTHELP)
{
JOptionPane.showMessageDialog(null, "TextMaster is a simple Text Editor application built using Java by Debrup Chatterjee.",
"About Editor",
JOptionPane.INFORMATION_MESSAGE);
}
}
//ACTION FOR NEW MENU OPTION OF FILE MENU
public void newfile()
{
if(!text.getText().equals(""))
{
opened=false;
int confirm = JOptionPane.showConfirmDialog(null,
"Text in the Untitled file has changed. \n Do you want to save the changes?",
"New File",
JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.INFORMATION_MESSAGE);
if( confirm == JOptionPane.YES_OPTION )
{
save();
text.setText(null);
}
else if( confirm == JOptionPane.NO_OPTION )
{
text.setText(null);
}
}
}
//ACTION FOR OPEN MENU OPTION OF FILE MENU
public void open()
{
text.setText(null);
JFileChooser ch = new JFileChooser();
ch.setCurrentDirectory(new File("."));
ch.setFileFilter(new javax.swing.filechooser.FileFilter()
{
public boolean accept(File f)
{
return f.isDirectory()
|| f.getName().toLowerCase().endsWith(".java");
}
public String getDescription()
{
return "Java files";
}
});
int result = ch.showOpenDialog(new JPanel());
if(result == JFileChooser.APPROVE_OPTION)
{
filename = String.valueOf(ch.getSelectedFile());
setTitle(filename);
opened=true;
FileReader fr;
BufferedReader br;
try
{
fr=new FileReader (filename);
br=new BufferedReader(fr);
String s;
while((s=br.readLine())!=null)
{
text.append(s);
text.append("\n");
}
fr.close();
}
catch(FileNotFoundException ex)
{
JOptionPane.showMessageDialog(this, "Requested file not found", "Error Dialog box", JOptionPane.ERROR_MESSAGE);}
catch(Exception ex)
{System.out.println(ex);}
}
}
//ACTION FOR SAVE MENU OPTION OF FILE MENU
public void save()
{
if(opened==true)
{
try
{
FileWriter f1 = new FileWriter(filename);
f1.write(text.getText());
f1.close();
opened = true;
}
catch(FileNotFoundException ex)
{
JOptionPane.showMessageDialog(this, "Requested file not found", "Error Dialog box", JOptionPane.ERROR_MESSAGE);}
catch(IOException ioe){ioe.printStackTrace();}
}
else
{
JFileChooser fc = new JFileChooser();
fc.setCurrentDirectory(new File("."));
int result = fc.showSaveDialog(new JPanel());
if(result == JFileChooser.APPROVE_OPTION)
{
filename = String.valueOf(fc.getSelectedFile());
setTitle(filename);
try
{
FileWriter f1 = new FileWriter(filename);
f1.write(text.getText());
f1.close();
opened = true;
}
catch(FileNotFoundException ex)
{
JOptionPane.showMessageDialog(this, "Requested file not found", "Error Dialog box", JOptionPane.ERROR_MESSAGE);}
catch(IOException ioe){ioe.printStackTrace();}
}
}
}
//ACTION FOR EXIT MENU OPTION OF FILE MENU AND CLOSE WINDOW BUTTON
public void exitApln()
{
if(!text.getText().equals(""))
{
int confirm = JOptionPane.showConfirmDialog(null,
"Text in the file has changed. \n Do you want to save the changes?",
"Exit",
JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.INFORMATION_MESSAGE);
if( confirm == JOptionPane.YES_OPTION )
{
save();
dispose();
System.exit(0);
}
else if( confirm == JOptionPane.CANCEL_OPTION )
{
e=new TextMaster();
String s= text.getText();
e.setVisible(true);
e.text.setText(s);
}
else if( confirm == JOptionPane.NO_OPTION )
{
dispose();
System.exit(0);
}
}
else
{
System.exit(0);
}
}
//CLASS FOR UNDOLISTENER
class UndoListener implements UndoableEditListener
{
public void undoableEditHappened(UndoableEditEvent e)
{
undo.addEdit(e.getEdit());
undoAction.update();
}
}
//CLASS FOR BUILDING AND DISPLAYING FONT DIALOG BOX
class fontDialogBox extends JFrame implements ActionListener
{
//DECLARATION OF ALL VARIABLES USED IN fontDialogBox CLASS
String availableFontString[] = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
JList fontList = new JList(availableFontString);
JLabel fontLabel = new JLabel("Font");
JTextField valueFont=new JTextField("Arial");
JScrollPane fontPane = new JScrollPane(fontList);
String fontStyleString[] = {"Normal","Bold","Italic","Bold Italic"};
JList styleList = new JList(fontStyleString);
JLabel styleLabel = new JLabel("Style");
int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane stylePane = new JScrollPane(styleList,v,h);
JTextField valueStyle=new JTextField("Normal");
String fontSizeString[] = {"8","10","12","14","16","18","20","22","24","28"};
JList sizeList = new JList(fontSizeString);
JLabel sizeLabel = new JLabel("Font size");
JScrollPane sizePane = new JScrollPane(sizeList);
JTextField valueSize=new JTextField("12");
JButton okButton = new JButton("OK");
JButton cancelButton = new JButton("Cancel");
JLabel sampleLabel = new JLabel("Sample:");
JTextField sample = new JTextField(" AaBbCc");
Font selectedFont;
//DEFAULT CONSTRUCTOR OF fontDialogBox CLASS
public fontDialogBox()
{
setSize(500,300);
setTitle("Font");
setVisible(true);
sample.setEditable(false);
getContentPane().setLayout(null);
fontLabel.setBounds(10,10,170,20);
valueFont.setBounds(10,35,170,20);
fontPane.setBounds(10,60,170,150);
styleLabel.setBounds(200,10,100,20);
valueStyle.setBounds(200,35,100,20);
stylePane.setBounds(200,60,100,150);
sizeLabel.setBounds(320,10,50,20);
valueSize.setBounds(320,35,50,20);
sizePane.setBounds(320,60,50,150);
okButton.setBounds(400,35,80,20);
cancelButton.setBounds(400,60,80,20);
sampleLabel.setBounds(150,235,50,30);
sample.setBounds(200,235,100,30);
getContentPane().add(fontLabel);
getContentPane().add(fontPane);
getContentPane().add(valueFont);
getContentPane().add(styleLabel);
getContentPane().add(stylePane);
getContentPane().add(valueStyle);
getContentPane().add(sizeLabel);
getContentPane().add(sizePane);
getContentPane().add(valueSize);
getContentPane().add(okButton);
getContentPane().add(cancelButton);
getContentPane().add(sampleLabel);
getContentPane().add(sample);
okButton.addActionListener(this);
cancelButton.addActionListener(this);
fontList.addListSelectionListener(new ListSelectionListener()
{
public void valueChanged(ListSelectionEvent event)
{
if (!event.getValueIsAdjusting())
{
valueFont.setText(fontList.getSelectedValue().toString());
selectedFont = new Font(valueFont.getText(),styleList.getSelectedIndex(),Integer.parseInt(valueSize.getText()));
sample.setFont(selectedFont);
}
}
});
styleList.addListSelectionListener(new ListSelectionListener()
{
public void valueChanged(ListSelectionEvent event)
{
if (!event.getValueIsAdjusting())
{
valueStyle.setText(styleList.getSelectedValue().toString());
selectedFont = new Font(valueFont.getText(),styleList.getSelectedIndex(),Integer.parseInt(valueSize.getText()));
sample.setFont(selectedFont);
}
}
});
sizeList.addListSelectionListener(new ListSelectionListener()
{
public void valueChanged(ListSelectionEvent event)
{
if (!event.getValueIsAdjusting())
{
valueSize.setText(sizeList.getSelectedValue().toString());
selectedFont = new Font(valueFont.getText(),styleList.getSelectedIndex(),Integer.parseInt(valueSize.getText()));
sample.setFont(selectedFont);
}
}
});
}//END OF DEFAULT CONSTRUCTOR OF fontdialogBox CLASS
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==okButton)
{
selectedFont = new Font(valueFont.getText(),styleList.getSelectedIndex(),Integer.parseInt(valueSize.getText()));
text.setFont(selectedFont);
setVisible(false);
}
if(ae.getSource()==cancelButton)
{
setVisible(false);
}
}
}// END OF fontDialogBox CLASS
//MAIN FUNCTION OF TextMaster CLASS
public static void main(String args[])
{
e= new TextMaster();
}
}//END OF TextMaster CLASS