I'll start off by showing my full code:
Main class
import javax.swing.JFrame; public class groupingTest { public static void main (String[] args) { groupWindow test = new groupWindow(); test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); test.setBounds(400, 400, 500, 100); test.setVisible(true); } }
Window class
import java.awt.FlowLayout; import javax.swing.JFrame; import javax.swing.ButtonGroup; import javax.swing.JCheckBox; import java.awt.Font; import java.awt.event.ItemListener; import java.awt.event.ItemEvent; import javax.swing.JLabel; public class groupWindow extends JFrame { private JLabel testText = new JLabel ("Some writing for test"); private JCheckBox plain; private JCheckBox bold; private JCheckBox italic; private JCheckBox bolditalic; private Font myFont; public groupWindow() { super("GUI Grouping Test"); setLayout(new FlowLayout()); // set our default font to plain testText.setFont(new Font("Serin", Font.PLAIN, 15)); // make our check boxes plain = new JCheckBox("plain", true); bold = new JCheckBox("bold", false); italic = new JCheckBox("italic", false); bolditalic = new JCheckBox("bolditalic", false); // add the check boxes to the main window add(testText); add(plain); add(bold); add(italic); add(bolditalic); // add our check boxes to a group so only one can be selected ButtonGroup groupFontAttrib = new ButtonGroup(); groupFontAttrib.add(plain); groupFontAttrib.add(bold); groupFontAttrib.add(italic); groupFontAttrib.add(bolditalic); // add a listener to our check boxes handler listener = new handler(); plain.addItemListener(listener); bold.addItemListener(listener); italic.addItemListener(listener); bolditalic.addItemListener(listener); } // create our listener class public class handler implements ItemListener { public void itemStateChanged(ItemEvent e) { // check what box is selected if (bolditalic.isSelected()) myFont = new Font("Serin", Font.BOLD + Font.ITALIC, 15); else if (bold.isSelected()) myFont = new Font("Serin", Font.BOLD, 15); else if (italic.isSelected()) myFont = new Font("Serin", Font.ITALIC, 15); else myFont = new Font("Serin", Font.PLAIN, 15); // change our label font now testText.setFont(myFont); } } }
At the start of the groupWindow it turns yellow and it says "The serializable class groupWindow does not declare a static final serialVersionUID field of type long".
I've been following a tutorial and he hasn't had this issue (it does look like I can suppress this warning but it could be useful to learn).
Thank you in advance,
- Nicky
EDIT:
I'm using Eclipse IDE.