Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: qustion

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default qustion

    What settings am i supposed to make at function g.drawline() in order to accept real numbers, for example i want to draw a line g.drawline(15.8,7.2,6.4,1225) ) using real numbers


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,302
    Thanks
    181
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: qustion

    Look at the Line2D (Java Platform SE 6) class. It is abstract, but you can retrieve an instance through one of the Line2D.Float or Line2D.Double child classes. They implement the Shape interface, so you can call the g.draw(Shape s) function to draw it (I believe this function only resides in the Graphics2D class, so you must cast your graphics object to a Graphics2D to call it).

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,444
    Thanks
    49
    Thanked 2,218 Times in 2,191 Posts

    Default Re: qustion

    draw a line g.drawline(15.8, 7.2, 6.4, 1225) ) using real numbers
    Interesting concept: partial pixels: .8 of a pixel. How would the hardware handle that?
    Can a pixel only show part of itself? What are the subparts of a pixel?

  4. #4
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: qustion

    The simple solution is to do all your calculations using floats/doubles, then when you're actually drawing cast them to ints.

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,302
    Thanks
    181
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: qustion

    For what its worth, despite being a partial pixel, floating points graphics become quite useful when you need to do more complex drawing such as transforms, bezier curves, etc...