
Drawing the dash line
Hi,
I have a very simple question. Is there is a function I can use to draw dash
line in Java AWT.
Thanks,
Frank

Re: Drawing the dash line
There are none that I know of but you can use something like this if you need
it,
protected void drawDashedLine(Graphics g, Point a, Point b,
int dashLen, int spaceLen)
{
int dely = Math.abs(a.yb.y)/Math.abs(a.xb.x);
int delx = Math.abs(a.xb.x)/Math.abs(a.yb.y);
int jumpLen = dashLen + spaceLen;
for(int x = a.x, y = a.y; x < b.x; x+= delx*jumpLen, y+= dely*jumpLen)
{
if(x+delx*dashLen > b.x  y+dely*dashLen > b.y)
g.drawLine(x, y, b.x, b.y);
else
g.drawLine(x,y,x+delx*dashLen, y+dely*dashLen);
}
}
I think this works perfectly
Hope this was of help
Moppy
"frankmail007" <frankmail007@yahoo.com> wrote:
>
>Hi,
>
>I have a very simple question. Is there is a function I can use to draw
dash
>line in Java AWT.
>
>Thanks,
>
>Frank

Re: Drawing the dash line
Sorry, the function that I gave you has quite a few major errors in it, but
I think you will have to develop something similar though.
"Moppy" <djavro@start.com.au> wrote:
>
>There are none that I know of but you can use something like this if you
need
>it,
>
>protected void drawDashedLine(Graphics g, Point a, Point b,
> int dashLen, int spaceLen)
>{
> int dely = Math.abs(a.yb.y)/Math.abs(a.xb.x);
> int delx = Math.abs(a.xb.x)/Math.abs(a.yb.y);
> int jumpLen = dashLen + spaceLen;
>
> for(int x = a.x, y = a.y; x < b.x; x+= delx*jumpLen, y+= dely*jumpLen)
> {
> if(x+delx*dashLen > b.x  y+dely*dashLen > b.y)
> g.drawLine(x, y, b.x, b.y);
> else
> g.drawLine(x,y,x+delx*dashLen, y+dely*dashLen);
> }
>}
>
>I think this works perfectly
>Hope this was of help
>Moppy
>
>"frankmail007" <frankmail007@yahoo.com> wrote:
>>
>>Hi,
>>
>>I have a very simple question. Is there is a function I can use to draw
>dash
>>line in Java AWT.
>>
>>Thanks,
>>
>>Frank
>

Re: Drawing the dash line
Thank you. I'll figure it out.
Frank
"Moppy" <djavro@start.com.au> wrote:
>
>
>Sorry, the function that I gave you has quite a few major errors in it,
but
>I think you will have to develop something similar though.
>
>
>
>"Moppy" <djavro@start.com.au> wrote:
>>
>>There are none that I know of but you can use something like this if you
>need
>>it,
>>
>>protected void drawDashedLine(Graphics g, Point a, Point b,
>> int dashLen, int spaceLen)
>>{
>> int dely = Math.abs(a.yb.y)/Math.abs(a.xb.x);
>> int delx = Math.abs(a.xb.x)/Math.abs(a.yb.y);
>> int jumpLen = dashLen + spaceLen;
>>
>> for(int x = a.x, y = a.y; x < b.x; x+= delx*jumpLen, y+= dely*jumpLen)
>> {
>> if(x+delx*dashLen > b.x  y+dely*dashLen > b.y)
>> g.drawLine(x, y, b.x, b.y);
>> else
>> g.drawLine(x,y,x+delx*dashLen, y+dely*dashLen);
>> }
>>}
>>
>>I think this works perfectly
>>Hope this was of help
>>Moppy
>>
>>"frankmail007" <frankmail007@yahoo.com> wrote:
>>>
>>>Hi,
>>>
>>>I have a very simple question. Is there is a function I can use to draw
>>dash
>>>line in Java AWT.
>>>
>>>Thanks,
>>>
>>>Frank
>>
>
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Development Centers
 Android Development Center
 Cloud Development Project Center
 HTML5 Development Center
 Windows Mobile Development Center
