• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Collision algorithm?

 
Greenhorn
Posts: 9
Netbeans IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Can someone give me a simple way to detect collision between components in jframe?

Thank,
 
Ranch Hand
Posts: 4632
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Turn up the sound.
 
Sheriff
Posts: 28407
101
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And if you don't think that Michael's suggestion applies to your situation, then it would help if you explained what you mean by "collision between components". Perhaps a small code example would help.
 
Ranch Hand
Posts: 356
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No offense to the previous posters, but I really dislike when stuff that is unneeded is said, especially if someone doesn't understand what they are doing and really cannot put out any code. Really turn up the sound?

That being said the most obvious thing would be to check the intersection of the 2 points, depending on what you are trying to do.

For example

http://docs.oracle.com/javase/1.4.2/docs/api/java/awt/Rectangle.html

Rectangle intersection(Rectangle r)
Computes the intersection of this Rectangle with the specified Rectangle.
boolean intersects(Rectangle r)
Determines whether or not this Rectangle and the specified Rectangle intersect.


Rectangle2D createIntersection(Rectangle2D r)
Returns a new Rectangle2D object representing the intersection of this Rectangle with the specified Rectangle2D.
Rectangle2D createUnion(Rectangle2D r)
Returns a new Rectangle2D object representing the union of this Rectangle with the specified Rectangle2D.

depending on what you want to do after the intersection is up to you, good luck hope this helps.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> Really turn up the sound?

a lame question will always deserve a lame answer
 
Paul Clapham
Sheriff
Posts: 28407
101
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Michael, come on, be nice. (It's the motto of the forum, remember.)

But really I don't think of things that you draw in a Swing application as "components". To me "components" are things like JButtons, which normally don't go about colliding. So your guess might be right, Jay, but I think the original poster owes us a bit more of an explanation.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my post wasn't directed at Jay, just an explanation of my first post.
apologies if there's any offence taken (certainly unintended).

anyway, back on topic, I too would like to find out more about how/why the components are bumping into each other.
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:Michael, come on, be nice. (It's the motto of the forum, remember.)

But really I don't think of things that you draw in a Swing application as "components". To me "components" are things like JButtons, which normally don't go about colliding. So your guess might be right, Jay, but I think the original poster owes us a bit more of an explanation.



I don't doubt his wording was incorrect, but some of us don't always know the exact terminology; however it isn't hard to guess what exactly he is talking about. (To my knowledge there isn't a ton of collision detection methods just the intersect).


I see this all the time on this forum that people really don't like to help others unless they

A. Try and put some code up(which sometimes cannot be done if you are extremely confused[Like in my TransferHandler thread])
B. They try and help themselves in some fashion.
C. Know how to 100% articulate their words and terminology.

The ranch to me should be about helping each other out even the noobies who are struggling, we were all new once, and sometimes we need help even if we cannot help ourselves at first.


I dislike the extreme egos I see on this forum that don't want to help anyone out in respect to these 3 points. Besides not answering the questions, and putting up a pointless post, the people, to me, look very childish. I really do not want to deal with such people, nor do the thread starters. We should be the role models and if there is an issue try and answer the question the best you can, and explain it to them.

I do, however, agree the OP should have explained more at first, but since I answered his question to the best of my ability he can either
A. Learn from it and it hopefully will answer his question
B. He will say it doesn't help much and will hopefully explain more now that I have given him a step in the right direction.

I also know that this is a site that we all are spending our free time to help others and that we should be as clear as possible. I REALLY appreciate EVERYTHING I have learned from this site, it is a great place, and there are tons of helpful/warm people, but really, pointless posts aren't needed and not only are you wasting the thread starter's time, but your own as well. why post if it's not going to solve anything? That being said Thank you Paul for the help you have given me I appreciate it greatly.

No offense to anyone in particular, just my feelings about it all,

I hope this question is resolved,

~JO

 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's not about egos at all. This forum, like most programming forums with the notable exception of one major forum that actively encourages spoonfeeding via reward points, aims to teach. Some posters need to learn not just Java, but how to ask a better question. A little sarcastic humor early on goes a long way toward making them realize that.

For those who are genuinely incapable of learning to ask an answerable question, or throw a hissy fit at a misperceived insult, a forum isn't the best learning resource. They too, discover that early and don't clutter the forum with vague, unanswerable questions.

Just my 2p on the matter.
 
reply
    Bookmark Topic Watch Topic
  • New Topic