How to set up a simple grid based game board in java?

WrZ

New Member
I'm currently learning Swing and thought making a game would make the process more interesting for me. I have my JFrame all set up with menu and tool bars, but now I'm constructing a JPanel to serve as the play area, in this case I'd like to make a grid. I can draw one on the panel easily enough using:\[code\]protected void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(Color.black); for(int x = 0 ; x <= getWidth() ; x += 16 ) { g.drawLine( x , 0 , x , getHeight() ); } g.setColor(Color.black); for(int y = 0 ; y <= getHeight() ; y += 16 ) { g.drawLine( 0 , y , getWidth() , y );\[/code\]But this has limited use later on if I want to accurately place and move images on the board. Is there another way I can draw a grid, perhaps using arrays? Just trying to make a clean layout before I dive into interactivity, and would appreciate any advice. Thanks!
 
Back
Top