Skip to content

Commit 7ddd317

Browse files
authored
Added Bold and Italic buttons
1 parent 180f1b6 commit 7ddd317

File tree

1 file changed

+47
-6
lines changed

1 file changed

+47
-6
lines changed

src/simplejavatexteditor/UI.java

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
* @modemail [email protected]
3232
* Removed unuse objects like container, Border emptyBorder
3333
* Removed unsused imports
34+
*
35+
* @Modifiedby Giorgos Pasentsis
36+
* @modemail [email protected]
3437
*/
3538
package simplejavatexteditor;
3639

@@ -55,9 +58,14 @@ public class UI extends JFrame implements ActionListener {
5558
private final JMenuItem newFile, openFile, saveFile, close, cut, copy, paste, clearFile, selectAll, quickFind,
5659
aboutMe, aboutSoftware, wordWrap;
5760
private final JToolBar mainToolbar;
58-
JButton newButton, openButton, saveButton, clearButton, quickButton, aboutMeButton, aboutButton, closeButton;
61+
JButton newButton, openButton, saveButton, clearButton, quickButton, aboutMeButton, aboutButton, closeButton,boldButton,italicButton;
5962
private final Action selectAllAction;
6063

64+
65+
//setup icons - Bold and Italic
66+
private final ImageIcon boldIcon = new ImageIcon("icons/bold.png");
67+
private final ImageIcon italicIcon = new ImageIcon("icons/italic.png");
68+
6169
// setup icons - File Menu
6270
private final ImageIcon newIcon = new ImageIcon("icons/new.png");
6371
private final ImageIcon openIcon = new ImageIcon("icons/open.png");
@@ -88,7 +96,7 @@ public class UI extends JFrame implements ActionListener {
8896
public UI() {
8997

9098
// Set the initial size of the window
91-
setSize(700, 500);
99+
setSize(800, 500);
92100

93101
// Set the title of the window
94102
setTitle("Untitled | " + SimpleJavaTextEditor.NAME);
@@ -101,9 +109,9 @@ public UI() {
101109

102110
// Set a default font for the TextArea
103111
textArea = new JTextArea("", 0, 0);
104-
textArea.setFont(new Font("Century Gothic", Font.BOLD, 12));
112+
textArea.setFont(new Font("Century Gothic", Font.PLAIN, 12));
105113
textArea.setTabSize(2);
106-
textArea.setFont(new Font("Century Gothic", Font.BOLD, 12));
114+
textArea.setFont(new Font("Century Gothic", Font.PLAIN, 12));
107115
textArea.setTabSize(2);
108116

109117
/* SETTING BY DEFAULT WORD WRAP ENABLED OR TRUE */
@@ -311,7 +319,18 @@ public void actionPerformed(ActionEvent ev) {
311319
closeButton.addActionListener(this);
312320
mainToolbar.add(closeButton);
313321
mainToolbar.addSeparator();
314-
322+
323+
boldButton = new JButton(boldIcon);
324+
boldButton.setToolTipText("Bold");
325+
boldButton.addActionListener(this);
326+
mainToolbar.add(boldButton);
327+
mainToolbar.addSeparator();
328+
329+
italicButton = new JButton(italicIcon);
330+
italicButton.setToolTipText("Italic");
331+
italicButton.addActionListener(this);
332+
mainToolbar.add(italicButton);
333+
mainToolbar.addSeparator();
315334
/**
316335
* **************** FONT SETTINGS SECTION **********************
317336
*/
@@ -485,8 +504,30 @@ else if (e.getSource() == openFile || e.getSource() == openButton) {
485504
} // If the source of the event was the "save" option
486505
else if (e.getSource() == saveFile || e.getSource() == saveButton) {
487506
saveFile();
507+
}// If the source of the event was the "Bold" button
508+
else if (e.getSource() == boldButton) {
509+
if(textArea.getFont().getStyle() == Font.BOLD){
510+
textArea.setFont(textArea.getFont().deriveFont(Font.PLAIN));
511+
512+
}
513+
else{
514+
515+
textArea.setFont(textArea.getFont().deriveFont(Font.BOLD));
516+
}
517+
518+
}// If the source of the event was the "Italic" button
519+
else if (e.getSource() == italicButton) {
520+
if(textArea.getFont().getStyle() == Font.ITALIC){
521+
textArea.setFont(textArea.getFont().deriveFont(Font.PLAIN));
522+
523+
}
524+
else{
525+
526+
textArea.setFont(textArea.getFont().deriveFont(Font.ITALIC));
527+
}
528+
488529
}
489-
530+
490531
// Clear File (Code)
491532
if (e.getSource() == clearFile || e.getSource() == clearButton) {
492533

0 commit comments

Comments
 (0)