Results 1 to 16 of 16
Thread: Help with House/Fence Applet.
- 04-07-2011, 02:57 PM #1
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
- 04-07-2011, 03:00 PM #2
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!
- 04-07-2011, 03:04 PM #3
What?! Where is there a rabbit some where? :eek:
LOLLast edited by GA Scooby; 04-07-2011 at 03:08 PM.
- 04-07-2011, 03:12 PM #4
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.
- 04-07-2011, 04:25 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
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?
- 04-07-2011, 04:28 PM #6
- 04-07-2011, 04:30 PM #7
- 04-07-2011, 04:33 PM #8
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 04-07-2011, 05:00 PM #9
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
So where is the code for the fence that you've tried then?
- 04-07-2011, 06:43 PM #10
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.
- 04-08-2011, 08:29 AM #11
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
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.
- 04-08-2011, 05:00 PM #12
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
-
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 [code] above your pasted code and the tag [/code] below your pasted code like so:
Best of luckJava Code:[code] // your code goes here // notice how the top and bottom tags are different [/code]
- 04-08-2011, 05:04 PM #14
Thanks Fubarable I appreciate the input :)
- 04-08-2011, 09:52 PM #15
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); }
- 04-11-2011, 09:58 AM #16
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Similar Threads
-
Fence Post problem
By seanfmglobal in forum New To JavaReplies: 6Last Post: 01-20-2011, 03:53 AM -
building a house but having problems connecting it
By youngflames in forum New To JavaReplies: 9Last Post: 01-26-2010, 06:00 PM -
build a house with windows and a door
By youngflames in forum New To JavaReplies: 3Last Post: 01-22-2010, 01:33 PM -
Hello gurus' in the house
By javahsm in forum New To JavaReplies: 0Last Post: 11-29-2008, 06:11 PM -
building a house
By dc2acgsr99 in forum Java AppletsReplies: 4Last Post: 03-07-2008, 11:18 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks