codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Drawing curvy line by Arcs  metan at 10:03 on Monday, March 27, 2006
 

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.


  Re: Drawing curvy line by Arcs  crwood at 16:38 on Monday, March 27, 2006
 

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.

  Re: Drawing curvy line by Arcs  metan at 05:43 on Tuesday, March 28, 2006
 

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.

  Re: Drawing curvy line by Arcs  metan at 05:47 on Tuesday, March 28, 2006
 

you ve dropped // construction comments in the code, do İ have to modify that lines? if yes how should İ modify them?



  Re: Drawing curvy line by Arcs  crwood at 05:54 on Tuesday, March 28, 2006
 

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.

  Re: Drawing curvy line by Arcs  metan at 06:43 on Tuesday, March 28, 2006
 

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.

  Re: Drawing curvy line by Arcs  crwood at 07:39 on Tuesday, March 28, 2006
 

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.

  Re: Drawing curvy line by Arcs  metan at 11:05 on Tuesday, March 28, 2006
 

Thank you very much indeed. it works perfectly.
Very much appriciated.








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: Problem to declare global variable in Object oriented perl
•  Re: dereferenceing a string to a constant name
•  Re: Submit multiple forms with one button
•  Re: Passing Password using $ssh->cmd
•  Re: ADODB.Recordset error (0x800A0CB3)
•  Re: Open a Modal Pop Up From a LinkButton In a GridView
•  Re: Need Javascript Multiple sidebar menu with sliding effects
•  Re: ASP.NET /Excel opening in frame Issue
•  Re: `section` is an unexpected token. Expecting white space. Line 1, position 137.


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2010