Quite a few things to fix here. Remember that Java is CASE SENSITIVE! Many of your errors is because you had a lowercase "s" when you should have had an uppercase "S". You also had an extra "d" when there is no d in the method name.
You also forgot data types on your variables and you don't add the variables to the GUI, you add the checkbox controls to the GUI.
java
/*
Purpose: Create a program that allows user to select from to Jbutton groups
thie first allows the to pick from 4 housing models, the second allows them
to pick the number of car in a garage IF GARAGE IS ADDED THEN IT IS 7775 PER CAR. Display aprorpriate results in a Jtext.
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JMyNewHome extends JFrame implements ItemListener
{
// Make sure you specify data type for your variables.
final int ASPEN = 100000;
final int BRITTANY = 120000;
final int COLONIAL = 180000;
final int DARTMOOR = 250000;
int[] GARAGE_NUMBER = {0,1,2,3};
int Garage = 7775;
int totalPrice;
// Checkbox declarations. Sets prices for the models.//
JCheckBox aspenBox = new JCheckBox("Aspen $" + ASPEN, false);
JCheckBox brittanyBox = new JCheckBox("Brittany $" + BRITTANY, true);
JCheckBox colonialBox = new JCheckBox("Colonial $" + COLONIAL, false);
JCheckBox dartmoorBox = new JCheckBox(" Dartmoor $" + DARTMOOR, false);
// JLabel select garage functions.//
JLabel garageLabel = new JLabel("Garage: Pick from here");
String[] numGarage = {"None " + GARAGE_NUMBER[0],
"1-Car " + GARAGE_NUMBER[1],
"2-Car " + GARAGE_NUMBER[2],
"3-Car " + GARAGE_NUMBER[3]};
JComboBox garageBox = new JComboBox(numGarage);
Container con;
JPanel panel = new JPanel();
JLabel priceLabel = new JLabel();
JTextField totPrice = new JTextField(10);
JTextField message = new JTextField(30);
JLabel optionLabel = new JLabel("Pricing based on current Market.");
public JMyNewHome()
{
super("Homes Pricing");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ButtonGroup houseGroup = new ButtonGroup();
// Add checkboxes to our button group
houseGroup.add(aspenBox);
houseGroup.add(brittanyBox);
houseGroup.add(colonialBox);
houseGroup.add(dartmoorBox);
// Add buttons, not the values, to the panel.
panel.add(aspenBox);
panel.add(brittanyBox);
panel.add(colonialBox);
panel.add(dartmoorBox);
panel.add(garageLabel);
panel.add(priceLabel);
panel.add(totPrice);
panel.add(message);
totPrice.setText("$" + totalPrice);
// Remember, Java is case sensitive! It is addItemListener, not additemlistener
aspenBox.addItemListener(this);
brittanyBox.addItemListener(this);
colonialBox.addItemListener(this);
dartmoorBox.addItemListener(this);
garageBox.addItemListener(this);
// No need for getContentPane, just add it to the frame.
add(panel);
}
public static void main(String[] args)
{
final int WIDTH = 400;
final int HEIGHT = 250;
JMyNewHome aFrame = new JMyNewHome();
aFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);
aFrame.setSize(WIDTH, HEIGHT);
aFrame.setVisible(true);
}
public void itemStateChanged(ItemEvent event)
{
// getSource has a capital "S"
Object source = event.getSource();
// getStateChange, not getStateChanged
int select = event.getStateChange();
if(source == aspenBox)
if(select == ItemEvent.SELECTED)
message.setText("Action: Aspen selected");
else
message.setText("Action: Apsen deslected");
else if(source == garageBox)
{
// Capital "S" in getSelectedIndex
int numGarage = garageBox.getSelectedIndex();
}
}
}
Read through the extra comments I put in. They will explain to you were your errors are and how they were fixed. And in the future, explain the problem rather than just throwing your code out there.
We are brilliant people, but we are not here to be your compilers.
Thanks! Enjoy!
"At DIC we be aspenBox and garageBox adding code ninjas... maybe we should become a garageBox band too!"
This post has been edited by Martyr2: 21 May, 2009 - 06:26 PM