aspose file tools*
The moose likes Beginning Java and the fly likes calculating totals in an applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "calculating totals in an applet" Watch "calculating totals in an applet" New topic
Author

calculating totals in an applet

jackie white
Greenhorn

Joined: Nov 05, 2003
Posts: 1
I'm new to all this and being the only girl in class, I get so frustrated because I can't get this to work right. All I want to do is use checkbox, say for 5 of them and total them up here is my code can some one help me?
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class PetClinicApplet extends Applet implements ItemListener, ActionListener
{
//Create components for applet
Label companyNameLabel = new Label(" LIONS, TIGERS, AND BEARS ");
Label welcomeLabel = new Label(" Welcome! ");
Label variousServiceLabel = new Label(" Please check services being used. ");
Checkbox officeVisitBox = new Checkbox("Office Visits ");
Checkbox hospitalBox = new Checkbox("Hospitalization ");
Checkbox vaccinBox = new Checkbox( "Vaccinations ");
Checkbox boardBox = new Checkbox("Boarding ");
Checkbox dentistBox = new Checkbox("Denistry ");
Checkbox xrayBox = new Checkbox("X-rays ");
Checkbox labBox = new Checkbox("Laboratory Work ");
Checkbox heartwormPrevBox = new Checkbox("Heartworm Prevention");
Checkbox prescripBox = new Checkbox("Prescriptions ");
Label outputLabel = new Label();
Label outputLabel1 = new Label();
Button calcButton = new Button("Calculate Totals");


public void init()
{
//Add components to window and set colors
setBackground(Color.gray);
setForeground(Color.black);
add(companyNameLabel);
add(welcomeLabel);
add(variousServiceLabel);
add(officeVisitBox);
officeVisitBox.addItemListener(this);
add(hospitalBox);
hospitalBox.addItemListener(this);
add(vaccinBox);
vaccinBox.addItemListener(this);
add(boardBox);
boardBox.addItemListener(this);
add(dentistBox);
dentistBox.addItemListener(this);
add(xrayBox);
xrayBox.addItemListener(this);
add(labBox);
labBox.addItemListener(this);
add(heartwormPrevBox);
heartwormPrevBox.addItemListener(this);
add(prescripBox);
prescripBox.addItemListener(this);
add(calcButton);
calcButton.addActionListener(this);
add(outputLabel);
add(outputLabel1);

//Assigning Values
int officeVisitBox = 35;
int hospitalBox = 75;
int vaccinBox = 25;
int boardBox = 15;
int dentistBox = 25;
int xrayBox = 12;
int labBox = 20;
int heartwormPrevBox = 12;
int prescripBox = 9;

}
public void itemStateChanged(ItemEvent choice)
{

int total;
total =
//Display Output
outputLabel1.setText("The total amount is $" + (total));
outputLabel.setForeground(Color.black);

}
public void actionPerformed(ActionEvent e)
{


}




}
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Jackie,
I would not use a button because the ItemStateChanged should be enough to do it. Here is one way you could make it work.

Regards,
Manfred.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: calculating totals in an applet