Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6638469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:26:22+00:00 2026-05-25T23:26:22+00:00

im trying to implement a getBounds() method, but i cant get union to work;

  • 0

im trying to implement a getBounds() method, but i cant get union to work; i must not understand how union works. my code is the following:

public Rectangle2D getBounds2D() {
    Rectangle2D rec= new Rectangle2D.Double();
    Rectangle2D temp;
    for(int i=0; i<shapes.size(); i++){
        temp = new Rectangle2D.Double(shapes.get(i).getBounds2D().getX(),shapes.get(i).getBounds2D().getY(),shapes.get(i).getBounds2D().getWidth(), shapes.get(i).getBounds2D().getHeight());
        rec.createUnion(temp);

    }
    return rec;
}

the shapes variable is an arraylist of Shapes.

i use temp to create a rectangle using the bounds from each shape in the arraylist

Ive used getbounds().getWidth/Height on temp to see if it were returning wierd numbers but the numbers look fine. When i call rec.getBounds.getWidth/Height i get 0.0 for both. From this, im assuming that im not using union() correctly. does anyone have any insight as to what i can to? thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:26:23+00:00Added an answer on May 25, 2026 at 11:26 pm

    If you are not sure how to use the method then why is your code so complex to test the method? Why are you looping through and array? How will you verify the results?

    Start with something simple. Try to use the method with just two rectangles and with hardcoded values for each Rectangle. Then you can easily verify the results. If it doesn’t work then you have a complete program to post.

    Something like:

    public class Test
    {
        public static void main(String args[]) throws Exception
        {
            Rectangle a = new Rectangle(5, 5, 30, 30);
            Rectangle b = new Rectangle(10, 10, 50, 50);
            a = a.union(b);
            System.out.println(a);
            System.out.println(b);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to implement AVAudioplayer and get some metering data of the played music, but
I'm trying implement my project in Apache Struts 2 but I'm not very familiar
Trying to implement sticky footer but its not working as planned. It throws it
SetFocus I'm trying implement the above Se Focus code in a Class Library that
Trying to implement this gallery on my website. http://coffeescripter.com/code/ad-gallery/ It is noted in the
Trying to implement the following structure from c to use NSArray in objective-c: In
Trying to implement a MSMQ-backed WCF PubSub. I understand that net.msmq is one-way; however
Trying to implement the new FP 10.1 Global error handler into my projects but
Trying to implement an autocomplete box ultimately. For now im following php academy's lead.
Just trying to implement mobFox into my app, but having trouble to make it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.