Skip to content

Commit c35fb4b

Browse files
committed
strikethrough works
1 parent 6237bc2 commit c35fb4b

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

src/simplejavatexteditor/UI.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
import java.util.Scanner;
6060
import javax.swing.text.DefaultEditorKit;
6161
import javax.swing.text.StyledEditorKit;
62+
import javax.swing.text.AttributeSet.FontAttribute;
63+
6264
import java.awt.event.*;
6365

6466
public class UI extends JFrame implements ActionListener {
@@ -568,6 +570,7 @@ else if (e.getSource() == boldButton) {
568570
} else {
569571
textArea.setFont(textArea.getFont().deriveFont(Font.BOLD));
570572
}
573+
571574
}// If the source of the event was the "Italic" button
572575
else if (e.getSource() == italicButton) {
573576
if (textArea.getFont().getStyle() == Font.ITALIC) {
@@ -591,18 +594,19 @@ else if(e.getSource() == underlineButton){
591594
//fontAttributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
592595
//Font UNDERLINE = new Font("Centry Gothic", Font.PLAIN, 12).deriveFont(fontAttributes);
593596

594-
//Amshah Mushtaq - strikethrough feature
597+
//Amshah Mushtaq - strikethrough feature
598+
595599
else if (e.getSource() == strikethroughButton){
596-
HashMap<TextAttribute, Integer> fontAttribute = new HashMap<TextAttribute, Integer>();
597-
fontAttribute.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
598-
Font STRIKETHROUGH = new Font("Centry", Font.PLAIN, 12).deriveFont(fontAttribute);
600+
HashMap<TextAttribute, Boolean> fontAttributes = new HashMap<TextAttribute, Boolean>();
601+
fontAttributes.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
602+
Font STRIKETHROUGH = new Font("Centry Gothic", Font.PLAIN, 12).deriveFont(fontAttributes);
599603
if(textArea.getFont().getStyle() == STRIKETHROUGH.getStyle() ){
600-
textArea.setFont(textArea.getFont().deriveFont(Font.PLAIN));
604+
textArea.setFont(textArea.getFont().deriveFont(fontAttributes));
601605
} else {
602606
textArea.setFont(textArea.getFont().deriveFont(STRIKETHROUGH.getStyle()));
603607
}
604-
}///STILL WORKING HERE!!!
605-
608+
}
609+
606610

607611
// Clear File (Code)
608612
if (e.getSource() == clearFile || e.getSource() == clearButton) {

0 commit comments

Comments
 (0)