473,395 Members | 1,458 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How can I use a loop to create parallel lines?

I am trying to draw a grid in my panel, but i can't quite figure out the loop to draw the parallel lines.

Thanks
Mar 10 '10 #1
5 6626
jkmyoung
2,057 Expert 2GB
Could you show us the code you're using to draw a single line?
What output are you getting right now?
Mar 10 '10 #2
private void drawgrid(Graphics paper) {
paper.setColor(Color.black); // set the color of walls black


paper.drawLine(50, 50, 250, 50);//draws h line
paper.drawLine(50, 70, 250, 70);//draws h line
paper.drawLine(50, 90, 250, 90);//draws h line
paper.drawLine(50, 110, 250, 110);//draws h line
paper.drawLine(50, 130, 250, 130);//draws h line
paper.drawLine(50, 150, 250, 150);//draws h line
paper.drawLine(50, 170, 250, 170);//draws h line
paper.drawLine(50, 190, 250, 190);//draws h line
paper.drawLine(50, 210, 250, 210);//draws h line
paper.drawLine(50, 230, 250, 230);//draws h line
paper.drawLine(50, 250, 250, 250);//draws h line

paper.drawLine(50, 50, 50, 250);//draws v line
paper.drawLine(70, 50, 70, 250);//draws v line
paper.drawLine(90, 50, 90, 250);//draws v line
paper.drawLine(110, 50, 110, 250);//draws v line
paper.drawLine(130, 50, 130, 250);//draws v line
paper.drawLine(150, 50, 150, 250);//draws v line
paper.drawLine(170, 50, 170, 250);//draws v line
paper.drawLine(190, 50, 190, 250);//draws v line
paper.drawLine(210, 50, 210, 250);//draws v line
paper.drawLine(230, 50, 230, 250);//draws v line
paper.drawLine(250, 50, 250, 250);//draws v line

}
}
Mar 11 '10 #3
sorry the previous message is my code for my parallel lines drawn ine at a time. This returns a grid, but i would like to improve my code with two loops.
Mar 11 '10 #4
jkmyoung
2,057 Expert 2GB
Please use [ code ] [ / code ] tags next time

paper.drawLine(50, 50, 250, 50);//draws h line
paper.drawLine(50, 70, 250, 70);//draws h line
These numbers change, starting from 50, adding 20 at a time, until 250

Replace the bolded parts with an integer variable instead:
Expand|Select|Wrap|Line Numbers
  1. for (int i = 50; i < = 250; i += 20){
  2.   paper.drawLine(50,i, 250,i);//draws h line
  3. }
Similarly do the same thing for the vertical lines.
paper.drawLine(50, 50, 50, 250);//draws v line
paper.drawLine(70, 50, 70, 250);//draws v line
Expand|Select|Wrap|Line Numbers
  1. for (int j = 50; j < = 250; j += 20){
  2.   paper.drawLine(50,j, 250,j);//draws v line
  3. }
If you can keep track, you can even combine the 2!
Expand|Select|Wrap|Line Numbers
  1. for (int i = 50; i < = 250; i += 20){
  2.   paper.drawLine(50,i, 250,i);//draws h line
  3.   paper.drawLine(i,50,i, 250);//draws v line
  4. }
Mar 11 '10 #5
Expand|Select|Wrap|Line Numbers
  1. for(int i=0;i<11;i++)
  2. {
  3.         paper.drawLine(50, 50+i*20, 250, 50+i*20);//draws h line
  4.     paper.drawLine(50+i*20, 50, 50+i*20, 250);//draws v line
  5. }
Mar 11 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: news.hku.hk | last post by:
is there any way to make a loop to store strings?? e.g. abc.txt contains 3 lines i.e. this is line 1. this is line 2. this is line 3. i want to create a loop that can make the three strings...
2
by: smauldin | last post by:
Why does the execution plan have a nested loop join for a simple select with an UDF in the where clause? Here is the query: select * from test_plan where vCol = my_udf('test') Here is the...
9
by: MNQ | last post by:
Hi All I want to use my parallel port of my PC to control some external devices. I am writing a program in ANSI C using the PacificC compiler. What I need to know is how to access the parallel...
32
by: Toby Newman | last post by:
At the page: http://www.strath.ac.uk/IT/Docs/Ccourse/subsection3_8_3.html#SECTION0008300000000000000 or http://tinyurl.com/4ptzs the author warns: "The for loop is frequently used, usually...
8
by: Terry Olsen | last post by:
How do I loop back to the beginning of a for/next loop before getting to the end of it? Isn't there an "iterate" command or something like that? For Each This in That ...code if This = False...
11
by: lovecreatesbeauty | last post by:
For example, line L1 and line L2 are two lines in two-dimensional space, the start-points and end-points can be described with following the `point_t' type. The start-points and end-points are:...
1
by: 2stepme | last post by:
I know I should be using a database ... but ... I have created a few pages which store user data in text files. The user text files where created using session_encode. There is a text file for...
43
by: parallelpython | last post by:
Has anybody tried to run parallel python applications? It appears that if your application is computation-bound using 'thread' or 'threading' modules will not get you any speedup. That is because...
1
by: Doug_J_W | last post by:
I have a Visual Basic (2005) project that contains around twenty embedded text files as resources. The text files contain two columns of real numbers that are separated by tab deliminator, and are...
5
by: George Sakkis | last post by:
I'm looking for any existing packages or ideas on how to implement the equivalent of a generator (in the Python sense, i.e. http://www.python.org/dev/peps/pep-0255/) in a parallel/distributed way....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.