Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

CIS-210-2017-M5-Wk4D2 Aclobe Connect Events Index Filter Events Slide Changes Ch

ID: 3869042 • Letter: C

Question

CIS-210-2017-M5-Wk4D2 Aclobe Connect Events Index Filter Events Slide Changes Chat Messeg.. Camera 1 import javax . swing. * ; 2import java awt.* | import Java. art. event. 4import java awt.Colar: public class JCarlysCatering xtends ustame implement, lten Listener, ActionListener Sharing lo-0o.00) Container con getContent Pane: GridLayout mainGrid new GridLayout aridlayout grido-new Gridlayaut(i, 2 GridLayout gridi n new GridLayout (1, 3, 12, 12) Gridlayaut( 13 JPancl introPanlnw JPancl JPanal promptPanal-new JHanel) JPancl boxcsPanclnew JPancl al entre PanalJanal 15 JPanel 51dc Panni new JPanel(), Jeanel dessertPana1 = new Jeana 1(); JPanel endFanel = near JPanel(), 17 21 nabel guest51.abe1 = new Jt.abel ("Please enter number of guests"}, JCheckBox chickenBox new JCheckBox ("Chickan", fal e), JChackBox EishBoxne CheckBox("ish", false) JCheckRox pastaRax = nAW JCheckBox {"Fasta", fal R}, 2.7 28 JChackBox potBox eu JCheckBox("Bakad potato", tals) TCheckRox breadRoxnaw TChackBoxI Garlic bread", fala kBox nieBoxnev JCheckBox"Apple nifalae) 0:48:022:37:35 9:14 PM Type here to search 7/272017

Explanation / Answer

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

public class JCarlysCatering extends JFrame

{

JButton btnOK;

ButtonOKListener btnOKListener;

JFrame Frame1 = new JFrame("Test Frame");

JPanel j1 = new JPanel (new FlowLayout());

JTextField t1 = new JTextField(20);

Label headerLabel = new Label();

Label statusLabel = new Label();

public static void main(String[] args)

{

JCarlysCatering event = new JCarlysCatering();

event.showCheckBoxGroupDemo();

  

}

public JCarlysCatering()

{

super(); //sets the title!

btnOK = new JButton("OK");

j1.add(t1);

j1.add(btnOK);

btnOKListener = new ButtonOKListener();

Frame1.add(j1);

btnOK.addActionListener(btnOKListener);

Frame1.setLayout(new FlowLayout());

Frame1.setSize(400,150);

Frame1.setVisible(true);

Frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

private void showCheckBoxGroupDemo()

{

headerLabel.setText("Control in action: CheckBoxGroup");

CheckboxGroup fruitGroup = new CheckboxGroup();

Checkbox chkApple = new Checkbox("Apple",fruitGroup,true);

Checkbox chkMango = new Checkbox("Mango",fruitGroup,false);

Checkbox chkPeer = new Checkbox("Peer",fruitGroup,false);

statusLabel.setText("Apple Checkbox: checked");

chkApple.addItemListener(new ItemListener() {

public void itemStateChanged(ItemEvent e) {   

statusLabel.setText("Apple Checkbox: checked");

}

});

chkMango.addItemListener(new ItemListener() {

public void itemStateChanged(ItemEvent e) {

statusLabel.setText("Mango Checkbox: checked");

}

});

chkPeer.addItemListener(new ItemListener() {

public void itemStateChanged(ItemEvent e) {

statusLabel.setText("Peer Checkbox: checked");

}

});

j1.add(chkApple);

j1.add(chkMango);

j1.add(chkPeer);

}

}

class ButtonOKListener implements ActionListener

{

public void actionPerformed(ActionEvent arg0)

{

JOptionPane.showInputDialog("$35");

// TODO Auto-generated method stub

try

{

//int num1 = Integer.parseInt(t1.getText());

}

catch (NumberFormatException e)

{

//default title and icon

JOptionPane.showInputDialog(/*Frame1,*/"Eggs are not supposed to be green.");

}   

}

}