import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class DormRoomApp extends JFrame{ private JTextArea textArea; public DormRoomApp(){ setTitle("Dorm Room Options"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(400, 300); setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS)); JCheckBox privateRoomCheckBox = new JCheckBox("Private Room"); JCheckBox internetCheckBox = new JCheckBox("Internet Connection"); JCheckBox cableTvCheckBox = new JCheckBox("Cable TV Connection"); JCheckBox microWaveCheckBox = new JCheckBox("Microwave"); JCheckBox refCheckBox = new JCheckBox("Refrigerator"); textArea = new JTextArea(); textArea.setEditable(false); add(privateRoomCheckBox); add(internetCheckBox); add(cableTvCheckBox); add(microWaveCheckBox); add(refCheckBox); add(new JScrollPane(textArea)); privateRoomCheckBox.addActionListener(new CheckBoxListener("Private Room")); internetCheckBox.addActionListener(new CheckBoxListener("Internet Connection")); cableTvCheckBox.addActionListener(new CheckBoxListener("Cable TV Connection")); microWaveCheckBox.addActionListener(new CheckBoxListener("Microwave")); refCheckBox.addActionListener(new CheckBoxListener("Refrigerator")); setVisible(true); } private class CheckBoxListener implements ActionListener{ private String option; public CheckBoxListener(String option){ this.option=option; } public void actionPerformed(ActionEvent e){ JCheckBox source = (JCheckBox) e.getSource(); if(source.isSelected()){ textArea.append(option + " selected.\n"); } else{ textArea.append(option + " delected.\n"); } } } public static void main(String[] args){ new DormRoomApp(); } } import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class PizzaOrderApp extends JFrame{ private JComboBox sizeComboBox; private JCheckBox[] toppingsCheckBoxes; private JLabel totalPriceLabel; private JCheckBox cheeseCheckBox; public PizzaOrderApp(){ setTitle("Pizza Order Apps"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(400, 300); setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS)); Font timesNewRomanFont = new Font("Times New Roman", Font.PLAIN, 14); sizeComboBox = new JComboBox<>(new String[]{"Small", "Medium", "Large", "Extra Large"}); sizeComboBox.setFont(timesNewRomanFont); toppingsCheckBoxes = new JCheckBox[]{ new JCheckBox("Pepperoni"), new JCheckBox("Mushrooms"), new JCheckBox("Onions"), new JCheckBox("Bell Peppers"), new JCheckBox("Olives") }; for(JCheckBox checkBox : toppingsCheckBoxes){ checkBox.setFont(timesNewRomanFont); } cheeseCheckBox = new JCheckBox("Cheese"); cheeseCheckBox.setFont(timesNewRomanFont); totalPriceLabel = new JLabel("Total Price: Php 0"); totalPriceLabel.setFont(timesNewRomanFont); add(new JLabel("Select Pizza Size:")); add(sizeComboBox); add(new JLabel("Select Toppings:")); for(JCheckBox checkBox : toppingsCheckBoxes){ add(sizeComboBox); } add(cheeseCheckBox); add(totalPriceLabel); sizeComboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e){ calculateTotalPrice(); } }); for(JCheckBox checkBox : toppingsCheckBoxes){ checkBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e){ calculateTotalPrice(); } }); } checkBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e){ calculateTotalPrice(); } }); } public void calculateTotalPrice(){ int basePrice = 0; switch(sizeComboBox.getSelectedIndex()){ case 0: basePrice = 300; break; case 1: basePrice = 400; break; case 2: basePrice = 500; break; case 3: basePrice =600; break; } } private class CheckBoxListener implements ActionListener{ private String option; public CheckBoxListener(String option){ this.option=option; } public void actionPerformed(ActionEvent e){ JCheckBox source = (JCheckBox) e.getSource(); if(source.isSelected()){ textArea.append(option + " selected.\n"); } else{ textArea.append(option + " delected.\n"); } } } public static void main(String[] args){ new DormRoomApp(); } }