java - How do I do an action response for when I untick my JCheckBoxes? -
i have gui bold , italic jcheckbox textarea. layout of gui fine functionality of jcheckbox items buggy. supposed convert text in textarea bold, italic or both depending on boxes ticked. have managed make text changed bold when bold button ticked initially, when deselect it remains bold, same goes italic button. here implementation action listener bold button, italic button uses 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 have no clue how check if both boxes checked in order make text both bold , italic, oppose 1 or other, suggestions on how appreciated, thanks
don't have direct experience have font bold , italic, need setup font constructor follows: new font("", font.bold|font.italic, 12). action performed logic off. need reference both checkboxes in class
private jcheckbox _cbbold; private jcheckbox _cbitalic; public void actionperformed(actionevent e) { int fontstyle = (_cbbold.isselected ? font.bold : 0) | (_cbitalic.isselected ? font.italic : 0); font f = new font("text area text", fontstyle, 12); //set font on textarea }
Comments
Post a Comment