Results 1 to 4 of 4
  1. #1
    buggedup is offline Member
    Join Date
    Apr 2011
    Posts
    19
    Rep Power
    0

    Default Draw a line in resolution independent way

    Hello!!

    I have to draw a line in resolution independent way using abstract coordinate system.
    I am using the following and also able to draw a line.
    void drawLine(int inStartX, int inStartY, int inEndX, int inEndY).
    But, I am supposed to pass all the parameters ranging between 0.0 to 1.0.

    Please help ASAP.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default

    Compute inStartX, inStartY, inEndX, inEndY based on resolution.

    To get better help sooner, post a SSCCE that clearly demonstrates your problem.

    Use code tags to post codes -- [code]CODE[/code] will display as
    Java Code:
    CODE
    Or paste your code between a pair of {code} tags.

    db

  3. #3
    buggedup is offline Member
    Join Date
    Apr 2011
    Posts
    19
    Rep Power
    0

    Default

    Code

    public void mypaint()
    {
    Graphics g;
    drawLine(0,0,248,100);
    }

    Code

    I have a mypaint method in a predefined class file. drawline has 4 integer parameters in the class file. I am not quite able to figure out how to do this in the abstract co-ordinate system

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,000
    Blog Entries
    7
    Rep Power
    20

    Default

    Read the API documentation for the Graphics2D class; that's the type of the object passed to your paintComponent(Graphics g) method; all you have to do is cast the parameter g to the Graphcs2D type and scale your coordinates appropriately.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. How to draw line with animation
    By hnchnc in forum Java 2D
    Replies: 1
    Last Post: 11-18-2010, 10:49 PM
  2. Draw line
    By janes in forum Java 2D
    Replies: 6
    Last Post: 03-25-2010, 10:48 PM
  3. Draw more than one line on run time
    By aiman in forum Java Applets
    Replies: 3
    Last Post: 12-10-2009, 02:44 AM
  4. How to Draw line in Java
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-22-2008, 11:08 PM
  5. How to draw a thick line
    By johnt in forum Java 2D
    Replies: 1
    Last Post: 05-31-2007, 04:27 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •