user3360927
user3360927

Reputation: 35

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)
    {
    }
}

Upvotes: 1

Views: 941

Answers (1)

Masudul
Masudul

Reputation: 21961

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);

Upvotes: 5

Related Questions