Question: Explain how this program works. You should be able to explain the purpose of every line of code. / * 1 * / import java.awt.

Explain how this program works. You should be able to explain the purpose of every line of code.
/*1*/ import java.awt.*; /*2*/ import java.awt.event.*; /*3*/ import javax.swing.*; /*4*/ public class Review_Problem_2 implements ActionListener {
/*5*//*6*//*7*//*8*//*9*//*10*//*11*//*12*//*13*//*14*//*15*//*16*//*17*//*18*//*19*//*20*//*21*//*22*//*23*//*24*//*25*//*26*//*27*//*28*//*29*//*30*//*31*//*32*//*33*//*34*//*35*/}
private boolean checked = false; public Review_Problem_2(){
final JFrame jf = new JFrame("Review Problem 2"); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jf.setLayout(new FlowLayout()); final JButton jb1= new JButton("Hello");
final JButton jb2= new JButton("GoodBy"); final JCheckBox cb1= new JCheckBox("Confuse Them"); jf.add(jb1); jf.add(jb2); jf.add(cb1); jf.setLocationRelativeTo(null); jf.setSize(400,400); jf.setVisible(true); cb1.addActionListener(this); jb1.addActionListener(new ActionHandler()); jb2.addActionListener(new ActionListener(){
@Override public void actionPerformed(ActionEvent e){ System.out.println(!checked ? "Goodbye" : "Hello?");
}}); }
@Override public void actionPerformed(ActionEvent e){ checked =! checked;
} class ActionHandler implements ActionListener {
@Override public void actionPerformed(ActionEvent e){ System.out.println(!checked ? "Hello" : "Goodbye?");
}}
public static void main(String[] args){ new Review_Problem_2();

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!