Solved

drawing multiple lines

Posted on 2004-04-13
4
146 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
4 Comments
 
LVL 92

Accepted Solution

by:
objects earned 20 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
fibonacci ten numbers 4 45
Error in @AspectJ Based AOP with Spring 2 18
hibernate jars 4 45
Desingning Refactoring existing code 2 26
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
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…
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.

791 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