I have a GUI with a bold and italic JCheckBox as well as a textarea. The layout of my GUI is fine but the functionality of my JCheckBox items are buggy. They are supposed to convert any text in the textarea to bold, italic or both depending on which boxes are ticked. I have managed to make it so that the text is changed to bold when the bold button is ticked initially, but when I deselect it it remains bold, the same goes for my italic button. Here is the implementation for the action listener for my bold button, my italic button uses the same ideas:
class Bold implements ActionListener {
private final FontSetter fontSetter;
private final JTextArea textarea;
private final Font font;
private final Font font1;
JCheckBox bold = new JCheckBox("Bold");
Bold(FontSetter fontSetter, JTextArea textarea) {
this.fontSetter = fontSetter;
this.textarea = textarea;
this.font = new Font(textarea.getText(), Font.BOLD, 12);
this.font1 = new Font(textarea.getText(), Font.PLAIN, 12);
}
public void actionPerformed(ActionEvent e) {
if (bold.isSelected() == false) {
fontSetter.setBold();
textarea.setFont(font);
}
else {
textarea.setFont(font1);
}
}
}
I also have no clue how to check if both the boxes are checked in order to make the text both bold and italic, as oppose to just one or the other, so any suggestions on how I could do this would be appreciated, thanks