JCheckBox checkbox = new JCheckBox("Enable feature A"); checkbox.setActionCommand("featureA");
JCheckBox checkbox = new JCheckBox("Enable feature B"); checkbox.setActionCommand("featureB"); checkbox.addActionListener(e -> { if (checkbox.isSelected()) { System.out.println("Feature B enabled."); } else { System.out.println("Feature B disabled."); } });In this example, a checkbox component is created with a label "Enable feature B". The setActionCommand method is used to set the action command string as "featureB". An action listener is added to the checkbox component, which checks if the checkbox is selected or not and prints a message accordingly. The javax.swing package library is used to create GUI components in Java.