I have to create a 7x7 grid that remains proportionally the same even when resized. Each fibonacci number will have to go in each square in order from top to bottom then resuming back to the top. The numbers must be centered horizontally in each grid square.
I already have the class that allows to create each fibonacci number and I have to use that class into my new class.
public class Fibs {
long n=0;
long myfib;
long last1;
long last2;
public long nextFib(){
if (n == 0){
myfib = n;
last1 = n;
n++;
}
else if (n == 1){
myfib = n;
last2 = n;
n++;
}
else{
myfib = last1 + last2;
last1=last2;
last2 = myfib;
}
return myfib;
}
}
And this is what I have for the applet.. This was supposed to be an introductory programming class and everyone has told me this is far too advanced for intro so any help is appreciated.
import javax.swing.JApplet;
import java.awt.*;
public class DrawFibs extends JApplet {
//create new object
Fibs f = new Fibs ();
//numbers of squares to draw
static final int numBoxes = 7;
public void paint (Graphics page){
//get the dimensions of the page
Rectangle r = page.getClipBounds();
//figure out the number of pixels to skip to make 7x7 squares
int stepX = r.width / numBoxes;
int stepY = r.height / numBoxes;
//converting nextFib method to a string
for (int i=0; i<=48; i++){
String s = String.valueOf(f.nextFib());
//get info about the size of the font in pixels
FontMetrics m = page.getFontMetrics (page.getFont());
//w is the width of the string s in pixels
int w = m.stringWidth(s);
//h is the height of the font in pixels
int h = m.getHeight();
//draw vertical lines
for(int x=0;x<r.width;x+=stepX){
page.drawLine(x, 0, x, r.height);
}
//draw horizontal lines
for(int y=0;y<r.width;y+=stepY){
page.drawLine(0, y, r.width, y);
}
//distribute string
for(int x=0;x<r.width;x+=stepX){
page.drawString(s, r.width/numBoxes, r.height/numBoxes);
}
}
}
}
here is the actual URL to the assignment if I happen to not be explaining it correctly
http://www.cs.utsa.edu/~dj/cs1713-1/hw2/index.html