Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-03-2008, 07:32 PM
dc2acgsr99's Avatar
Member
 
Join Date: Jan 2008
Location: Pittsburgh
Posts: 26
dc2acgsr99 is on a distinguished road
Send a message via AIM to dc2acgsr99
building a house
In all actuality I have many questions here but heres one for starters. In my java class we are starting to do applets for html. Our first project to to make a house that will show up good in 800 x 600 resolution. The instructor recommended to draw it out in a grid first. Is there any special way I should draw this grid so the sizes of the objects are accurate when transfured to the pc?? If that makes any sence to anyone.
__________________
Hey I'm still learning... Thats my story and I'm sticking to it
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-07-2008, 02:36 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,029
hardwired is on a distinguished road
Code:
// <applet code="HouseDrawing" width="400" height="400"></applet> import java.awt.*; import java.awt.geom.Line2D; import javax.swing.*; public class HouseDrawing extends JApplet { public void init() { add(new HouseDrawPanel()); } } class HouseDrawPanel extends JPanel { int rows = 32; int cols = 32; int pad = 20; protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int w = getWidth(); int h = getHeight(); double xInc = (double)(w - 2*pad)/cols; double yInc = (double)(h - 2*pad)/rows; g2.setPaint(new Color(210,200,230)); for(int j = 0; j <= rows; j++) { double y = pad + j*yInc; g2.draw(new Line2D.Double(pad, y, w-pad, y)); } for(int j = 0; j <= cols; j++) { double x = pad + j*xInc; g2.draw(new Line2D.Double(x, pad, x, h-pad)); } g2.setPaint(Color.red); double x1 = pad + 5*xInc; double y1 = pad + (rows/2)*yInc; double x2 = x1; double y2 = pad + (rows-5)*yInc; g2.draw(new Line2D.Double(x1, y1, x2, y2)); x2 = pad + (cols/2)*xInc; g2.draw(new Line2D.Double(x1, y2, x2, y2)); x1 = x2; double length = y2 - y1; y1 = y1 + length/2; g2.draw(new Line2D.Double(x1, y1, x2, y2)); } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 03-07-2008, 09:16 PM
dc2acgsr99's Avatar
Member
 
Join Date: Jan 2008
Location: Pittsburgh
Posts: 26
dc2acgsr99 is on a distinguished road
Send a message via AIM to dc2acgsr99
Just ran your program there and I must say thats impressive beyond my current abilities. I have My applet done but my question now is how do I change font size and make it bold? Here is the code I am working with, it is to be run as html at 800x600, and the font is the last part of the code...

Code:
import java.awt.*; import java.applet.*; public class kthLab2 extends Applet { public void paint (Graphics g) { background(g); house (g); roof1 (g); roof2 (g); windows (g); framing (g); extras (g); text (g); } public void background(Graphics g) { setBackground (new Color(65,105,225)); //sky g.setColor (new Color (225,225,225)); //coluds g.fillOval (15,35,170,55); g.fillOval (20,20,160,50); g.fillOval (350,50,170,55); g.fillOval (355,35,160,50); g.setColor (new Color(225,140,0)); //sun g.fillOval (650,035,120,120); g.setColor (new Color(0,100,0)); //grass g.fillRect (000,370,800,800); g.fillOval (400,300,500,300); g.fillOval (150,320,500,300); g.fillOval (000,280,500,300); g.fillOval (000,320,300,110); } public void house (Graphics g) { g.setColor (new Color(139,69,19)); //house and garage g.fillRect (100,250,400,200); g.fillRect (499,320,200,130); g.setColor(new Color(190,190,190)); //doors and chimney g.fillRect (160,150,60,90); g.fillRect (245,380,110,70); g.fillRect (508,350,180,100); 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(new Color(190,190,190)); //house roof int x[] = {98,300,501}; int y[] = {250,130,250}; g.fillPolygon(x,y,3); } public void roof2 (Graphics g) { g.setColor (new Color(190,190,190)); //garage roof int x[] = {499,499,700}; int y[] = {320,249,320}; g.fillPolygon(x,y,3); } public void windows (Graphics g) { g.setColor (new Color(186,134,11)); //outer frame effect g.fillOval (521,350,68,31); g.fillOval (606,350,68,31); 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.fillOval (241,261,118,78); g.setColor (new Color(175,238,238)); //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); g.fillOval (245,265,110,70); g.fillOval (525,353,60,25); g.fillOval (610,353,60,25); } public void framing (Graphics g) { g.setColor (new Color(139,69,19)); //grage and door sections g.fillRect (298,380,2,70); g.fillRect (508,382,180,2); g.fillRect (508,417,180,2); g.setColor (new Color(186,134,11)); //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 (297,265,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,298,110,5); g.fillRect (245,375,110,5); //door and garage frame g.fillRect (240,375,5,75); g.fillRect (352,375,5,75); g.fillRect (508,345,180,5); g.fillRect (503,345,5,105); g.fillRect (688,345,5,105); } public void extras (Graphics g) { g.setColor (new Color(210,180,140)); //smoke for chimney g.fillOval (160,105,35,45); g.fillOval (170,95,35,45); g.fillOval (160,85,35,45); g.fillOval (170,35,35,45); g.fillOval (160,25,35,45); g.fillOval (170,15,35,45); g.setColor (new Color(105,105,105)); //sidewalk and driveway g.fillRect (508,450,180,150); g.fillRect (245,450,107,50); g.fillRect (274,500,50,40); g.fillRect (274,520,250,45); } public void text (Graphics g) //header text { g.setColor(new Color(225,0,0)); g.drawString("Here is a house.",390,70); } }
__________________
Hey I'm still learning... Thats my story and I'm sticking to it
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 03-07-2008, 10:59 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,029
hardwired is on a distinguished road
Code:
public void text (Graphics g) //header text { g.setFont(new Font("Dialog", Font.PLAIN, 24)); g.setColor(new Color(225,0,0)); g.drawString("Here is a house.",390,70); }
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 03-08-2008, 12:18 AM
dc2acgsr99's Avatar
Member
 
Join Date: Jan 2008
Location: Pittsburgh
Posts: 26
dc2acgsr99 is on a distinguished road
Send a message via AIM to dc2acgsr99
Thank you so much for that!
__________________
Hey I'm still learning... Thats my story and I'm sticking to it
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Building a document from a DOM Java Tip Java Tips 0 01-03-2008 10:22 AM
building file and variable names from variables madad2005 New To Java 2 07-18-2007 05:47 PM
Problem with String Building Albert New To Java 0 07-09-2007 08:20 PM
Building A Java Project In Eclipse JavaForums Eclipse 0 05-22-2007 10:34 PM
help needed regarding tree building invincible_me New To Java 1 04-29-2007 11:39 AM


All times are GMT +3. The time now is 05:57 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org