OK, I need some help with this. I
have done something wrong here
and I have no idea how to fix it. I
am confused aoout the total price
of the whole thing and how to go
about coding it. Please take a look and let me what I need change to
get this thing to work... import javax.swing.*;
import java.awt.*;
import java.awt.event.*; public class JInsurance extends
JFrame implements ItemListener
{
int hmoPrice = 200, ppoPrice =
800;
int[] additPrice ={0,20,75}; int basePrice = 0, totalPrice =
basePrice; JCheckBox hmoBox = new
JCheckBox("HMO $" + hmoPrice,
false);
JCheckBox ppoBox = new
JCheckBox("PPO $" + ppoPrice,
false); JLabel additLabel = new JLabel
("Additional Coverage: Make a
selection");
String[] additNames = {"None $"
+ additPrice[0], "Vision $" +
additPrice[1], "Dental $" + additPrice[2]};
JComboBox additBox = new
JComboBox(additNames); JLabel insOptionsLabel = new
JLabel("Insurance Options:");
JTextField totPrice = new
JTextField(10);
JTextField message = new
JTextField(30); JLabel optionExplainLabel =
new JLabel("Base price for
insurance with HMO $" + basePrice
+ ".");
JLabel optionExplainLabel2 =
new JLabel("Optionally, you can choose HMO or PPO only"); public JInsurance()
{
super("Insurance Price
Estimator");
setDefaultCloseOperation
(JFrame.EXIT_ON_CLOSE); JPanel pane = new JPanel();
ButtonGroup insGroup = new
ButtonGroup();
insGroup.add(hmoBox);
insGroup.add(ppoBox);
pane.add(hmoBox); pane.add(ppoBox);
pane.add(additLabel);
pane.add(additBox);
pane.add(insOptionsLabel);
pane.add
(optionExplainLabel); pane.add
(optionExplainLabel2);
pane.add(totPrice);
pane.add(message);
totPrice.setText("$" +
totalPrice); hmoBox.addItemListener
(this);
ppoBox.addItemListener
(this);
additBox.addItemListener
(this); setContentPane(pane);
}
public static void main(String[]
args)
{
JFrame aFrame = new JInsurance();
aFrame.setSize(400,250);
aFrame.setVisible(true);
}
public void itemStateChanged
(ItemEvent event) {
Object source =
event.getSource();
int select =
event.getStateChange(); if(source == additBox)
{
int addNum =
additBox.getSelectedIndex();
addPrice = additPrice
[addNum]; message.setText("Action:
Insurance options changed $" +
addPrice + " added");
}
else
message.setText("Action: Insurance type changed");
totalPrice = basePrice
+additPrice;
if(ppoBox.isSelected())
totalPrice +=
ppoPrice; else if
(fishBox.isSelected())
totalPrice +=
fishPrice; }
}