Re: Problem with overlapping custom componets
- From: L I M <clgoh@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 15 Nov 2007 08:42:00 -0800 (PST)
On Nov 14, 2:54 pm, "A. Bolmarcich" <agge...@xxxxxxxxxxxxxxxxxxxx>
wrote:
On 2007-11-14, L I M <cl...@xxxxxxxxxxxxxxxxxxxxxxx> wrote:
[snip]
Unless, if you've tried running the code, the user is given an
impression that
the lines are indeed non-overlapping, only the rectagle borders are.
Simply put it, the drawings of the rectagle borders had not covered
that part of the blue line, since the rectangle is transparent. But
the event is still consumed by the rectangle instead of the line
underneath it, since the rectangular object is still on top of that
line.
If that is the problem, then a boolean contains(int x, int y) method
should be added to the Line class. A return value of true indicates
that the component should receive mouse events when the mouse is at
location (x,y) of the component.
<code>
public boolean contains( int x, int y ) {
if( isBetween( x, line.getX1(), line.getX2() ) ) {
return (y - Math.min( line.getY1(), line.getY2() ) ) == ( x -
Math.min( line.getX1(), line.getX2() ) ) / Math.abs( line.getX1() -
line.getX2() ) * Math.abs( line.getY1() - line.getY2() );
} else {
return false;
}
}
private boolean isBetween( double x, double a, double b ) {
if( a > b ) {
return x <= a && x >= b;
} else if ( a < b ) {
return x >= a && x <= b;
} else {
return x == a;
}
}
</code>
Is that it??
.
- References:
- Problem with overlapping custom componets
- From: Chanchal
- Re: Problem with overlapping custom componets
- From: A. Bolmarcich
- Problem with overlapping custom componets
- Prev by Date: drag and drop in a JMenu/JMenuItem
- Next by Date: Re: PDF Processing
- Previous by thread: Re: Problem with overlapping custom componets
- Next by thread: PDF Processing
- Index(es):