Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8644875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:24:25+00:00 2026-06-12T12:24:25+00:00

Basically what this simple program does is display the summary when you click on

  • 0

Basically what this simple program does is
display the summary when you click on the button,
There are three radio buttons for the pizza sizes, and three checkboxes for the toppings.
The problem I’m having is when the user first click on a topping, then after clicking the button and displaying the appropriate summary in a MessageDialog, when the users wants to have no toppings, it won’t display the “No Toppings Selected”

import java.applet.Applet;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.*;
import javax.swing.*;

public class PizzaOrdering extends Applet implements ActionListener, ItemListener {

    Button btnOk = new Button("OK");
    CheckboxGroup cbgSize = new CheckboxGroup();
    Checkbox chkSmall = new Checkbox("Small", cbgSize, false);
    Checkbox chkMedium = new Checkbox("Medium", cbgSize, false);
    Checkbox chkLarge = new Checkbox("Large", cbgSize, false);
    Checkbox chkPep = new Checkbox("Pepperoni");
    Checkbox chkMush = new Checkbox("Mushroom");
    Checkbox chkAnch = new Checkbox("Anchiovies");
    String pizza = "";
    String topping1 = "";
    String topping2 = "";
    String topping3 = "";
    String others = "with no toppings";
    Label lbl1 = new Label("Size");
    Label lbl2 = new Label("Toppings");
    Label spacer = new Label("                                                ");
    Label spacer2 = new Label("                                                ");

    @Override
    public void init() {
        resize(250, 150);
        add(lbl1);
        add(spacer);
        add(chkSmall);
        add(chkMedium);
        add(chkLarge);
        add(lbl2);
        add(spacer2);
        add(chkPep);
        add(chkMush);
        add(chkAnch);
        add(btnOk);
        chkAnch.addItemListener(this);
        chkPep.addItemListener(this);
        chkMush.addItemListener(this);
        btnOk.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == btnOk) {
            if (cbgSize.getSelectedCheckbox() == chkSmall) {
                pizza = "Small";
            }
            if (cbgSize.getSelectedCheckbox() == chkMedium) {
                pizza = "Medium";
            }
            if (cbgSize.getSelectedCheckbox() == chkLarge) {
                pizza = "Large";
            }
            JOptionPane.showMessageDialog(btnOk, "You ordered a " + 
                    pizza + " pizza " + others, "Your Order", WIDTH);
        }
    }

    @Override
    public void itemStateChanged(ItemEvent ex) {
        boolean state1 = false;
        boolean state2 = false;
        boolean state3 = false;
        if (ex.getItemSelectable() == chkMush) {
            state1 = chkMush.getState();
            if (state1 == true) {
                topping1 = "Mushroom";
            } else if (state1 == false) {
                topping1 = "";
                if (state2 == false && state3 == false) {
                    others = "with no toppings";
                }
            }
        }

        if (ex.getItemSelectable() == chkPep) {
            state2 = chkPep.getState();
            if (state2 == true) {
                topping2 = "Pepperoni";
            } else if (state2 == false) {
                topping2 = "";
                if (state1 == false && state3 == false) {
                    others = "with no toppings";
                }
            }
        }

        if (ex.getItemSelectable() == chkAnch) {
            state3 = chkAnch.getState();
            if (state3 == true) {
                topping3 = "Anchiovies";

            } else if (state3 == false) {
                topping3 = "";
                if (state1 == false && state2 == false) {
                    others = "with no toppings";
                }
            }
        }
        others = " with the following topping:" + 
                topping1 + " " + topping2 + " " + topping3;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T12:24:26+00:00Added an answer on June 12, 2026 at 12:24 pm

    The itemStateChanged method is not even called when the user does not check or uncheck any of the checkboxes. So put the “No topping selected” label visible by default and hide or remove it in the itemStatechanged method whenever some topping has been selected. You can use a static int field ‘count’ in your itemStateChanged method and increment it on every topping selected and decrement on every topping deselected.

    In this way, for every deselection, decrease count by one and check count, if it is zero, just set that label with “no topping selected” visible or reappear.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just want to design this very simple website. Basically there are multiple pages
I have a simple script that does some search and replace. This is basically
Basically my question is the exact same one as this: Simple client/server, TCP/IP encrypting
I basically have three tables, posts, images and postimages (this simply contains the ids
There must be a simple solution to this, but after 4 hours of browsing
I basically have a simple problem in my program that I just want to
Basically, Im just trying out a very simple collision test for another program Im
I am sure there is a simple answer to this, but my google-fu fails
Basically this is a question how to access local scope handler. I trying to
So basically this code: class A { }; class B { B (const B&

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.