Search code examples
javaswingbooleanjcheckbox

CheckBox in java code


i can't seem to determine what my code is missing.. please help.. i want to create a check box on my code but i can't get it right.. this is from another frame, it's not my main program..

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Start extends JFrame implements ItemListener
{
    JLabel num1 = new JLabel("1) Is Internet Explorer a web browser?");
    JCheckBox true = new JCheckBox("True", false);
    JCheckBox false = new JCheckBox("False", false);
    String output, insChosen;

    public Start()
    {
        setBounds(100,100,500,400);
        setResizable(false);
        num1.setFont(new Font("Arial", Font.ITALIC,12));
        add(num1);
        true.addItemListener(this);
        false.addItemListener(this);
        add(true);
        add(false);
    }

    public void itemStateChanged(ItemEvent check)
    {
    }
}

Solution

  • true and false is Java keyword. You can't use keyword as identifier. Please follow the Java identifier naming convention. For example:

    JCheckBox trueCheck = new JCheckBox("True", false);
    JCheckBox falseCheck = new JCheckBox("False", false);