Results 1 to 3 of 3
  1. #1
    Snake006 is offline Member
    Join Date
    Jun 2013
    Posts
    96
    Rep Power
    0

    Default how to make a resizalbe house

    I am currently trying to make a method to make a resizable house. While I can certainly resize the size of every object in the house, for example a window, door, or roof, that has proven very difficult due to balancing issues(having a big window can overshadow the entire house). What I would like to do is resize all objects together at the same time so everything is spaced out accordingly. I imagine I will need some sort of mathematical formula to do so(which I am horrible at). Here is the method for drawing the house and the implementation of it.

    Java Code:
    public void drawhouse(double sizeH, double sizeW,double xpos, double ypos) {
     
            GRect body = new GRect(sizeH, sizeW);  //  w/2 h/3
            body.setFilled(true);
            body.setFillColor(Color.GRAY);
            add(body, xpos, ypos);
    
            GRect window = new GRect( 40, 60);
            window.setFilled(true);
            window.setFillColor(Color.WHITE);
            add (window, 250,250 );
    
            GRect window2 = new GRect( 40, 60);
            window2.setFilled(true);
            window2.setFillColor(Color.WHITE);
            add (window2, 475,250 );
            
            GRect door = new GRect (60,90);
            door.setFilled(true);
            door.setFillColor(Color.orange);
            add (door, 363,274);
            
            int w = this.getWidth();
            int h = this.getHeight();
            GPolygon roof = new GPolygon (w, h);
            roof.setFilled(true);
            roof.setFillColor(Color.orange);
            roof.addVertex(0, 200);
            roof.addVertex(380, 200);
            roof.addVertex(200, 0);
            add (roof, 200 ,0 );
         
        }
    
        public void run() {
            int w = this.getWidth();
            int h = this.getHeight();
    
            drawhouse(w/2,h/3,200,200);  //this is where the house size can be edited,
            //note I didn't include specifications for the roof since editing it unbalances the whole    //thing
    
        }
    Ideally I wish I could just save all these objects into one (like creating a GObject and just calling that when I would want to edit it, but that has proven unsuccessful)
    Any thoughts?

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,614
    Rep Power
    5

    Default Re: how to make a resizalbe house

    Do you really want to resize the objects or just how they are displayed? In Swing you can always call
    Graphics2D.scale() to scale the graphics context prior to drawing.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    Snake006 is offline Member
    Join Date
    Jun 2013
    Posts
    96
    Rep Power
    0

    Default Re: how to make a resizalbe house

    How should that method normally look? I am having trouble calling it since it is non-static method being referenced from a static context.
    To answer you question I guess I would like all the objects to behave as one object, thus making it easier to resize the whole thing, rather than having to calculate for what every single size each object must adjust to fit inside the house. Basically this drawhouse method makes a bunch of objects, such as windows, a door, and a roof and draws them all on the screen. I would like to take the entire drawn object and resize it using a method of some sort or saving all the objects into one GObject and then resizing it.

Similar Threads

  1. Replies: 2
    Last Post: 09-23-2012, 10:35 PM
  2. Replies: 6
    Last Post: 08-18-2012, 09:54 AM
  3. 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
  •