Results 1 to 8 of 8
Thread: How to Draw a 'Line'...
- 06-12-2012, 07:05 PM #1
How to Draw a 'Line'...
Just as the title says, I'm wondering how I could draw a line in Java, and by drawing a line, I don't mean a Line2D.Double object in the paint class. I'm talking about literally drawing a line with the mouse, like you would in Microsoft Paint.
I was thinking about making an array of Rectangle2D.Double objects and then playing their x and y locations to where the mouse travels every 500 milliseconds.. Whenever I do this, though, the rectangle continuously just shows up over my mouse and doesn't leave a trail whatsoever.
Any ideas how you would approach this issue?
- 06-12-2012, 07:10 PM #2
Re: How to Draw a 'Line'...
There are a number of ways to do this. Save the point when you click, save the point when you release, and draw a line between the points. Or when you drag, save the previous mouse position, then draw a line from the previous mouse position to the current, and set previous equal to current. Or just draw points wherever you drag.
Which approach you take (and there are still others) depends on the exact effect you're going for. What's wrong with the Line2D.Double class?How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 06-12-2012, 07:10 PM #3
Re: How to Draw a 'Line'...
I moved this thread to the Java2D forum for closer topic alignment.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 06-12-2012, 10:10 PM #4
Re: How to Draw a 'Line'...
It's not necessary drawing a straight line, which is one coordinate to another, it's giving the user the ability to draw where the user drags the mouse to make a line, any line, squiggly, zigzag, etc, like this picture below:
But I initially got it to work, the problem was I was declaring new Rectangle2D.Double objects as the mouse moves IN the paint class.. while I was initially supposed to do it out of the class, and then paint all the rectangles according to their coordinates afterwards.
Good thing is it's working now though, thanks for the assistance!
- 06-13-2012, 01:45 PM #5
Re: How to Draw a 'Line'...
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 06-13-2012, 09:17 PM #6
Re: How to Draw a 'Line'...
Why do they call it rush hour when nothing moves? - Robin Williams
- 06-13-2012, 10:13 PM #7
Re: How to Draw a 'Line'...
Could you explain how, or show an example involving how to use Path2D.Double objects? It's sounds like it'd probably cover the problems I'm likely to have to deal with my algorithm
- 06-14-2012, 02:35 PM #8
Re: How to Draw a 'Line'...
How about you take a stab at it and see what happens, then post an SSCCE if you get stuck? How are you using Rectangle2D now? I would predict you're just using it to get at two endpoints, which Line2D already has.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
Similar Threads
-
How to draw a line?
By Lund01 in forum New To JavaReplies: 9Last Post: 10-27-2011, 06:09 PM -
How to draw line with animation
By hnchnc in forum Java 2DReplies: 1Last Post: 11-18-2010, 10:49 PM -
Draw line
By janes in forum Java 2DReplies: 6Last Post: 03-25-2010, 10:48 PM -
Draw more than one line on run time
By aiman in forum Java AppletsReplies: 3Last Post: 12-10-2009, 02:44 AM -
How to draw a thick line
By johnt in forum Java 2DReplies: 1Last Post: 05-31-2007, 04:27 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks