Drawing the dash line


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Drawing the dash line

  1. #1
    frankmail007 Guest

    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

  2. #2
    Moppy Guest

    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.y-b.y)/Math.abs(a.x-b.x);
    int delx = Math.abs(a.x-b.x)/Math.abs(a.y-b.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



  3. #3
    Moppy Guest

    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.y-b.y)/Math.abs(a.x-b.x);
    > int delx = Math.abs(a.x-b.x)/Math.abs(a.y-b.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

    >



  4. #4
    frankmail007 Guest

    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.y-b.y)/Math.abs(a.x-b.x);
    >> int delx = Math.abs(a.x-b.x)/Math.abs(a.y-b.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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

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