Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > how to draw a dashed line between two points

Reply
Thread Tools

how to draw a dashed line between two points

 
 
Rick
Guest
Posts: n/a
 
      09-30-2003
Can someone please show me how to draw a dashed line between two points?
Is there a method in the AWT library that allows this? Thanks!

Rick

 
Reply With Quote
 
 
 
 
Robert Olofsson
Guest
Posts: n/a
 
      09-30-2003
Rick (rrquick@nospam-com) wrote:
: Can someone please show me how to draw a dashed line between two points?
: Is there a method in the AWT library that allows this? Thanks!

http://java.sun.com/docs/books/tutor...keandfill.html

/robo
 
Reply With Quote
 
 
 
 
Tr0mBoNe-
Guest
Posts: n/a
 
      09-30-2003
Rick <rrquick@nospam-com> wrote in message news:<3f79818a$(E-Mail Removed)>...
> Can someone please show me how to draw a dashed line between two points?
> Is there a method in the AWT library that allows this? Thanks!
>
> Rick


There is only one way i can think of. First you have to take the 2
points, and their line connecting them, and dividing it up into n
segments where n is really big. Then, you can compute the endpoints of
each segment and make every n/oh say 50 lines wite (or the background
color). There is more math and a trickey algorithm to get down so it
will be scalable, but its really not that hard. There is no method in
any awt class that will make the style of the line dotted, unless you
create a border around a rectangle of 0 width and 0 padding, but it
would take about the same amount of code to implement.

Cheers.
 
Reply With Quote
 
Sandip Chitale
Guest
Posts: n/a
 
      09-30-2003
Rick <rrquick@nospam-com> wrote in message news:<3f79818a$(E-Mail Removed)>...
> Can someone please show me how to draw a dashed line between two points?
> Is there a method in the AWT library that allows this? Thanks!
>
> Rick

http://groups.google.com/groups?q=dr...ist.com&rnum=2

For reference:

public void drawDashedLine(Graphics g,int x1,int y1,int x2,int
y2,double dashlength,double spacelength){
double linelength=Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
double yincrement=(y2-y1)/(linelength/(dashlength+spacelength));
double xincdashspace=(x2-x1)/(linelength/(dashlength+spacelength));
double yincdashspace=(y2-y1)/(linelength/(dashlength+spacelength));
double xincdash=(x2-x1)/(linelength/(dashlength));
double yincdash=(y2-y1)/(linelength/(dashlength));
int counter=0;
for(double i=0;i<linelength-dashlength;i+=dashlength+spacelength){
g.drawLine((int) (x1+xincdashspace*counter),(int)
(y1+yincdashspace*counter),
(int) (x1+xincdashspace*counter+xincdash),(int)
(y1+yincdashspace*counter+yincdash));
counter++;
}
if ((dashlength+spacelength)*counter<=linelength)
g.drawLine((int) (x1+xincdashspace*counter),(int)
(y1+yincdashspace*counter),x2,y2);
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
draw a line if the color of points of beginning and end are différent from white olsr.kamal@gmail.com Python 2 03-06-2013 08:57 PM
how to draw line dynamically between two points balakrishnan.dinesh@gmail.com Javascript 1 08-25-2006 12:06 PM
Creating a dashed line John Abbler HTML 18 07-18-2005 02:09 AM
Re: GUI Graphics: draw a line between two pre-specified points Yasir Khalifa Java 3 06-29-2004 06:20 AM
possible to draw a line between two ImageButton WebControls? n_o_s_p_a__m ASP .Net Web Controls 1 11-26-2003 02:56 AM



Advertisments