?
Solved

drawing multiple lines

Posted on 2004-04-13
4
Medium Priority
?
170 Views
Last Modified: 2010-03-31
hi,
i'm trying to draw lines at different locations. what i want is assistance on whther i should use a loop to do that. the x,y coordinates will be randomly picked. any sites or codes that might assist would be greatly appreciated
0
Comment
Question by:Kalliba
2 Comments
 
LVL 92

Accepted Solution

by:
objects earned 80 total points
ID: 10817553
yes use a loop

for (int i=0; i<100; i++)
{
   int x1 = ...;
   int y1 = ...;
   int x2 = ...;
   int y2 = ...;
   g.drawLine(x1, y1, x2, y2);
}
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10817582
You could try something like:

final int DELTA_X = 20;
int numLines = 5;
int height = getHeight();
for(int i = 0;i < numLines;i++) {
      int x = 0;
      int y = (int)(Math.random() * height);
      g.drawLine(x, y, x + deltaX, y);
}
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month14 days, 15 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question