Results 1 to 16 of 16
  1. #1
    GA Scooby's Avatar
    GA Scooby is offline Member
    Join Date
    Apr 2011
    Posts
    8
    Rep Power
    0

    Default Help with House/Fence Applet.

    Hey guys first post here. I have to design and implement a fence that draws a simple fence with vertical, equally spaced slats backed by two horizontal support boards. Behind my fence I had to develop a house in the background. Note: the house has to be visible behind the slats in the fence.


    Here is what I have:

    import java.awt.*;
    import java.applet.*;

    public class ProgrammingAssignment7 extends Applet
    {
    public void paint (Graphics g)
    {

    house (g);
    roof1 (g);
    windows (g);
    framing (g);


    }


    public void house (Graphics g)
    {
    g.setColor (Color.black); //house
    g.fillRect (100,250,400,200);
    g.setColor(Color.blue); //doors
    g.fillRect (245,380,110,70);
    g.setColor (new Color(186,134,11)); //door knobs
    g.fillOval (282,412,10,10);
    g.fillOval (307,412,10,10);

    }

    public void roof1 (Graphics g)
    {
    g.setColor(Color.red); //house roof
    int x[] = {98,300,501};
    int y[] = {250,130,250};
    g.fillPolygon(x,y,3);
    }



    public void windows (Graphics g)
    {
    g.setColor (Color.red); //outer frame effect
    g.fillRect (121,261,78,78);
    g.fillRect (121,361,78,78);
    g.fillRect (401,261,78,78);
    g.fillRect (401,361,78,78);
    g.setColor (Color.orange); //windows
    g.fillRect (125,265,70,70);
    g.fillRect (125,365,70,70);
    g.fillRect (405,265,70,70);
    g.fillRect (405,365,70,70);


    }

    public void framing (Graphics g)
    {
    g.setColor (Color.red); //door sections
    g.fillRect (298,380,2,70);
    g.setColor (Color.red); //inner frame effect
    g.fillRect (157,265,5,70);
    g.fillRect (157,365,5,70);
    g.fillRect (437,265,5,70);
    g.fillRect (438,365,5,70);
    g.fillRect (125,298,70,5);
    g.fillRect (125,398,70,5);
    g.fillRect (405,298,70,5);
    g.fillRect (405,398,70,5);
    g.fillRect (245,375,110,5); //door

    }



    }

    thanks :D

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,889
    Rep Power
    8

    Default

    And here's the hat trick!
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    GA Scooby's Avatar
    GA Scooby is offline Member
    Join Date
    Apr 2011
    Posts
    8
    Rep Power
    0

    Default

    What?! Where is there a rabbit some where? :eek:

    LOL
    Last edited by GA Scooby; 04-07-2011 at 03:08 PM.

  4. #4
    GA Scooby's Avatar
    GA Scooby is offline Member
    Join Date
    Apr 2011
    Posts
    8
    Rep Power
    0

    Default

    Ahh I see now. I don't need the full program I just need some help with getting the slats set up evenly an able to see the house through the slats. This was my last resort that's why I signed up. I've never had a problem until this program.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,856
    Rep Power
    19

    Default

    Not sure what you're looking for here.
    Since you've already drawn a door, wouldn't a fence be similar, simply with lots of thinner bits, plus two short and wide bits?

  6. #6
    GA Scooby's Avatar
    GA Scooby is offline Member
    Join Date
    Apr 2011
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by Tolls View Post
    Not sure what you're looking for here.
    Since you've already drawn a door, wouldn't a fence be similar, simply with lots of thinner bits, plus two short and wide bits?
    I am looking for help in how to get the fence posts set up in such a way that they are evenly spaced apart so that they look uniform and symmetric.

    Every time I set it up it's never even or it's lying behind the house.

  7. #7
    GA Scooby's Avatar
    GA Scooby is offline Member
    Join Date
    Apr 2011
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by GA Scooby View Post
    I am looking for help in how to get the fence posts set up in such a way that they are evenly spaced apart so that they look uniform and symmetric.

    Every time I set it up it's never even or it's lying behind the house.
    Professor recommended using a for loop.

  8. #8
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,889
    Rep Power
    8

    Default

    Quote Originally Posted by GA Scooby View Post
    Professor recommended using a for loop.
    Then I would probably use a for loop.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,856
    Rep Power
    19

    Default

    So where is the code for the fence that you've tried then?

  10. #10
    GA Scooby's Avatar
    GA Scooby is offline Member
    Join Date
    Apr 2011
    Posts
    8
    Rep Power
    0

    Default

    Right here:

    int x = 5, y = 200, w = 25, l = 75, s= 10;


    for (int count = 0; count < S; count++)//draws the vertical slats of the fence
    {
    if (count < S)
    {
    page.setColor (Color.yellow);
    page.fillRect (x,y,w,l);
    }

    x += W + 10;

    {
    page.setColor (Color.yellow);//draws the two support beams of the fence
    page.fillRect (0,y+5,350,10);
    page.fillRect (0,y+60,350,10);
    Last edited by GA Scooby; 04-07-2011 at 07:49 PM.

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,856
    Rep Power
    19

    Default

    Can you use code tags, so it's easier to read?

    Anyway, what happens when you use that code?
    It looks to me at first glance that it should produce 10 upright blocks, 25 wide, 75 high, with a gap of 10 between them.

    ETA: Also can you post your actual code, wince that above won't compile, even if put in a method.

  12. #12
    GA Scooby's Avatar
    GA Scooby is offline Member
    Join Date
    Apr 2011
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by Tolls View Post
    Can you use code tags, so it's easier to read?

    Anyway, what happens when you use that code?
    It looks to me at first glance that it should produce 10 upright blocks, 25 wide, 75 high, with a gap of 10 between them.

    ETA: Also can you post your actual code, wince that above won't compile, even if put in a method.
    I actually just went in and took your advice by doing them each post one at a time. It worked out pretty well I think. I should have just done that in the first place...:p

    Here is the whole code that I did:

    Java Code:
    import java.awt.*;
    import java.applet.*;
    
    public class ProgrammingAssignment7 extends Applet
    {
       public void paint (Graphics g)
       {
          
          house (g);
          roof1 (g);
          windows (g);
          framing (g);
          fencepost (g);
         
       }
      
     
       public void house (Graphics g)
       {
          g.setColor (Color.black);   //house 
          g.fillRect (100,250,400,200);
          g.setColor(Color.blue);   //doors   
          g.fillRect (245,380,110,70);
          g.setColor (new Color(186,134,11));   //door knobs
          g.fillOval (282,412,10,10);
          g.fillOval (307,412,10,10);
         
       }
      
       public void roof1 (Graphics g)
       {
          g.setColor(Color.red);   //house roof
          int x[] = {98,300,501};
          int y[] = {250,130,250};
          g.fillPolygon(x,y,3);
       }
      
      public void fencepost (Graphics g)
      {
         g.setColor (Color.white); //verticle fence posts
    	  g.fillRect (100,400,10,50);
    	  g.fillRect (125,400,10,50);
    	  g.fillRect (150,400,10,50);
    	  g.fillRect (175,400,10,50);
    	  g.fillRect (200,400,10,50);
    	  g.fillRect (225,400,10,50);
    	  g.fillRect (250,400,10,50);
    	  g.fillRect (275,400,10,50);
    	  g.fillRect (300,400,10,50);
    	  g.fillRect (325,400,10,50);
    	  g.fillRect (350,400,10,50);
    	  g.fillRect (375,400,10,50);
    	  g.fillRect (400,400,10,50);
    	  g.fillRect (425,400,10,50);
    	  g.fillRect (450,400,10,50);
    	  g.fillRect (475,400,10,50);
    	  g.fillRect (500,400,10,50);
    	  g.fillRect (100,415,400,5); //horizontal slats
    	  g.fillRect (100,435,400,5);
      }
       public void windows (Graphics g)
       {
          g.setColor (Color.red);   //outer frame effect
          g.fillRect (121,261,78,78);
          g.fillRect (121,361,78,78);
          g.fillRect (401,261,78,78);
          g.fillRect (401,361,78,78);
          g.setColor (Color.orange);   //windows
          g.fillRect (125,265,70,70);
          g.fillRect (125,365,70,70);
          g.fillRect (405,265,70,70);
          g.fillRect (405,365,70,70);
          
          
       }
      
       public void framing (Graphics g)
       {
          g.setColor (Color.red);   //door sections
          g.fillRect (298,380,2,70);
          g.setColor (Color.red);   //inner frame effect
          g.fillRect (157,265,5,70);
          g.fillRect (157,365,5,70);
          g.fillRect (437,265,5,70);
          g.fillRect (438,365,5,70);
          g.fillRect (125,298,70,5);
          g.fillRect (125,398,70,5);
          g.fillRect (405,298,70,5);
          g.fillRect (405,398,70,5);
          g.fillRect (245,375,110,5);   //door            
          
       }
      
      
         
    }
    Last edited by Fubarable; 04-08-2011 at 05:01 PM. Reason: code tags added

  13. #13
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I have edited your code and added code tags which should help make your posted code retain its formatting and be more readable.

    To do this yourself, highlight your pasted code (please be sure that it is already formatted when you paste it into the forum; the code tags don't magically format unformatted code) and then press the code button, and your code will have tags.

    Another way to do this is to manually place the tags into your code by placing the tag [cod&#101;] above your pasted code and the tag [/cod&#101;] below your pasted code like so:

    Java Code:
    [cod&#101;]
      // your code goes here
      // notice how the top and bottom tags are different
    [/cod&#101;]
    Best of luck

  14. #14
    GA Scooby's Avatar
    GA Scooby is offline Member
    Join Date
    Apr 2011
    Posts
    8
    Rep Power
    0

    Default

    Thanks Fubarable I appreciate the input :)

  15. #15
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default

    for the vertical fence post you can also use a loop like

    Java Code:
    		for (int i=100; i < 525; i+=25) {
    			g.fillRect(i, 400, 10, 50);
    		}

  16. #16
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,856
    Rep Power
    19

    Default

    Quote Originally Posted by GA Scooby View Post
    I actually just went in and took your advice by doing them each post one at a time.
    I don't think that was my advice...but hey ho.

Similar Threads

  1. Fence Post problem
    By seanfmglobal in forum New To Java
    Replies: 6
    Last Post: 01-20-2011, 03:53 AM
  2. building a house but having problems connecting it
    By youngflames in forum New To Java
    Replies: 9
    Last Post: 01-26-2010, 06:00 PM
  3. build a house with windows and a door
    By youngflames in forum New To Java
    Replies: 3
    Last Post: 01-22-2010, 01:33 PM
  4. Hello gurus' in the house
    By javahsm in forum New To Java
    Replies: 0
    Last Post: 11-29-2008, 06:11 PM
  5. building a house
    By dc2acgsr99 in forum Java Applets
    Replies: 4
    Last Post: 03-07-2008, 11:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •