import java.awt.*;
import javax.swing.*;
public class RushPanelRx extends JPanel {
Board myBoard;
RushPanelRx(Board board) {
myBoard = board;
}
// Overriding this method is easier for custom drawing.
protected void paintComponent(Graphics g) {
super.paintComponent(g);
double yInc = (double)(myBoard.getHeight()-1)/Board.NOOFROWS;
for (int row = 0; row <= Board.NOOFROWS; row ++) {
int y = (int)(row * yInc);
g.drawLine(0, y, myBoard.getWidth(), y);
}
double xInc = (double)(myBoard.getWidth()-1)/Board.NOOFCOLS;
for (int col = 0; col <= Board.NOOFROWS; col++) {
int x = (int)(col * xInc);
g.drawLine(x, 0, x, myBoard.getHeight());
}
}
public static void main(String[] args) {
Board board = new Board(300, 300);
RushPanelRx rushPanel = new RushPanelRx(board);
JFrame f = new JFrame("The Rush Hour Game");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(rushPanel);
f.setSize(350, 350);
f.setVisible(true);
}
}
class Board {
public static final int NOOFROWS = 6;
public static final int NOOFCOLS = 6;
int width;
int height;
Board(int width, int height) {
this.width = width;
this.height = height;
}
public int getWidth() { return width; }
public int getHeight() { return height; }
}