Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 3 123 LastLast
Results 1 to 25 of 60

Thread: Beginner help please.

  1. #1
    Member
    Join Date
    Dec 2012
    Posts
    30
    Thanks
    29
    Thanked 0 Times in 0 Posts

    Post Beginner help please.

    Hey, I am a beginner and my teacher assigned us this task :
    Write an application for a construction company to handle a customer's order to build a new home. Use separate ButtonGroups to allow the customer to select one of four models, the number of bedrooms, and a garage type. Assume that the models are the Aspen, $100000; the Brittany, $120000; the Colonial, $180000; or the Dartmoor, $250000. Assume that any model can have two, three, or four bedrooms and that each bedroom adds $10500 to the base price. Assume that garage type can be zero-, one-, two-, or three-car , and that each car adds $7775 to the price.

    I have no idea how to use actionlistener to get the price to add up everytime the user checks a checkbox!!
    can someone please help, it's due tomorrow!!


    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
     
    public class JMyNewHome extends JFrame
    {
     
    	public static void main(String[] arg)
        {
        	JMyNewHome window = new JMyNewHome();
        	window.setVisible(true);
        }
     
    	JCheckBox aspen = new JCheckBox("Aspen-$100,000");
    	JCheckBox brittany = new JCheckBox("Brittany-$120,000");
    	JCheckBox colonial = new JCheckBox("Colonial-$180,00");
    	JCheckBox dartmoor = new JCheckBox("Dartmoor-$250,000");
    	JCheckBox twobed = new JCheckBox("2 Bed-$21,000");
    	JCheckBox threebed = new JCheckBox("3 Bed-$31,500");
    	JCheckBox fourbed = new JCheckBox("4 Bed-$42,000");
    	JCheckBox carzero = new JCheckBox("0 Car-$0");
    	JCheckBox carone = new JCheckBox("1 Car-$7,775");
    	JCheckBox cartwo = new JCheckBox("2 Car-$15,550");
    	JCheckBox carthree = new JCheckBox("3 Car-$23,325");
    	JLabel price = new JLabel("$0.00");
    	Container contentPane = getContentPane();
    /*	final int aspen = 100000;
    	final int brittany = 120000;
    	final int colonial = 180000;
    	final int dartmoor = 250000;
    	final int twobed = 21000;
    	final int threebed = 31500;
    	final int fourbed = 42000;
    	final int carzero = 0;
    	final int carone = 7775;
    	final int cartwo = 15550;
    	final int carthree = 23325;
    	int price = 0;
    */	
        public JMyNewHome()
        {
        	setTitle("My New Home");
            setLayout(new FlowLayout());
            contentPane.add(aspen);
        	contentPane.add(brittany);
        	contentPane.add(colonial);
        	contentPane.add(dartmoor);
        	contentPane.add(twobed);
        	contentPane.add(threebed);
        	contentPane.add(fourbed);
        	contentPane.add(carzero);
        	contentPane.add(carone);
        	contentPane.add(cartwo);
        	contentPane.add(carthree);
        	contentPane.add(price);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setSize(500,150);
            ButtonGroup house = new ButtonGroup();
            house.add(aspen);
            house.add(brittany);
            house.add(colonial);
            house.add(dartmoor);
            ButtonGroup beds = new ButtonGroup();
            beds.add(twobed);
            beds.add(threebed);
            beds.add(fourbed);
            ButtonGroup cars = new ButtonGroup();
            cars.add(carzero);
            cars.add(carone);
            cars.add(cartwo);
            cars.add(carthree);
    		ClickButtonListener clickListener = new ClickButtonListener();
        	aspen.addActionListener(clickListener);
        }
     
    	 public class ClickButtonListener implements ActionListener
    	 {
    	 	public void actionPerformed(ActionEvent e)
        	{
        		if(aspen==ItemEvent.SELECTED)
        		{
        			price.setText("100,000");
        		}
        		else if(brittany==ItemEvent.SELECTED)
        		{
        			price.setText("120,000");
        		}
        	}
    	 }
     
     
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Beginner help please.

    how to use actionlistener to get the price
    Where is the price that you want to get? The actionlistener is passed an object that contains a reference to the component that created the event. Call that object's get source method to get a reference to the component that created the event, cast that reference to the type of the component and then you can call its methods to get the user's selections etc

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    xdorkiee (December 13th, 2012)

  4. #3
    Member
    Join Date
    Dec 2012
    Posts
    30
    Thanks
    29
    Thanked 0 Times in 0 Posts

    Default Re: Beginner help please.

    Quote Originally Posted by Norm View Post
    Where is the price that you want to get? The actionlistener is passed an object that contains a reference to the component that created the event. Call that object's get source method to get a reference to the component that created the event, cast that reference to the type of the component and then you can call its methods to get the user's selections etc

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    well i grouped my jcheckboxes so they can only choose 1 kind of house,beds,and garages.
    so like, the one house they choose, once they click on the jcheckbox of i.e, aspen the price of 100,000 will appear in the jlabel.
    next, i would click the 2 bed button and the price would change to aspen+twobed, i can't even explain.

    This seems like an AP comp sci problem but my teacher gave it to us, beginner comp sci?!

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Beginner help please.

    When the listener method is called, You will get a reference to the check box that was clicked. You can get the price from the text of the check box.
    You don't have to test all of the checkboxes to see which one is currently selected.
    If you don't understand my answer, don't ignore it, ask a question.

  6. The Following User Says Thank You to Norm For This Useful Post:

    xdorkiee (December 13th, 2012)

  7. #5
    Member
    Join Date
    Dec 2012
    Posts
    30
    Thanks
    29
    Thanked 0 Times in 0 Posts

    Default Re: Beginner help please.

    		ClickButtonListener clickListener = new ClickButtonListener();
        	aspen.addActionListener(clickListener);
    brittany.addActionListener(clickListener);
    colonial.addActionListener(clickListener);
    dartmoor.addActionListener(clickListener);
    twobeds.addActionListener(clickListener);

    would i have to do that for every single checkbox?

  8. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Beginner help please.

    Yes, all the checkboxes need listeners.
    If you don't understand my answer, don't ignore it, ask a question.

  9. The Following User Says Thank You to Norm For This Useful Post:

    xdorkiee (December 13th, 2012)

  10. #7
    Member
    Join Date
    Dec 2012
    Posts
    30
    Thanks
    29
    Thanked 0 Times in 0 Posts

    Default Re: Beginner help please.

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
     
    public class JMyNewHome extends JFrame
    {
     
    	public static void main(String[] arg)
        {
        	JMyNewHome window = new JMyNewHome();
        	window.setVisible(true);
        }
     
    	JCheckBox aspen = new JCheckBox("Aspen-$100,000");
    	JCheckBox brittany = new JCheckBox("Brittany-$120,000");
    	JCheckBox colonial = new JCheckBox("Colonial-$180,00");
    	JCheckBox dartmoor = new JCheckBox("Dartmoor-$250,000");
    	JCheckBox twobed = new JCheckBox("2 Bed-$21,000");
    	JCheckBox threebed = new JCheckBox("3 Bed-$31,500");
    	JCheckBox fourbed = new JCheckBox("4 Bed-$42,000");
    	JCheckBox carzero = new JCheckBox("0 Car-$0");
    	JCheckBox carone = new JCheckBox("1 Car-$7,775");
    	JCheckBox cartwo = new JCheckBox("2 Car-$15,550");
    	JCheckBox carthree = new JCheckBox("3 Car-$23,325");
    	JLabel price = new JLabel("$0.00");
    	Container contentPane = getContentPane();
    /*	final int aspen = 100000;
    	final int brittany = 120000;
    	final int colonial = 180000;
    	final int dartmoor = 250000;
    	final int twobed = 21000;
    	final int threebed = 31500;
    	final int fourbed = 42000;
    	final int carzero = 0;
    	final int carone = 7775;
    	final int cartwo = 15550;
    	final int carthree = 23325;
    	int price = 0;
    */	
        public JMyNewHome()
        {
        	setTitle("My New Home");
            setLayout(new FlowLayout());
            contentPane.add(aspen);
        	contentPane.add(brittany);
        	contentPane.add(colonial);
        	contentPane.add(dartmoor);
        	contentPane.add(twobed);
        	contentPane.add(threebed);
        	contentPane.add(fourbed);
        	contentPane.add(carzero);
        	contentPane.add(carone);
        	contentPane.add(cartwo);
        	contentPane.add(carthree);
        	contentPane.add(price);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setSize(500,150);
            ButtonGroup house = new ButtonGroup();
            house.add(aspen);
            house.add(brittany);
            house.add(colonial);
            house.add(dartmoor);
            ButtonGroup beds = new ButtonGroup();
            beds.add(twobed);
            beds.add(threebed);
            beds.add(fourbed);
            ButtonGroup cars = new ButtonGroup();
            cars.add(carzero);
            cars.add(carone);
            cars.add(cartwo);
            cars.add(carthree);
    		ClickButtonListener clickListener = new ClickButtonListener();
        	aspen.addActionListener(clickListener);
        	brittany.addActionListener(clickListener);
        	colonial.addActionListener(clickListener);
        	dartmoor.addActionListener(clickListener);
        	twobed.addActionListener(clickListener);
        	threebed.addActionListener(clickListener);
        	fourbed.addActionListener(clickListener);
        	carzero.addActionListener(clickListener);
        	carone.addActionListener(clickListener);
        	cartwo.addActionListener(clickListener);
        	carthree.addActionListener(clickListener);
        }
     
    	 public class ClickButtonListener implements ActionListener
    	 {
    	 	public void actionPerformed(ActionEvent e)
        	{
        		if(aspen==ItemEvent.SELECTED)
        		{
        			price.setText("100,000");
        		}
        		else if(brittany==ItemEvent.SELECTED)
        		{
        			price.setText("120,000");
        		}
        	}
    	 }
     
     
    }

    ok this is what i have so far.

    i am clueless into how to get the total price of checked items..

    someone told me to use

    public void actionPerformed(ActionEven e) {
     
       Object o = e.getSource();
     
       if(o == aspen) {
     
            if(aspen.isSelected() {
     
                ... increase
     
            }
     
            else {
     
                 ... decrease
     
            }
     
        else if(o == britanny) {
     
            if(brittany.isSelected()) {
     
               ...

    what do the dots/increase/decrease mean?

  11. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Beginner help please.

    how to get the total price of checked item
    Cast o to JCheckBox and you will have a reference to the object that was selected.
    Then you can call that object's methods to get the text shown: "....-$<the amount>"
    Add a call to the println method to show what you have gotten so far.
    Then you can get <the amount> using the String class's sub string method and convert it to a number by using the Integer class's parse method.
    Read the API doc for those classes to see how to use their methods.
    If you don't understand my answer, don't ignore it, ask a question.

  12. The Following User Says Thank You to Norm For This Useful Post:

    xdorkiee (December 13th, 2012)

  13. #9
    Member
    Join Date
    Dec 2012
    Posts
    30
    Thanks
    29
    Thanked 0 Times in 0 Posts

    Default Re: Beginner help please.

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
     
    public class JMyNewHome extends JFrame
    {
     
    	public static void main(String[] arg)
        {
        	JMyNewHome window = new JMyNewHome();
        	window.setVisible(true);
        }
     
    	JCheckBox aspen = new JCheckBox("Aspen-$100,000");
    	JCheckBox brittany = new JCheckBox("Brittany-$120,000");
    	JCheckBox colonial = new JCheckBox("Colonial-$180,00");
    	JCheckBox dartmoor = new JCheckBox("Dartmoor-$250,000");
    	JCheckBox twobed = new JCheckBox("2 Bed-$21,000");
    	JCheckBox threebed = new JCheckBox("3 Bed-$31,500");
    	JCheckBox fourbed = new JCheckBox("4 Bed-$42,000");
    	JCheckBox carzero = new JCheckBox("0 Car-$0");
    	JCheckBox carone = new JCheckBox("1 Car-$7,775");
    	JCheckBox cartwo = new JCheckBox("2 Car-$15,550");
    	JCheckBox carthree = new JCheckBox("3 Car-$23,325");
    	JLabel price = new JLabel("$0.00");w
    	Container contentPane = getContentPane();
    /*	final int aspen = 100000;
    	final int brittany = 120000;
    	final int colonial = 180000;
    	final int dartmoor = 250000;
    	final int twobed = 21000;
    	final int threebed = 31500;
    	final int fourbed = 42000;
    	final int carzero = 0;
    	final int carone = 7775;
    	final int cartwo = 15550;
    	final int carthree = 23325;
    	int price = 0;
    */	
        public JMyNewHome()
        {
        	setTitle("My New Home");
            setLayout(new FlowLayout());
            contentPane.add(aspen);
        	contentPane.add(brittany);
        	contentPane.add(colonial);
        	contentPane.add(dartmoor);
        	contentPane.add(twobed);
        	contentPane.add(threebed);
        	contentPane.add(fourbed);
        	contentPane.add(carzero);
        	contentPane.add(carone);
        	contentPane.add(cartwo);
        	contentPane.add(carthree);
        	contentPane.add(price);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setSize(500,150);
            ButtonGroup house = new ButtonGroup();
            house.add(aspen);
            house.add(brittany);
            house.add(colonial);
            house.add(dartmoor);
            ButtonGroup beds = new ButtonGroup();
            beds.add(twobed);
            beds.add(threebed);
            beds.add(fourbed);
            ButtonGroup cars = new ButtonGroup();
            cars.add(carzero);
            cars.add(carone);
            cars.add(cartwo);
            cars.add(carthree);
    		ClickButtonListener clickListener = new ClickButtonListener();
        	aspen.addActionListener(clickListener);
        	brittany.addActionListener(clickListener);
        	colonial.addActionListener(clickListener);
        	dartmoor.addActionListener(clickListener);
        	twobed.addActionListener(clickListener);
        	threebed.addActionListener(clickListener);
        	fourbed.addActionListener(clickListener);
        	carzero.addActionListener(clickListener);
        	carone.addActionListener(clickListener);
        	cartwo.addActionListener(clickListener);
        	carthree.addActionListener(clickListener);
        }
     
    	 public class ClickButtonListener implements ActionListener
    	 {
    	 	public void actionPerformed(ActionEvent e)
        	{
        		Object o = e.getSource();
        		if(o==aspen)
        		{
        			if(aspen.isSelected()
        			{
     
        			}
        			else
        			{
     
        			}
        			else if(o==brittany)
        			{
        			if(brittany.isSelected()
        			{
     
        			}
        			else
        			{
     
        			}
        			else if(o==colonial)
        			{
        			if(colonial.isSelected()
        			{
     
        			}
        			else
        			{
     
        			}
        			else if(o==dartmoor)
        			{
        			if(dartmoor.isSelected()
        			{
     
        			}
        			else
        			{
     
        			}
        			else if(o==twobed)
        			{
        			if(twobed.isSelected()
        			{
     
        			}
        			else
        			{
     
        			}
        			else if(o==threebed)
        			{
        			if(threebed.isSelected()
        			{
     
        			}
        			else
        			{
     
        			}
        			else if(o==fourbed)
        			{
        			if(fourbed.isSelected()
        			{
     
        			}
        			else
        			{
     
        			}
        			else if(o==carzero)
        			{
        			if(carzero.isSelected()
        			{
     
        			}
        			else
        			{
     
        			}
        			else if(o==carone)
        			{
        			if(carone.isSelected()
        			{
     
        			}
        			else
        			{
     
        			}
        			else if(o==cartwo)
        			{
        			if(cartwo.isSelected()
        			{
     
        			}
        			else
        			{
     
        			}
        			else if(o==cartthree)
        			{
        			if(cartthree.isSelected()
        			{
     
        			}
        			else
        			{
     
        			}
        		}
    	 	}
    	 }
     
    }

    ahh okay, am i headed the right "direction"?

    what would i put if else black spots? the amount string?

  14. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Beginner help please.

    what would i put if else black spots? the amount string?
    Sorry, I don't understand what you are asking.

    I don't think you need all the if/else if statements in the listener method. The ActionEvent method has a reference to the checkbox that was selected. I described above(post#8) how to get the amount from the text on the checkbox.
    If you don't understand my answer, don't ignore it, ask a question.

  15. The Following User Says Thank You to Norm For This Useful Post:

    xdorkiee (December 13th, 2012)

  16. #11
    Member
    Join Date
    Dec 2012
    Posts
    30
    Thanks
    29
    Thanked 0 Times in 0 Posts

    Default Re: Beginner help please.

    Sorry.

    Okay, i've worked on it and I really have no idea what i'm doing.

    I want my output to setText to my grand total.

    here's what i have, i know my curlies are really off at the actionlistener

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
     
    public class JMyNewHome extends JFrame
    {
     
    	public static void main(String[] arg)
        {
        	JMyNewHome window = new JMyNewHome();
        	window.setVisible(true);
        }
     
    	JCheckBox aspen = new JCheckBox("Aspen-$100,000");
    	JCheckBox brittany = new JCheckBox("Brittany-$120,000");
    	JCheckBox colonial = new JCheckBox("Colonial-$180,00");
    	JCheckBox dartmoor = new JCheckBox("Dartmoor-$250,000");
    	JCheckBox twobed = new JCheckBox("2 Bed-$21,000");
    	JCheckBox threebed = new JCheckBox("3 Bed-$31,500");
    	JCheckBox fourbed = new JCheckBox("4 Bed-$42,000");
    	JCheckBox carzero = new JCheckBox("0 Car-$0");
    	JCheckBox carone = new JCheckBox("1 Car-$7,775");
    	JCheckBox cartwo = new JCheckBox("2 Car-$15,550");
    	JCheckBox carthree = new JCheckBox("3 Car-$23,325");
    	JLabel price = new JLabel("$0.00");w
    	Container contentPane = getContentPane();
    /*	final int aspen = 100000;
    	final int brittany = 120000;
    	final int colonial = 180000;
    	final int dartmoor = 250000;
    	final int twobed = 21000;
    	final int threebed = 31500;
    	final int fourbed = 42000;
    	final int carzero = 0;
    	final int carone = 7775;
    	final int cartwo = 15550;
    	final int carthree = 23325;
    	int price = 0;
    */	
        public JMyNewHome()
        {
        	setTitle("My New Home");
            setLayout(new FlowLayout());
            contentPane.add(aspen);
        	contentPane.add(brittany);
        	contentPane.add(colonial);
        	contentPane.add(dartmoor);
        	contentPane.add(twobed);
        	contentPane.add(threebed);
        	contentPane.add(fourbed);
        	contentPane.add(carzero);
        	contentPane.add(carone);
        	contentPane.add(cartwo);
        	contentPane.add(carthree);
        	contentPane.add(price);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setSize(500,150);
            ButtonGroup house = new ButtonGroup();
            house.add(aspen);
            house.add(brittany);
            house.add(colonial);
            house.add(dartmoor);
            ButtonGroup beds = new ButtonGroup();
            beds.add(twobed);
            beds.add(threebed);
            beds.add(fourbed);
            ButtonGroup cars = new ButtonGroup();
            cars.add(carzero);
            cars.add(carone);
            cars.add(cartwo);
            cars.add(carthree);
    		ClickButtonListener clickListener = new ClickButtonListener();
        	aspen.addActionListener(clickListener);
        	brittany.addActionListener(clickListener);
        	colonial.addActionListener(clickListener);
        	dartmoor.addActionListener(clickListener);
        	twobed.addActionListener(clickListener);
        	threebed.addActionListener(clickListener);
        	fourbed.addActionListener(clickListener);
        	carzero.addActionListener(clickListener);
        	carone.addActionListener(clickListener);
        	cartwo.addActionListener(clickListener);
        	carthree.addActionListener(clickListener);
        	price.setText(+hprice+bprice+cprice)
        }
     
    	 public class ClickButtonListener implements ActionListener
    	 {
    	 	public void actionPerformed(ActionEvent e)
        	{
        		Object o = e.getSource();
        		if(o==aspen)
        		{
        			if(aspen.isSelected()
        			{
        			int hprice = 100000	
        			}
        			else if(o==brittany)
        			{
        			if(brittany.isSelected()
        			{
        			int hprice = 120000		
        			}
        			else if(o==colonial)
        			{
        			if(colonial.isSelected()
        			{
        			int hprice = 180000	
        			}
        			else if(o==dartmoor)
        			{
        			if(dartmoor.isSelected()
        			{
        			int hprice = 250000	
        			}
        			else if(o==twobed)
        			{
        			if(twobed.isSelected()
        			{
        			int bprice = 21000	
        			}
        			else if(o==threebed)
        			{
        			if(threebed.isSelected()
        			{
        			int bprice = 31500	
        			}
        			else if(o==fourbed)
        			{
        			if(fourbed.isSelected()
        			{
        			int bprice = 42000	
        			}
        			else if(o==carzero)
        			{
        			if(carzero.isSelected()
        			{
    				int cprice = 0	
        			}
        			else if(o==carone)
        			{
        			if(carone.isSelected()
        			{
        			int cprice = 7775	
        			}
        			else if(o==cartwo)
        			{
        			if(cartwo.isSelected()
        			{
        			int cprice = 15550	
        			}
        			else if(o==cartthree)
        			{
        			if(cartthree.isSelected()
        			{
        			int cprice = 23325	
        			}
        			}
        		}
    	 	}
    	 }
     
    }

  17. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Beginner help please.

    Can you describe in a list of steps what the code in the action listener should do?
    I don't understand the logic that is used there.

    To see what values are set by the java program, add some println statements to the action listener method that print out the value of the variable: o

    I think you can get the amount from the checkbox object and not need all the if/else if statements in the listener method. The technique depends on if the data is in the text of the checkboxes.
    If it is, then you can get it there and not use all the if/else if statements.
    If you don't understand my answer, don't ignore it, ask a question.

  18. The Following User Says Thank You to Norm For This Useful Post:

    xdorkiee (December 13th, 2012)

  19. #13
    Member
    Join Date
    Dec 2012
    Posts
    30
    Thanks
    29
    Thanked 0 Times in 0 Posts

    Default Re: Beginner help please.

    here's how i want it to look like


  20. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Beginner help please.

    Look at the GridLayout layout manager. Put each row of components into a container and add that container to the layout.
    If you don't understand my answer, don't ignore it, ask a question.

  21. The Following User Says Thank You to Norm For This Useful Post:

    xdorkiee (December 13th, 2012)

  22. #15
    Member
    Join Date
    Dec 2012
    Posts
    30
    Thanks
    29
    Thanked 0 Times in 0 Posts

    Default Re: Beginner help please.

    I'm using a flow layout for now.
    The question I'm having soo much trouble on is how do i get the final price to show up?
    Like in the first, it has brittany , 2 bedrooms and no garage selected, and its total price shown.
    While the second has dartmoor 4 bedrooms and 3 cars selects and its a different price..

    Never knew a program would be so depressing.

  23. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Beginner help please.

    how do i get the final price to show up?
    Have a separate variable for the currently selected price for each category.
    When a checkbox is selected update the price for its category, sum the prices for each category and display it.
    If you don't understand my answer, don't ignore it, ask a question.

  24. The Following User Says Thank You to Norm For This Useful Post:

    xdorkiee (December 13th, 2012)

  25. #17
    Member
    Join Date
    Dec 2012
    Posts
    30
    Thanks
    29
    Thanked 0 Times in 0 Posts

    Default Re: Beginner help please.

    Quote Originally Posted by Norm View Post
    Have a separate variable for the currently selected price for each category.
    When a checkbox is selected update the price for its category, sum the prices for each category and display it.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
     
    public class JMyNewHome extends JFrame
    {
     
    	public static void main(String[] arg)
        {
        	JMyNewHome window = new JMyNewHome();
        	window.setVisible(true);
        }
     
    	JCheckBox aspen = new JCheckBox("Aspen-$100,000");
    	JCheckBox brittany = new JCheckBox("Brittany-$120,000");
    	JCheckBox colonial = new JCheckBox("Colonial-$180,00");
    	JCheckBox dartmoor = new JCheckBox("Dartmoor-$250,000");
    	JCheckBox twobed = new JCheckBox("2 Bed-$21,000");
    	JCheckBox threebed = new JCheckBox("3 Bed-$31,500");
    	JCheckBox fourbed = new JCheckBox("4 Bed-$42,000");
    	JCheckBox carzero = new JCheckBox("0 Car-$0");
    	JCheckBox carone = new JCheckBox("1 Car-$7,775");
    	JCheckBox cartwo = new JCheckBox("2 Car-$15,550");
    	JCheckBox carthree = new JCheckBox("3 Car-$23,325");
    	JLabel price = new JLabel("$0.00");w
    	Container contentPane = getContentPane();
    /*	final int aspen = 100000;
    	final int brittany = 120000;
    	final int colonial = 180000;
    	final int dartmoor = 250000;
    	final int twobed = 21000;
    	final int threebed = 31500;
    	final int fourbed = 42000;
    	final int carzero = 0;
    	final int carone = 7775;
    	final int cartwo = 15550;
    	final int carthree = 23325;
    	int price = 0;
    */	
        public JMyNewHome()
        {
        	setTitle("My New Home");
            setLayout(new FlowLayout());
            contentPane.add(aspen);
        	contentPane.add(brittany);
        	contentPane.add(colonial);
        	contentPane.add(dartmoor);
        	contentPane.add(twobed);
        	contentPane.add(threebed);
        	contentPane.add(fourbed);
        	contentPane.add(carzero);
        	contentPane.add(carone);
        	contentPane.add(cartwo);
        	contentPane.add(carthree);
        	contentPane.add(price);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setSize(500,150);
            ButtonGroup house = new ButtonGroup();
            house.add(aspen);
            house.add(brittany);
            house.add(colonial);
            house.add(dartmoor);
            ButtonGroup beds = new ButtonGroup();
            beds.add(twobed);
            beds.add(threebed);
            beds.add(fourbed);
            ButtonGroup cars = new ButtonGroup();
            cars.add(carzero);
            cars.add(carone);
            cars.add(cartwo);
            cars.add(carthree);
    		ClickButtonListener clickListener = new ClickButtonListener();
        	aspen.addActionListener(clickListener);
        	brittany.addActionListener(clickListener);
        	colonial.addActionListener(clickListener);
        	dartmoor.addActionListener(clickListener);
        	twobed.addActionListener(clickListener);
        	threebed.addActionListener(clickListener);
        	fourbed.addActionListener(clickListener);
        	carzero.addActionListener(clickListener);
        	carone.addActionListener(clickListener);
        	cartwo.addActionListener(clickListener);
        	carthree.addActionListener(clickListener);
        	price.setText(+hprice+bprice+cprice)
        }
     
    	 public class ClickButtonListener implements ActionListener
    	 {
    	 	public void actionPerformed(ActionEvent e)
        	{
        		Object o = e.getSource();
        		if(o==aspen)
        		{
        			if(aspen.isSelected()
        			{
        			int hprice = 100000	
        			}
        			else if(o==brittany)
        			{
        			if(brittany.isSelected()
        			{
        			int hprice = 120000		
        			}
        			else if(o==colonial)
        			{
        			if(colonial.isSelected()
        			{
        			int hprice = 180000	
        			}
        			else if(o==dartmoor)
        			{
        			if(dartmoor.isSelected()
        			{
        			int hprice = 250000	
        			}
        			else if(o==twobed)
        			{
        			if(twobed.isSelected()
        			{
        			int bprice = 21000	
        			}
        			else if(o==threebed)
        			{
        			if(threebed.isSelected()
        			{
        			int bprice = 31500	
        			}
        			else if(o==fourbed)
        			{
        			if(fourbed.isSelected()
        			{
        			int bprice = 42000	
        			}
        			else if(o==carzero)
        			{
        			if(carzero.isSelected()
        			{
    				int cprice = 0	
        			}
        			else if(o==carone)
        			{
        			if(carone.isSelected()
        			{
        			int cprice = 7775	
        			}
        			else if(o==cartwo)
        			{
        			if(cartwo.isSelected()
        			{
        			int cprice = 15550	
        			}
        			else if(o==cartthree)
        			{
        			if(cartthree.isSelected()
        			{
        			int cprice = 23325	
        			}
        			}
        		}
    	 	}
    	 }
     
    }

    here i put my variable as hprice , for the house pricing, bprice, for bed pricing, and cprice for car pricing.
    then i put

    price.setText(+hprice+bprice+cprice)

    since my price variable was 0.00 at default cause none was selected.

  26. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Beginner help please.

    You need to set the contents of the textfield AFTER the user has selected a checkbox.
    The posted code calls setText() BEFORE the user has done anything.
    If you don't understand my answer, don't ignore it, ask a question.

  27. The Following User Says Thank You to Norm For This Useful Post:

    xdorkiee (December 13th, 2012)

  28. #19
    Member
    Join Date
    Dec 2012
    Posts
    30
    Thanks
    29
    Thanked 0 Times in 0 Posts

    Default Re: Beginner help please.

    Quote Originally Posted by Norm View Post
    You need to set the contents of the textfield AFTER the user has selected a checkbox.
    The posted code calls setText() BEFORE the user has done anything.
    ok here it is, it looks right BUT I'M STILL GETTING ALOT OF ERRORS ><

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
     
    public class JMyNewHome extends JFrame
    {
     
    	public static void main(String[] arg)
        {
        	JMyNewHome window = new JMyNewHome();
        	window.setVisible(true);
        }
     
    	JCheckBox aspen = new JCheckBox("Aspen-$100,000");
    	JCheckBox brittany = new JCheckBox("Brittany-$120,000");
    	JCheckBox colonial = new JCheckBox("Colonial-$180,00");
    	JCheckBox dartmoor = new JCheckBox("Dartmoor-$250,000");
    	JCheckBox twobed = new JCheckBox("2 Bed-$21,000");
    	JCheckBox threebed = new JCheckBox("3 Bed-$31,500");
    	JCheckBox fourbed = new JCheckBox("4 Bed-$42,000");
    	JCheckBox carzero = new JCheckBox("0 Car-$0");
    	JCheckBox carone = new JCheckBox("1 Car-$7,775");
    	JCheckBox cartwo = new JCheckBox("2 Car-$15,550");
    	JCheckBox carthree = new JCheckBox("3 Car-$23,325");
    	JLabel price = new JLabel("$0.00");w
    	Container contentPane = getContentPane();
    /*	final int aspen = 100000;
    	final int brittany = 120000;
    	final int colonial = 180000;
    	final int dartmoor = 250000;
    	final int twobed = 21000;
    	final int threebed = 31500;
    	final int fourbed = 42000;
    	final int carzero = 0;
    	final int carone = 7775;
    	final int cartwo = 15550;
    	final int carthree = 23325;
    	int price = 0;
    */	
        public JMyNewHome()
        {
        	setTitle("My New Home");
            setLayout(new FlowLayout());
            contentPane.add(aspen);
        	contentPane.add(brittany);
        	contentPane.add(colonial);
        	contentPane.add(dartmoor);
        	contentPane.add(twobed);
        	contentPane.add(threebed);
        	contentPane.add(fourbed);
        	contentPane.add(carzero);
        	contentPane.add(carone);
        	contentPane.add(cartwo);
        	contentPane.add(carthree);
        	contentPane.add(price);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setSize(500,150);
            ButtonGroup house = new ButtonGroup();
            house.add(aspen);
            house.add(brittany);
            house.add(colonial);
            house.add(dartmoor);
            ButtonGroup beds = new ButtonGroup();
            beds.add(twobed);
            beds.add(threebed);
            beds.add(fourbed);
            ButtonGroup cars = new ButtonGroup();
            cars.add(carzero);
            cars.add(carone);
            cars.add(cartwo);
            cars.add(carthree);
    		ClickButtonListener clickListener = new ClickButtonListener();
        	aspen.addActionListener(clickListener);
        	brittany.addActionListener(clickListener);
        	colonial.addActionListener(clickListener);
        	dartmoor.addActionListener(clickListener);
        	twobed.addActionListener(clickListener);
        	threebed.addActionListener(clickListener);
        	fourbed.addActionListener(clickListener);
        	carzero.addActionListener(clickListener);
        	carone.addActionListener(clickListener);
        	cartwo.addActionListener(clickListener);
        	carthree.addActionListener(clickListener);
        }
     
    	 public class ClickButtonListener implements ActionListener
    	 {
    	 	public void actionPerformed(ActionEvent e)
        	{
        		Object o = e.getSource();
        		if(o==aspen)
        		{
        			if(aspen.isSelected()
        			{
        			int hprice = 100000	
        			}
        		}
        		else if(o==brittany)
        		{
        			if(brittany.isSelected()
        			{
        			int hprice = 120000		
        			}
        		}
        		else if(o==colonial)
        		{
        			if(colonial.isSelected()
        			{
        			int hprice = 180000
        			}	
        		}
        		else if(o==dartmoor)
        		{
        			if(dartmoor.isSelected()
        			{
        			int hprice = 250000	
        			}
        		}
        		else if(o==twobed)
        		{
        			if(twobed.isSelected()
        			{
        			int bprice = 21000	
        			}
        		}
        		else if(o==threebed)
        		{
        			if(threebed.isSelected()
        			{
        			int bprice = 31500
        			}	
        		}
        		else if(o==fourbed)
        		{
        			if(fourbed.isSelected();
        			{
        			int bprice = 42000	
        			}
        		}
        		else if(o==carzero)
        		{
        			if(carzero.isSelected()
        			{
    				int cprice = 0
        			}	
        		}
        		else if(o==carone)
        		{
        			if(carone.isSelected()
        			{
        			int cprice = 7775	
        			}
        		}
        		else if(o==cartwo)
        		{
        			if(cartwo.isSelected()
        			{
        			int cprice = 15550	
        			}
        		}
        		else if(o==cartthree)
        		{
        			if(cartthree.isSelected()
        			{
        			int cprice = 23325	
        			}
        		}
        		price.setText(+hprice+bprice+cprice);
    	 	}
    	 }
     
    }

  29. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Beginner help please.

    GETTING ALOT OF ERRORS
    Please copy the full text of the error messages and post them here.
    If you don't understand my answer, don't ignore it, ask a question.

  30. The Following User Says Thank You to Norm For This Useful Post:

    xdorkiee (December 13th, 2012)

  31. #21
    Member
    Join Date
    Dec 2012
    Posts
    30
    Thanks
    29
    Thanked 0 Times in 0 Posts

    Default Re: Beginner help please.

    Quote Originally Posted by Norm View Post
    Please copy the full text of the error messages and post them here.
    --------------------Configuration: <Default>--------------------
    K:\CompSci\Projects\JMyNewHome.java:35: error: ';' expected
    	Container contentPane = getContentPane();
    	         ^
    K:\CompSci\Projects\JMyNewHome.java:35: error: <identifier> expected
    	Container contentPane = getContentPane();
    	                     ^
    K:\CompSci\Projects\JMyNewHome.java:102: error: ')' expected
        			if(aspen.isSelected()
        			                     ^
    K:\CompSci\Projects\JMyNewHome.java:104: error: ';' expected
        			int hprice = 100000	
        			                   ^
    K:\CompSci\Projects\JMyNewHome.java:109: error: ')' expected
        			if(brittany.isSelected()
        			                        ^
    K:\CompSci\Projects\JMyNewHome.java:111: error: ';' expected
        			int hprice = 120000		
        			                   ^
    K:\CompSci\Projects\JMyNewHome.java:116: error: ')' expected
        			if(colonial.isSelected()
        			                        ^
    K:\CompSci\Projects\JMyNewHome.java:118: error: ';' expected
        			int hprice = 180000
        			                   ^
    K:\CompSci\Projects\JMyNewHome.java:123: error: ')' expected
        			if(dartmoor.isSelected()
        			                        ^
    K:\CompSci\Projects\JMyNewHome.java:125: error: ';' expected
        			int hprice = 250000	
        			                   ^
    K:\CompSci\Projects\JMyNewHome.java:130: error: ')' expected
        			if(twobed.isSelected()
        			                      ^
    K:\CompSci\Projects\JMyNewHome.java:132: error: ';' expected
        			int bprice = 21000	
        			                  ^
    K:\CompSci\Projects\JMyNewHome.java:137: error: ')' expected
        			if(threebed.isSelected()
        			                        ^
    K:\CompSci\Projects\JMyNewHome.java:139: error: ';' expected
        			int bprice = 31500
        			                  ^
    K:\CompSci\Projects\JMyNewHome.java:144: error: ')' expected
        			if(fourbed.isSelected();
        			                       ^
    K:\CompSci\Projects\JMyNewHome.java:146: error: ';' expected
        			int bprice = 42000	
        			                  ^
    K:\CompSci\Projects\JMyNewHome.java:151: error: ')' expected
        			if(carzero.isSelected();
        			                       ^
    K:\CompSci\Projects\JMyNewHome.java:153: error: ';' expected
    				int cprice = 0
    				              ^
    K:\CompSci\Projects\JMyNewHome.java:158: error: ')' expected
        			if(carone.isSelected();
        			                      ^
    K:\CompSci\Projects\JMyNewHome.java:160: error: ';' expected
        			int cprice = 7775	
        			                 ^
    K:\CompSci\Projects\JMyNewHome.java:165: error: ')' expected
        			if(cartwo.isSelected();
        			                      ^
    K:\CompSci\Projects\JMyNewHome.java:167: error: ';' expected
        			int cprice = 15550	
        			                  ^
    K:\CompSci\Projects\JMyNewHome.java:172: error: ')' expected
        			if(cartthree.isSelected();
        			                         ^
    K:\CompSci\Projects\JMyNewHome.java:174: error: ';' expected
        			int cprice = 23325	
        			                  ^
    24 errors
     
    Process completed.

  32. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Beginner help please.

    K:\CompSci\Projects\JMyNewHome.java:102: error: ')' expected
        			if(aspen.isSelected()
        			                     ^
    The error message says what is wrong. The compiler wants a ) above the ^
    The same with the message about the ; Add a ; above the ^

    You need to compile more often and correct the errors then. Compile every few lines instead of waiting so long and getting so many errors.
    If you don't understand my answer, don't ignore it, ask a question.

  33. The Following User Says Thank You to Norm For This Useful Post:

    xdorkiee (December 13th, 2012)

  34. #23
    Member
    Join Date
    Dec 2012
    Posts
    30
    Thanks
    29
    Thanked 0 Times in 0 Posts

    Default Re: Beginner help please.

    ahh thanks soo much!!

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
     
    public class JMyNewHome extends JFrame
    {
     
    	public static void main(String[] arg)
        {
        	JMyNewHome window = new JMyNewHome();
        	window.setVisible(true);
        }
     
    	JCheckBox aspen = new JCheckBox("Aspen-$100,000");
    	JCheckBox brittany = new JCheckBox("Brittany-$120,000");
    	JCheckBox colonial = new JCheckBox("Colonial-$180,00");
    	JCheckBox dartmoor = new JCheckBox("Dartmoor-$250,000");
    	JCheckBox twobed = new JCheckBox("2 Bed-$21,000");
    	JCheckBox threebed = new JCheckBox("3 Bed-$31,500");
    	JCheckBox fourbed = new JCheckBox("4 Bed-$42,000");
    	JCheckBox carzero = new JCheckBox("0 Car-$0");
    	JCheckBox carone = new JCheckBox("1 Car-$7,775");
    	JCheckBox cartwo = new JCheckBox("2 Car-$15,550");
    	JCheckBox carthree = new JCheckBox("3 Car-$23,325");
    	JLabel price = new JLabel("$0.00");w
    	Container contentPane = getContentPane();
    /*	final int aspen = 100000;
    	final int brittany = 120000;
    	final int colonial = 180000;
    	final int dartmoor = 250000;
    	final int twobed = 21000;
    	final int threebed = 31500;
    	final int fourbed = 42000;
    	final int carzero = 0;
    	final int carone = 7775;
    	final int cartwo = 15550;
    	final int carthree = 23325;
    	int price = 0;
    */	
        public JMyNewHome()
        {
        	setTitle("My New Home");
            setLayout(new FlowLayout());
            contentPane.add(aspen);
        	contentPane.add(brittany);
        	contentPane.add(colonial);
        	contentPane.add(dartmoor);
        	contentPane.add(twobed);
        	contentPane.add(threebed);
        	contentPane.add(fourbed);
        	contentPane.add(carzero);
        	contentPane.add(carone);
        	contentPane.add(cartwo);
        	contentPane.add(carthree);
        	contentPane.add(price);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setSize(500,150);
            ButtonGroup house = new ButtonGroup();
            house.add(aspen);
            house.add(brittany);
            house.add(colonial);
            house.add(dartmoor);
            ButtonGroup beds = new ButtonGroup();
            beds.add(twobed);
            beds.add(threebed);
            beds.add(fourbed);
            ButtonGroup cars = new ButtonGroup();
            cars.add(carzero);
            cars.add(carone);
            cars.add(cartwo);
            cars.add(carthree);
    		ClickButtonListener clickListener = new ClickButtonListener();
        	aspen.addActionListener(clickListener);
        	brittany.addActionListener(clickListener);
        	colonial.addActionListener(clickListener);
        	dartmoor.addActionListener(clickListener);
        	twobed.addActionListener(clickListener);
        	threebed.addActionListener(clickListener);
        	fourbed.addActionListener(clickListener);
        	carzero.addActionListener(clickListener);
        	carone.addActionListener(clickListener);
        	cartwo.addActionListener(clickListener);
        	carthree.addActionListener(clickListener);
        }
     
    	 public class ClickButtonListener implements ActionListener
    	 {
    	 	public void actionPerformed(ActionEvent e)
        	{
        		Object o = e.getSource();
        		if(o==aspen)
        		{
        			if(aspen.isSelected())
        			{
        			int hprice = 100000;	
        			}
        		}
        		else if(o==brittany)
        		{
        			if(brittany.isSelected())
        			{
        			int hprice = 120000;		
        			}
        		}
        		else if(o==colonial)
        		{
        			if(colonial.isSelected())
        			{
        			int hprice = 180000;
        			}	
        		}
        		else if(o==dartmoor)
        		{
        			if(dartmoor.isSelected())
        			{
        			int hprice = 250000;	
        			}
        		}
        		else if(o==twobed)
        		{
        			if(twobed.isSelected())
        			{
        			int bprice = 21000;	
        			}
        		}
        		else if(o==threebed)
        		{
        			if(threebed.isSelected())
        			{
        			int bprice = 31500;
        			}	
        		}
        		else if(o==fourbed)
        		{
        			if(fourbed.isSelected())
        			{
        			int bprice = 42000;	
        			}
        		}
        		else if(o==carzero)
        		{
        			if(carzero.isSelected())
        			{
    				int cprice = 0;
        			}	
        		}
        		else if(o==carone)
        		{
        			if(carone.isSelected())
        			{
        			int cprice = 7775;	
        			}
        		}
        		else if(o==cartwo)
        		{
        			if(cartwo.isSelected())
        			{
        			int cprice = 15550;	
        			}
        		}
        		else if(o==cartthree)
        		{
        			if(cartthree.isSelected())
        			{
        			int cprice = 23325;	
        			}
        		}
        		price.setText(+hprice+bprice+cprice);
    	 	}
    	 }
     
    }

    alright i have two errors left.

    --------------------Configuration: <Default>--------------------
    K:\CompSci\Projects\JMyNewHome.java:35: error: ';' expected
    	Container contentPane = getContentPane();
    	         ^
    K:\CompSci\Projects\JMyNewHome.java:35: error: <identifier> expected
    	Container contentPane = getContentPane();
    	                     ^
    2 errors
     
    Process completed.

    why is it not completing my container? o.o

  35. #24
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Beginner help please.

    Look at the code before the line with the error.
    If you don't understand my answer, don't ignore it, ask a question.

  36. The Following User Says Thank You to Norm For This Useful Post:

    xdorkiee (December 13th, 2012)

  37. #25
    Member
    Join Date
    Dec 2012
    Posts
    30
    Thanks
    29
    Thanked 0 Times in 0 Posts

    Default Re: Beginner help please.

    wow i can't believe i missed that ><

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
     
    public class JMyNewHome extends JFrame
    {
     
    	public static void main(String[] arg)
        {
        	JMyNewHome window = new JMyNewHome();
        	window.setVisible(true);
        }
     
    	JCheckBox aspen = new JCheckBox("Aspen-$100,000");
    	JCheckBox brittany = new JCheckBox("Brittany-$120,000");
    	JCheckBox colonial = new JCheckBox("Colonial-$180,00");
    	JCheckBox dartmoor = new JCheckBox("Dartmoor-$250,000");
    	JCheckBox twobed = new JCheckBox("2 Bed-$21,000");
    	JCheckBox threebed = new JCheckBox("3 Bed-$31,500");
    	JCheckBox fourbed = new JCheckBox("4 Bed-$42,000");
    	JCheckBox carzero = new JCheckBox("0 Car-$0");
    	JCheckBox carone = new JCheckBox("1 Car-$7,775");
    	JCheckBox cartwo = new JCheckBox("2 Car-$15,550");
    	JCheckBox carthree = new JCheckBox("3 Car-$23,325");
    	JLabel price = new JLabel("$0.00");
    	Container contentPane = getContentPane();
    /*	final int aspen = 100000;
    	final int brittany = 120000;
    	final int colonial = 180000;
    	final int dartmoor = 250000;
    	final int twobed = 21000;
    	final int threebed = 31500;
    	final int fourbed = 42000;
    	final int carzero = 0;
    	final int carone = 7775;
    	final int cartwo = 15550;
    	final int carthree = 23325;
    	int price = 0;
    */	
        public JMyNewHome()
        {
        	setTitle("My New Home");
            setLayout(new FlowLayout());
            contentPane.add(aspen);
        	contentPane.add(brittany);
        	contentPane.add(colonial);
        	contentPane.add(dartmoor);
        	contentPane.add(twobed);
        	contentPane.add(threebed);
        	contentPane.add(fourbed);
        	contentPane.add(carzero);
        	contentPane.add(carone);
        	contentPane.add(cartwo);
        	contentPane.add(carthree);
        	contentPane.add(price);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setSize(500,150);
            ButtonGroup house = new ButtonGroup();
            house.add(aspen);
            house.add(brittany);
            house.add(colonial);
            house.add(dartmoor);
            ButtonGroup beds = new ButtonGroup();
            beds.add(twobed);
            beds.add(threebed);
            beds.add(fourbed);
            ButtonGroup cars = new ButtonGroup();
            cars.add(carzero);
            cars.add(carone);
            cars.add(cartwo);
            cars.add(carthree);
    		ClickButtonListener clickListener = new ClickButtonListener();
        	aspen.addActionListener(clickListener);
        	brittany.addActionListener(clickListener);
        	colonial.addActionListener(clickListener);
        	dartmoor.addActionListener(clickListener);
        	twobed.addActionListener(clickListener);
        	threebed.addActionListener(clickListener);
        	fourbed.addActionListener(clickListener);
        	carzero.addActionListener(clickListener);
        	carone.addActionListener(clickListener);
        	cartwo.addActionListener(clickListener);
        	carthree.addActionListener(clickListener);
        }
     
    	 public class ClickButtonListener implements ActionListener
    	 {
    	 	public void actionPerformed(ActionEvent e)
        	{
        		Object o = e.getSource();
        		if(o==aspen)
        		{
        			if(aspen.isSelected())
        			{
        			int hprice = 100000;	
        			}
        		}
        		else if(o==brittany)
        		{
        			if(brittany.isSelected())
        			{
        			int hprice = 120000;		
        			}
        		}
        		else if(o==colonial)
        		{
        			if(colonial.isSelected())
        			{
        			int hprice = 180000;
        			}	
        		}
        		else if(o==dartmoor)
        		{
        			if(dartmoor.isSelected())
        			{
        			int hprice = 250000;	
        			}
        		}
        		else if(o==twobed)
        		{
        			if(twobed.isSelected())
        			{
        			int bprice = 21000;	
        			}
        		}
        		else if(o==threebed)
        		{
        			if(threebed.isSelected())
        			{
        			int bprice = 31500;
        			}	
        		}
        		else if(o==fourbed)
        		{
        			if(fourbed.isSelected())
        			{
        			int bprice = 42000;	
        			}
        		}
        		else if(o==carzero)
        		{
        			if(carzero.isSelected())
        			{
    				int cprice = 0;
        			}	
        		}
        		else if(o==carone)
        		{
        			if(carone.isSelected())
        			{
        			int cprice = 7775;	
        			}
        		}
        		else if(o==cartwo)
        		{
        			if(cartwo.isSelected())
        			{
        			int cprice = 15550;	
        			}
        		}
        		else if(o==carthree)
        		{
        			if(carthree.isSelected())
        			{
        			int cprice = 23325;	
        			}
        		}
        		price.setText(+hprice+bprice+cprice);
    	 	}
    	 }
     
    }

    ugh now the program won't recognise my h/b/cprice

    --------------------Configuration: <Default>--------------------
    K:\CompSci\Projects\JMyNewHome.java:177: error: cannot find symbol
        		price.setText(+hprice+bprice+cprice);
        		               ^
      symbol:   variable hprice
      location: class JMyNewHome.ClickButtonListener
    K:\CompSci\Projects\JMyNewHome.java:177: error: cannot find symbol
        		price.setText(+hprice+bprice+cprice);
        		                      ^
      symbol:   variable bprice
      location: class JMyNewHome.ClickButtonListener
    K:\CompSci\Projects\JMyNewHome.java:177: error: cannot find symbol
        		price.setText(+hprice+bprice+cprice);
        		                             ^
      symbol:   variable cprice
      location: class JMyNewHome.ClickButtonListener
    3 errors
     
    Process completed.

    im not quite sure where to put it...

Page 1 of 3 123 LastLast

Similar Threads

  1. Please help me I'm a beginner
    By alloka in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 14th, 2012, 03:23 AM
  2. I am a beginner please help :)
    By mvonb17 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: February 6th, 2012, 03:44 PM
  3. Beginner
    By codejava in forum Member Introductions
    Replies: 2
    Last Post: August 22nd, 2011, 08:11 AM
  4. Beginner
    By angelo24 in forum Member Introductions
    Replies: 1
    Last Post: August 19th, 2011, 07:14 AM
  5. I need a help ! i am beginner
    By yinky in forum Java Theory & Questions
    Replies: 3
    Last Post: September 30th, 2009, 07:22 AM