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
5 6626
Could you show us the code you're using to draw a single line?
What output are you getting right now?
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
}
}
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.
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: - for (int i = 50; i < = 250; i += 20){
-
paper.drawLine(50,i, 250,i);//draws h line
-
}
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 - for (int j = 50; j < = 250; j += 20){
-
paper.drawLine(50,j, 250,j);//draws v line
-
}
If you can keep track, you can even combine the 2! - for (int i = 50; i < = 250; i += 20){
-
paper.drawLine(50,i, 250,i);//draws h line
-
paper.drawLine(i,50,i, 250);//draws v line
-
}
- for(int i=0;i<11;i++)
-
{
-
paper.drawLine(50, 50+i*20, 250, 50+i*20);//draws h line
-
paper.drawLine(50+i*20, 50, 50+i*20, 250);//draws v line
-
}
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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:...
|
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...
|
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...
|
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...
|
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....
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |