Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

X and Y coordinates for drawing lines on applet

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an applet. I am drawing lines on it. The code of my applet is as follows:

I want to make the ending X and Y coordinates of each line as starting X and Y coordinates of the next line. In this way I would be able to draw a continuous line on applet. I am stuck on this issue. Somebody can help me to resolve it. Thanks
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are many ways of doing this, probably the easiest and certainly the least elegant is to just set the start coordinates of each line to the appropriate value ie:

A better way would to have an array of single X,Y co-ordinates ie
Then iterate over the array the array length - 1 times using the current index as the start X, Y coordinate and the current index + 1 as the end X, Y coordinate.
 
Anam Zahra
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried a lot but unable to find a way to get the solution.
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry but I've no idea what that code is supposed to do or how it relates to your original question. Has your question changed?

I've noticed in both your posts your code has a nested for loop with the inner for loop iterating exactly once. You can remove the inner for loop as it isn't doing anything other than adding confusion.

 
All that thinking. Doesn't it hurt? What do you think about this tiny ad?
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic