Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-27-2012, 02:13 PM   PM User | #1
kthreeone
New to the CF scene

 
Join Date: Nov 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
kthreeone is an unknown quantity at this point
Creating a house using BlueJ Shapes

Hi all! I'm very new to java coding, and I was assigned the task of making a house using the shapes folder example in BlueJ. My code is meant to use four square shapes, a triangle and a circle to form a house. However, the problem that I'm having is that when I try to create the house (both one and two window variants), only the roof (triangle) and the sun (circle) show. It's beyond my understanding just what has gone wrong, though I'm sure it's something simple that I'm overlooking.

Code:
 
 /**
 * MyPicture class has as attributes a number of shapes
 * and uses them to create pictures
 *
 * Name
 * Date
 */
public class MyPicture

{
    private Square Square1;
    private Square Square2;
    private Square Square3;
    private Square Square4;
    private Circle Circle1;
    private Triangle Triangle1;
   
   
    /**
     * Instantiates a new MyPicture object. This is a default constructor
     * that only gives values to one of the object's attributes - a circle
     * which is given the colour yellow and made visible.
     * The other attributes are set to NULL.
     */
   
   
    public MyPicture()
    {
        Circle1 = new Circle();
        Circle1.changeColor("yellow");
        Circle1.makeVisible();
    }
 
     /**
     * A basic, one windowed house is created, consisting of two squares and triangles
     * which assigned integer values and then individually set to be visible.
     */public void createOneWindowHouse(){
        Square1 = new Square(110, 60, 90, "red");            
        //Creates 'square1'
        Square2 = new Square(30, 70, 110, "black");           
        //Creates 'square2'
        Triangle1 = new Triangle(50, 150, 114, 40, "yellow"); 
        //Creates 'triangle1'
        Square1.makeVisible();                               
        //Enables visibility for 'square1'
        Square2.makeVisible();                               
        //Enables visibility for 'square2'
        Triangle1.makeVisible();                             
        //Enables visibility for 'triangle1'
    }
   
     /**
     * A varied version of the one windowed house is created, which creates a new square located
     * to the right of the first square in order to create a two windowed house. 
     */public void createTwoWindowHouse(){
        Square1 = new Square(110, 60, 90, "red");             
        //Creates 'square1'
        Square2 = new Square(30, 70, 110, "black");            
        //Creates 'square2'
        Square3 = new Square(30, 115, 110,"black");          
        //Creates 'square3'
        Square4 = new Square(12, 60, 60, "black");
        //Creates 'square4'
        Triangle1 = new Triangle(50, 150, 114, 40, "yellow");  
        //Creates 'triangle1'
        Square1.makeVisible();                                
        //Enables visibility for 'square1'
        Square2.makeVisible();                                
        //Enables visibility for 'square2'
        Square3.makeVisible();                                
        //Enables visibility for 'square3'
        Triangle1.makeVisible();                              
        //Enables visibility for 'triangle1'
    }

    /**
     * This allows the user to select the colour of the porch. 
     */public void changePorchColour(String colour){
     Square4.changeColor(colour);
     
     //Changes the colour of square4, which represents the porch. 
    
    }
    
    /**
     * Depending on which value that users input, a one or two windowed house is created. 
     */public void chooseAHouse(int choice){
       
        if (choice==1){
            createOneWindowHouse();  
            //When the chosen value is 1, this method is performed
        }
        else if (choice==2) {
            createTwoWindowHouse();      
            //When the chosen value is 2, this method is performed
        }
       
        else if (choice!=1 && choice!=2){       
            System.out.println("ERROR!  input must be either 1 or 2");    
            // If value is not equal to choice 1 or choice 2, the error message is displayed. 
       
        }
    }
   
    /**
     * This changes the colour of the roof by selecting valid colours (e.g. "blue", "red", "green").
     */public void changeRoofColour(String colour){
   
    Triangle1.changeColor(colour);
   //Changes the colour of the triangle which was used to create the roof
}
 
    /**
     * This changes the colour of the roof by entering a valid number from 1-6.
     * (e.g. 1 = black, 6= white)
     * If the input is an invalid number, an error message is displayed. 
     */public void changeRoofColour2(int choice){
     
     if (choice==1){ 
        Triangle1.changeColor("black");
        }
     else if (choice==2){
         Triangle1.changeColor("red");
        }
     else if (choice==3){ 
          Triangle1.changeColor("blue");
        }
     else if (choice==4){ 
         Triangle1.changeColor("yellow");
        }
     else if (choice==5){ 
         Triangle1.changeColor("green");
        }
      else if (choice==6){ 
         Triangle1.changeColor("white");
        }
      else{
         System.out.println("ERROR! input must be between 1 and 6");
        }
    }
   
    
    
}
If anybody can help me with this I'd be very grateful. Thanks in advance!
kthreeone is offline   Reply With Quote
Old 11-27-2012, 02:47 PM   PM User | #2
007julien
Regular Coder

 
Join Date: May 2012
Location: France
Posts: 115
Thanks: 0
Thanked 17 Times in 15 Posts
007julien is an unknown quantity at this point
Java (which is to a dance was developed in France in the early part of the 20th century) is not javascript !
007julien is offline   Reply With Quote
Old 11-27-2012, 05:02 PM   PM User | #3
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
This is the JavaScript forum. Java and Javascript are entirely different programming languages, in spite of the confusingly similar names. Rather like Austria and Australia! Ask a mod to move this thread to the right forum.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Old 11-28-2012, 03:37 AM   PM User | #4
kthreeone
New to the CF scene

 
Join Date: Nov 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
kthreeone is an unknown quantity at this point
Quote:
Originally Posted by Philip M View Post
This is the JavaScript forum. Java and Javascript are entirely different programming languages, in spite of the confusingly similar names. Rather like Austria and Australia! Ask a mod to move this thread to the right forum.
Oh dear that's quite embarrassing. How do I go about getting a mod to move my thread? It's been a long time since I've used a forum!
kthreeone is offline   Reply With Quote
Old 11-28-2012, 03:43 AM   PM User | #5
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Quote:
Originally Posted by kthreeone View Post
Oh dear that's quite embarrassing. How do I go about getting a mod to move my thread? It's been a long time since I've used a forum!
I'll take care of moving it, then review it.

I won't be able to run this code since there isn't enough here. Are these painted onto a gui or are these handled in the CLI? The output for the errors looks like the CLI is in use here, but colour is not fun on the CLI.

Edit:
BTW, I won't be able to look at this until tomorrow now as I have to go bake a cheesecake. But check and see where you are calling all of this step it through a debugger and verify that the shapes are set properly. I'm assuming its a GUI in use here which would tell me its something to do with the painting, but unfortunately we can't see where the painting is occurring (or how; this object isn't a paintable type, but has no access to these items within it individually).
Edit:
Unless its just textual output? For which we'd definitely need to see how its accessing.


Last edited by Fou-Lu; 11-28-2012 at 03:58 AM..
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:56 PM.


Advertisement
Log in to turn off these ads.