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

  • SEARCH
  • Home
  • 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 6939155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:35:08+00:00 2026-05-27T12:35:08+00:00

I am to stimulate a java applet of a menu with checkboxes and checkboxgroups,

  • 0

I am to stimulate a java applet of a menu with checkboxes and checkboxgroups, with calories listed next to each food choice. My problem is I cannot figure out why I keep getting this error message when i compile it:

AnAppletWithCheckboxes.java:188: illegal forward reference
int crepeVal = Integer.parseInt(textField.getText());

I get that for every line that I have is converting the textField into an int, so hence there are 17 errors. Any idea of why will be appreciated!

Here is my Code:: it is very long because there are plenty checkboxes and textFields. I commented Out My place of Error! :

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class AnAppletWithCheckboxes extends Applet implements ItemListener {
    public void init() {
        setLayout(new GridLayout(1, 0));

    CheckboxGroup dinnerType = new CheckboxGroup();
    standard = new Checkbox("standard", dinnerType, false);
    standard.addItemListener(this);
    deluxe = new Checkbox("deluxe", dinnerType, true);
    deluxe.addItemListener(this);   

    CheckboxGroup appetizers = new CheckboxGroup();
    crepe = new Checkbox("crepe", appetizers, false);
    crepe.addItemListener(this);
    quiche = new Checkbox("quiche", appetizers, false);
    quiche.addItemListener(this);
    dumpling = new Checkbox("dumpling", appetizers, false);
    dumpling.addItemListener(this);

textField = new TextField("300");
    textField.setEditable(false);
textField2 = new TextField("330");
    textField2.setEditable(false);
textField3 = new TextField("98");
    textField3.setEditable(false);

    CheckboxGroup soupOrSalad = new CheckboxGroup();

    soup = new Checkbox("Soup", soupOrSalad, false);
    soup.addItemListener(this);

    CheckboxGroup soups = new CheckboxGroup();
    cream = new Checkbox("cream", soups, false);
    cream.addItemListener(this);
    broth = new Checkbox("broth", soups, false);
    broth.addItemListener(this);
    gumbo = new Checkbox("gumbo", soups, false);
    gumbo.addItemListener(this);

textField4 = new TextField("190");
    textField4.setEditable(false);
textField5 = new TextField("20");
    textField5.setEditable(false);
textField6 = new TextField("110");
    textField6.setEditable(false);

    salad = new Checkbox("Salad", soupOrSalad, false);
    salad.addItemListener(this);

    CheckboxGroup salads = new CheckboxGroup();
    tossed = new Checkbox("tossed", salads, false);
    tossed.addItemListener(this);
    caesar = new Checkbox("caesar", salads, false);
    caesar.addItemListener(this);
    croutons = new Checkbox("croutons");
    croutons.addItemListener(this);
    lite = new Checkbox("lite dressing");
    lite.addItemListener(this);

textField7 = new TextField("35");
    textField7.setEditable(false);
textField8 = new TextField("90");
    textField8.setEditable(false);
textField9 = new TextField("60");
    textField9.setEditable(false);
textField10 = new TextField("50");
    textField10.setEditable(false);

    CheckboxGroup entrees = new CheckboxGroup();
    chicken = new Checkbox("chicken", entrees, false);
    chicken.addItemListener(this);
    beef = new Checkbox("beef", entrees, false);
    beef.addItemListener(this);
    lamb = new Checkbox("lamb", entrees, false);
    lamb.addItemListener(this);
    fish = new Checkbox("fish", entrees, false);
    fish.addItemListener(this);

textField11 = new TextField("200");
    textField11.setEditable(false);
textField12 = new TextField("170");
    textField12.setEditable(false);
textField13 = new TextField("65");
    textField13.setEditable(false);
textField14 = new TextField("150");
    textField14.setEditable(false);

    CheckboxGroup deserts = new CheckboxGroup();
    pie = new Checkbox("pie", deserts, false);
    pie.addItemListener(this);
    fruit = new Checkbox("fruit", deserts, false);
    fruit.addItemListener(this);
    sherbet = new Checkbox("sherbet", deserts, false);
    sherbet.addItemListener(this);

textField15 = new TextField("80");
    textField15.setEditable(false);
textField16 = new TextField("60");
    textField16.setEditable(false);
textField17 = new TextField("107");
    textField17.setEditable(false);

calories = new Button("Calories");

calTextField = new TextField("0"+total);
    calTextField.setEditable(false);

    setLayout(new GridLayout(0, 1));

    Panel p = new Panel();
    add(p);
    p.add(standard);
    p.add(deluxe);

    appetizerPanel = new Panel();
    add(appetizerPanel);
label = new Label("Appetizer");
    appetizerPanel.add(label);
    appetizerPanel.add(crepe);
appetizerPanel.add(textField);
    appetizerPanel.add(quiche);
appetizerPanel.add(textField2);
    appetizerPanel.add(dumpling);
appetizerPanel.add(textField3);

    soupPanel = new Panel();
    add(soupPanel);
    soupPanel.add(soup);
    soupPanel.add(cream);
soupPanel.add(textField4);
    soupPanel.add(broth);
soupPanel.add(textField5);
    soupPanel.add(gumbo);
soupPanel.add(textField6);

    saladPanel = new Panel();
    add(saladPanel);
    saladPanel.add(salad);
    saladPanel.add(tossed);
saladPanel.add(textField7);
    saladPanel.add(caesar);
saladPanel.add(textField8);
    saladPanel.add(croutons);
saladPanel.add(textField9);
    saladPanel.add(lite);
saladPanel.add(textField10);

    entreePanel = new Panel();
    add(entreePanel);
label2 = new Label("Entree");
    entreePanel.add(label2);
    entreePanel.add(chicken);
entreePanel.add(textField11);
    entreePanel.add(beef);
entreePanel.add(textField12);
    entreePanel.add(lamb);
entreePanel.add(textField13);
    entreePanel.add(fish);
entreePanel.add(textField14);

desertPanel = new Panel();
    add(desertPanel);
label3 = new Label("Desert");
    desertPanel.add(label3);
    desertPanel.add(pie);
desertPanel.add(textField15);
    desertPanel.add(fruit);
desertPanel.add(textField16);
    desertPanel.add(sherbet);
desertPanel.add(textField17);

caloriesPanel = new Panel();
add(caloriesPanel);
caloriesPanel.add(calories);
caloriesPanel.add(calTextField);
}    

public void LabelChange(Label b) { 
if (b ==label3)
    b.setForeground(Color.lightGray);
else
    label3.setForeground(Color.black);
}

/* This is where i get those errors!! */

int crepeVal = Integer.parseInt(textField.getText());
int quicheVal = Integer.parseInt(textField2.getText());
int dumplingVal = Integer.parseInt(textField3.getText());
int creamVal = Integer.parseInt(textField4.getText());
int brothVal = Integer.parseInt(textField5.getText());
int gumboVal = Integer.parseInt(textField6.getText());
int tossedVal = Integer.parseInt(textField7.getText());
int caesarVal = Integer.parseInt(textField8.getText());
int croutonsVal = Integer.parseInt(textField9.getText());
int liteVal = Integer.parseInt(textField10.getText());
int chickenVal = Integer.parseInt(textField11.getText());
int beefVal = Integer.parseInt(textField12.getText());
int lambVal = Integer.parseInt(textField13.getText());
int fishVal = Integer.parseInt(textField14.getText());
int pieVal = Integer.parseInt(textField15.getText());
int fruitVal = Integer.parseInt(textField16.getText());
int sherbetVal = Integer.parseInt(textField17.getText());

public boolean action(Event evt, Object whatAction){
if(!(evt.target instanceof Button)){
    return false;
} 
else {
    calorieCount();
    return true;
}    
}

public void calorieCount () {
if (crepe.getState()) 
    crepeVal += total;
else
    crepeVal = 0;
if (quiche.getState()) 
    quicheVal += total;
else
    quicheVal = 0;
if (dumpling.getState()) 
    dumplingVal += total;
else
    dumplingVal= 0;
if (cream.getState()) 
    creamVal += total;
else
    creamVal = 0;
if (broth.getState()) 
    brothVal += total;
else
    brothVal = 0;
if (gumbo.getState()) 
    gumboVal += total;
else
    gumboVal = 0;
if (tossed.getState()) 
    tossedVal += total;
else
    tossedVal = 0;
if (caesar.getState()) 
    caesarVal += total;
else
    caesarVal = 0;
if (croutons.getState()) 
    croutonsVal += total;
else
    croutonsVal = 0;
if (lite.getState()) 
    liteVal += total;
else
    liteVal = 0;
if (chicken.getState()) 
    chickenVal += total;
else
    chickenVal = 0;
if (beef.getState()) 
    beefVal += total;
else
    beefVal = 0;
if (lamb.getState()) 
    lambVal += total;
else
    lambVal = 0;
if (fish.getState()) 
    fishVal += total;
else
    fishVal = 0;
if (pie.getState()) 
    pieVal += total;
else
    pieVal = 0;
if (fruit.getState()) 
    fruitVal += total;
else
    fruitVal = 0;
if (sherbet.getState()) 
    sherbetVal += total;
else
    sherbetVal = 0;  
}

public void itemStateChanged(ItemEvent e) {
    if (e.getSource() == standard || e.getSource() == deluxe)
        handleDinnerType((Checkbox)e.getSource());
    else if (e.getSource() == soup || e.getSource() == salad)
        handleSoupSaladChoice((Checkbox)e.getSource());
}

void handleDinnerType(Checkbox selectedType) {
    boolean enabled;
    if (selectedType == standard){
        enabled = false;
    LabelChange(label3);
}
    else{
        enabled = true;
    LabelChange(label);
}

soup.setEnabled(enabled);
salad.setEnabled(enabled);
    pie.setEnabled(enabled);
    fruit.setEnabled(enabled);
    sherbet.setEnabled(enabled);
    cream.setEnabled(enabled);
    broth.setEnabled(enabled);
    gumbo.setEnabled(enabled);
    tossed.setEnabled(enabled);
    caesar.setEnabled(enabled);
    croutons.setEnabled(enabled);
    lite.setEnabled(enabled);

}

void handleSoupSaladChoice(Checkbox selectedCourse) {
    boolean soupEnabled, saladEnabled;
    if (selectedCourse == soup) {
        soupEnabled = true;
        saladEnabled = false;
    soup.setForeground(Color.BLACK);
        salad.setForeground(Color.lightGray);
    }
    else {
        soupEnabled = false;
        saladEnabled = true;
    soup.setForeground(Color.lightGray);
        salad.setForeground(Color.BLACK);
    }
    cream.setEnabled(soupEnabled);
    broth.setEnabled(soupEnabled);
    gumbo.setEnabled(soupEnabled);

    tossed.setEnabled(saladEnabled);
    caesar.setEnabled(saladEnabled);
    croutons.setEnabled(saladEnabled);
    lite.setEnabled(saladEnabled);
}

Label
label, label2, label3;

Panel
    appetizerPanel, soupPanel, saladPanel, entreePanel, desertPanel, caloriesPanel;

Checkbox
    standard, deluxe,
    soup, salad,
    crepe, quiche, dumpling,
    cream, broth, gumbo,
    tossed, caesar,
    croutons, lite,
    chicken, beef, lamb, fish,
    pie, fruit, sherbet;

Button calories;
int total = 0;

TextField
textField, textField2, textField3,
textField4, textField5, textField6,
textField7, textField8, textField9,
textField10, textField11, textField12, 
textField13, textField14, textField15, 
textField16, textField17, calTextField;

}

  • 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-05-27T12:35:09+00:00Added an answer on May 27, 2026 at 12:35 pm

    In Java, you are not allowed to refer to a field a in an initializer of another field b if b is declared before a in the source code. That is, this is allowed:

    int b = 3;
    int a = b;
    

    but this is not allowed:

    int a = b;
    int b = 3;
    

    By the way, if Java had some magic way of figuring out that textField had to be initialized before crepeVal, you would still get a NullPointerException since textField is null after object construction.

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

Sidebar

Related Questions

I should simulate a p2p protocol (using Java) in which each node initially has
I have a problem regarding running multiple threads executing a pipeline in Java. Say
We have a Java Applet built using AWT. This applet lets you select pictures
I'm writing a Java applet where I should be able to simulate a connection
I need to call a servlet call for an automation of a java applet
I am writing a very basic web spider in java.I am facing one problem,
I have a java concurrency problem, it goes like this: There is a Servlet
I am working on a Java project and need to have a keypress simulate
I was wondering, in java, is it possible to in anyway, simulate pass by
Say I have a GUI Java project of something that simulates an ATM machine,

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.