import javax.swing.*: import java.awt.* import java.awt.event. public class Game
ID: 3694487 • Letter: I
Question
import javax.swing.*: import java.awt.* import java.awt.event. public class Game extends JFrame ( private JCheckBox cl, c2, c3; private int valuel, value2, value3; private Container contents publlic Game 0 super("Play this game); contents - getContentPane0: contents.setLayout(new FlowLayoutO): cl new JCheckBox("Choice 1"); e2 = new JCheckBox("Choice 2"); c3 new JCheckBox("Choice 3") contents.add(cl); contents.add(c2); contents.add (c3); My Handler mh = new My Handler(); cl.addltemListener(mh); c2.addltemListener(mh) c3.addltemListener(mh); setSize(400, 400); setVisible(true); private class MyHandler implements ItemListener public void itemStateChanged(ltemEvent ie) if (ie.getSource0cl) ( if (ie.getStateChange ItemEvent.SELECTED) value1 = 1; valuel 0; if (ie.getStateChange) else else if (ie.getSource) c2) ItemEvent.SELECTED) value2 2 value2 = 0; else if (ie.getSource) value3 5; value3 0; else c3) t if (ie.getStateChange) ItemEvent.SELECTED) elseExplanation / Answer
a)There are 3 check boxes in all.
b)The three checkboxes are for
checkbox1=>choice1
chechbox2=>choice2
checkbox3=>choice3
c)when use clicks choice 3,It checks if the checkbox is selected or not,If it is selected then value3 will be assigned to 5 .If it is not then value3 will be assigned to 0.value 1 and value 2 are 0.total will be 5+0+0=5
d)when the user checks choice 1,then the checkbox will be selected and value1 will be assigned to 1 and then when the user checks choice 3 then value3 will be 5.total =5+1=6
e)when user checks choice 1 first then value 1 will be 1,when the user checks choice 2,value 2 will be 2,then when the user checks choice 3,the value 3 will be 5.
as a result the output will be 1+2+5=>8 (the sum of all 3 values)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.