|
Hi to all,
I want to draw a curvy line in java. The cuves should be in fixed size. And when mouse draging the curves will be drawn depending on the line length. I should only draw curvy line nothing more. When mouse dragged it will only draw a curvy line by putting args right after each other. check out the image: http://img96.imageshack.us/img96/238/arcdraw5sv.jpg
Any suggestions are greatly appriciated.
thanx.
metan.
|
|
|
I made an app for you that does just what you show in your image. I posted it in reply 4 on your java 2D forum thread. It is made with the idea of flip-flopping a partial arc segment to either side of the path of the mouse. It even draws circles. I reused the code I posted above it to avoid having to start over with everything. The two apps are very different. I left in the construction primitives in case you were interested in understanding/modifying how it was put together.
|
|
|
I am sory mate but, i dont understand what you mean by "construction primitives" can you show how can I use the code for my arc drawing tool? I have circles and stuff, thanx. but how can I modify the code so that i can draw curvy lines?
appriciated.
best regards
metan.
|
|
|
you ve dropped // construction comments in the code, do İ have to modify that lines? if yes how should İ modify them?
|
|
|
They are the points, line and ellipse drawn in this block
if(showConstruction)
{
g2.setPaint(Color.red);
g2.draw(circle);
g2.setPaint(Color.green.darker());
g2.fill(new Ellipse2D.Double(pStart.x-2, pStart.y-2, 4, 4));
g2.fill(new Ellipse2D.Double(pEnd.x-2, pEnd.y-2, 4, 4));
g2.setPaint(Color.blue);
g2.fill(new Ellipse2D.Double(pCenter.x-2, pCenter.y-2, 4, 4));
g2.setPaint(Color.cyan);
g2.draw(line);
}
|
|
inside the paintComponent method.
How to use it in your app? Once you understand how it works you can use/modify the code from flipFlop, getCenter, getAngles and the mouse events for you app. I don't know how you are drawing things in you app so I can't say any more. you ve dropped // construction comments in the code, do Ý have to modify that lines? if yes how should Ý modify them?
No they are just notes to help identify them so you can remove them when you're finished with the construction info.
|
|
|
Well, when i run your code in eclipse, it brushes where mouse is dragged, no arcs or ellipses drawn. So i thought i should modify your code.
In my project I ve a main Frame and in the frame i have a Jpanel where drawing goes, when mouse clicks the necessary drawing button it will draw the selected item. I have rectangle, line, arrowi triangle, and a curvy line button, for example when i click the RECT button, it calls the drawRect(Graphics g) function so that mouse will draw a rectangle, so i will put your code to the drawCurvyLine(Graphics g) function. Well your code, when runned individually it is painting like a brush tool in MSPaint. Thats because i am asking how should i modify the code. Unless you are telling me that your code is putting arcs like my image.
Am i right?
thanx for your helps.
<Added>
Well, when i run your code in eclipse, it brushes where mouse is dragged, no arcs or ellipses drawn. So i thought i should modify your code.
In my project I ve a main Frame and in the frame i have a Jpanel where drawing goes, when mouse clicks the necessary drawing button it will draw the selected item. I have rectangle, line, arrow, triangle, etc.. and a curvy line button, for example when i click the RECT button, it calls the drawRect(Graphics g) function so that mouse will draw a rectangle, so i will put your code to the drawCurvyLine(Graphics g) function. Well your code, -when runned individually-, it is painting like a brush tool in MSPaint. Thats because i am asking how should i modify the code. Unless you are telling me that your code is putting arcs like my image.
Am i right?
thanx for your helps.
|
|
|
when i run your code in eclipse, it brushes where mouse is dragged, no arcs or ellipses drawn
The second code I posted will not do "brush" type drawing like the first one did. Since they both have the same name there must be some old class files from the first one that are being run. I recommend that you delete all source and class files related to the CurvyLines app, copy and paste the second app posted (in reply 4), compile and run as if for the first time. You might even change the names of the classes to avoid trouble. If you see a wide stroke, brush-style of drawing it is the wrong app. The second app will draw lines that look just like the ones in your image.
|
|
|
Thank you very much indeed. it works perfectly.
Very much appriciated.
|
|
|
|
|
|
|
|