1

Well,i'm new to Java and these days i practice with the acm.library. I have to create a house with 2 windows,a door and a roof. But,i want them centered in their positions, regardless the width and height of the shapes.

I just have centered the wall of the house,and right now i want some help about how to place the door at the center of the house and how to place the 2 windows right and left of the door.

EDIT : DONE with door and left window!!!

here is my code:

import acm.program.*;

import java.awt.*;

import acm.graphics.*;

public class home extends GraphicsProgram
{

public void run () 
{

        double x = (getWidth() - FIGURE_WIDTH)/2  ;
        double y = (getHeight() - FIGURE_HEIGHT) /2 ; 
        GRect rect = new GRect(x,y, FIGURE_WIDTH,FIGURE_HEIGHT);
        rect.setFilled(false);
        rect.setColor(Color.BLACK);
        add(rect);



    }
        private static final double FIGURE_WIDTH = 480;
        private static final double FIGURE_HEIGHT = 200;

}
Robin Green
  • 32,079
  • 16
  • 104
  • 187
Socratεs
  • 27
  • 8
  • Divide the length of your front wall by 4. The door is centered on 1/2, and the windows are centered on 1/4 and 3/4, respectively. – Gilbert Le Blanc Nov 21 '13 at 20:31
  • @GilbertLeBlanc in my code,how can i do this? i understand what you say,but i need to see an example with how to center the door inside the front wall in order to create the windows by myself. – Socratεs Nov 21 '13 at 20:41
  • Say the front wall is 480 pixels across. The door is centered on 240, and the windows are centered on 120 and 360, respectively. – Gilbert Le Blanc Nov 21 '13 at 20:48
  • @GilbertLeBlanc could you show me an example with the door? understood what you say but ,i can't do it into my code. – Socratεs Nov 21 '13 at 20:59
  • I've never used the ACM library. I've always used Java 2D classes. – Gilbert Le Blanc Nov 21 '13 at 21:08

0 Answers0