Using While loop to have drawLine redraw
843789Apr 6 2010 — edited Apr 7 2010Hey guys, first post for these forums so thought I'd say hello and howdoyado. Just to let you know I'm currently on week 2 of my Java Programming experience ( self teaching ) and have run into a little wall with a current book I'm read. It is How To Program 7th Edition. I got this book because it is basically a book you would have in a Java class with excersises, tests and chapter summaries and stuff like that at the end of each chapter. Right now I'm on the control statement section of the book and I got it pretty quickly. Not utilizing do...while loops yet or Switch or anything like that, mainly just if, if else and while loops.
Within each section is a small glimpse of graphics programming with the Java language ( which I am most interested in since im an aspiring game programmer, but gonna learn most everything else before learning graphics, another good reason I like this book since it slowly moves what your learning and incorporates that knowledge with small portions of graphics coding ) and then at the end of the chapter the summary gives you test programs to right on your own. The current program giving me headaches is this one.
"Create the design in the left screen capture of Fig. 4.22. Begin by dividing each edge
into an equal number of increments (we chose 15 again). The first line starts in the topleft
corner and ends one step right on the bottom edge. For each successive line, move
down one increment on the left edge and right one increment on the bottom edge. Continue
drawing lines until you reach the bottom-right corner. The figure should scale as
you resize the window so that the endpoints always touch the edges.
b) Modify your answer in part (a) to mirror the design in all four corners, as shown in the
right screen capture of Fig. 4.22."
I've tried this over and over with different styles of while loops using counters, using getHeight and getWidth within the while argument while (width <= height), or while ( counter <= 15 ), as well as trying the whole dividing by 15 increments. I think its just the language of this program test that is getting me confused. I mean I can use g.drawLine to draw squares and triangles just fine, but this while loop things is getting me lol. After 2 hours last night of trying different ways to get the While loop to redraw my lines into patterns I gave up and am now here to see if anyone can help me with it.
I know, long drawn out thing for a simple question. But hey, first post, start with a bang.