School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Welcome to Dream.In.Code
Become an Expert!

Join 340,103 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 4,749 people online right now. Registration is fast and FREE... Join Now!



Swing Components

Swing Components My Compiles aren't working ... Don't know where to start to fi Rate Topic: -----

#1 lprice292  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 11
  • Joined: 07-March 09


Dream Kudos: 0

Post icon  Posted 21 May 2009 - 05:33 PM

/*
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
 {
	  
	
	
 	 final  ASPEN = 100000;
	 final BRITTANY = 120000;
	 final  COLONIAL = 180000; 
	 final  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);
	con = getContentPanel();
	con.add(panel);
	ButtonGroup houseGroup = new ButtonGroup();
	houseGroup.add(ASPEN);
	houseGroup.add(BRITTANY);
	houseGroup.add(COLONIAL);
	houseGroup.add(DARTMOOR);
	panel.add(ASPEN);
	panel.add(BRITTANY);
	panel.add(COLONIAL);
	panel.add(DARTMOOR);
	panel.add(garageLabel);
	panel.add(priceLabel);
	panel.add(totPrice);
	panel.add(message);
	totPrice.setText("$" + totalPrice);
	aspenBox.additemlistener(this);
	brittanyBox.additemlistener(this);
	colonialBox.additemlistener(this);
	dartmoorBox.additemlistener(this);
	garageBox.additemlistener(this);
	}
	
public static void main(String[] args)
	{
		final int WIDTH = 400;
		final int HEIGHT = 250;
		JMyNewHome aFrame = new
			JMyNewHome();
		aFrame.setSize(WIDTH, HEIGHT);
		aFrame.setVisible(true);
		}
		public void itemStateChanged(ItemEvent event)
		{
			Object source = event.getsource();
			int select = event.getStateChanged();
			if(source == aspenBox)
				if(select == ItemEvent.SELECTED)
					message.setText("Action: Aspen selected");
				else
					message.setText("Action: Apsen deslected");
				else if(source == garageBox)
				{
					int numGarage = garageBox.getselectedIndex();
					
		}
	
	}
	
}


Was This Post Helpful? 0
  • +
  • -


#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • Icon
  • View blog
  • Group: Mentors
  • Posts: 7,676
  • Joined: 18-April 07


Dream Kudos: 0

Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

Posted 21 May 2009 - 06:25 PM

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.

/*
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!" :snap:

This post has been edited by Martyr2: 21 May 2009 - 06:26 PM

Was This Post Helpful? 1
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month