Name: Anonymous 2010-03-13 11:50
How do i make this look like a grid using nested loops?
Fuck, this is pissing me off.
import java.awt.*;
import javax.swing.*;
public class Week1GraphicsQ6 extends JFrame
{
public static void main(String[] args)
{
Week1GraphicsQ6 w = new Week1GraphicsQ6();
w.setVisible(true);
}
public Week1GraphicsQ6()
{
setTitle("fgdgs");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(500,220);
setLocation(300,300);
getContentPane().setBackground(Color.green);
}
int numCols=9;
int numRows=8;
Rectangle getRect(int thisRow, int thisCol)
{
Insets myInsets = getInsets();
int display_left = myInsets.left;
int display_top= myInsets.top;
int display_width = getWidth() - myInsets.left - myInsets.right;
int display_height = getHeight() - myInsets.top - myInsets.bottom;
Rectangle myRectangle=new Rectangle ();
myRectangle.width= display_width/numCols;
myRectangle.height= display_width/numRows;
myRectangle.x = myRectangle.width*thisCol;
myRectangle.y = myRectangle.height*thisRow;
return myRectangle;
}
public void paint(Graphics g)
{
Insets myInsets = getInsets();
int display_left = myInsets.left;
int display_top= myInsets.top;
int display_width = getWidth() - myInsets.left - myInsets.right;
int display_height = getHeight() - myInsets.top - myInsets.bottom;
Rectangle r = getRect(1,3);
Graphics2D g2 = (Graphics2D)g;
super.paint(g2);
g2.drawRect(r.x, r.y,r.width,r.height);
Rectangle r1 = getRect(2,3);
g2.drawRect(r1.x, r1.y,r1.width,r1.height);
Rectangle r2 = getRect(3,3);
g2.drawRect(r2.x, r2.y,r2.width,r2.height);
Rectangle r3 = getRect(4,3);
g2.drawRect(r3.x, r3.y,r3.width,r3.height);
}
}
Fuck, this is pissing me off.
import java.awt.*;
import javax.swing.*;
public class Week1GraphicsQ6 extends JFrame
{
public static void main(String[] args)
{
Week1GraphicsQ6 w = new Week1GraphicsQ6();
w.setVisible(true);
}
public Week1GraphicsQ6()
{
setTitle("fgdgs");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(500,220);
setLocation(300,300);
getContentPane().setBackground(Color.green);
}
int numCols=9;
int numRows=8;
Rectangle getRect(int thisRow, int thisCol)
{
Insets myInsets = getInsets();
int display_left = myInsets.left;
int display_top= myInsets.top;
int display_width = getWidth() - myInsets.left - myInsets.right;
int display_height = getHeight() - myInsets.top - myInsets.bottom;
Rectangle myRectangle=new Rectangle ();
myRectangle.width= display_width/numCols;
myRectangle.height= display_width/numRows;
myRectangle.x = myRectangle.width*thisCol;
myRectangle.y = myRectangle.height*thisRow;
return myRectangle;
}
public void paint(Graphics g)
{
Insets myInsets = getInsets();
int display_left = myInsets.left;
int display_top= myInsets.top;
int display_width = getWidth() - myInsets.left - myInsets.right;
int display_height = getHeight() - myInsets.top - myInsets.bottom;
Rectangle r = getRect(1,3);
Graphics2D g2 = (Graphics2D)g;
super.paint(g2);
g2.drawRect(r.x, r.y,r.width,r.height);
Rectangle r1 = getRect(2,3);
g2.drawRect(r1.x, r1.y,r1.width,r1.height);
Rectangle r2 = getRect(3,3);
g2.drawRect(r2.x, r2.y,r2.width,r2.height);
Rectangle r3 = getRect(4,3);
g2.drawRect(r3.x, r3.y,r3.width,r3.height);
}
}