Hi all, I am attempting to create a pool of water graphic (divided into 9 equal parts (ie. 3x3 grid)) for a fishing game and would like to know how I would go about applying a grid to the space so I can refer to any of the 9 spaces.
Code:import java.awt.*; import javax.swing.JFrame; import javax.swing.JPanel; public class Pool extends JFrame { public Pool() { setTitle("Carpet Fishing Game"); getContentPane().add(new FishingPanel()); } public static void main(String[] args) { Pool frame = new Pool(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(500,500); frame.setVisible(true); } } class FishingPanel extends JPanel { protected void paintComponent(Graphics g) { super.paintComponent(g); Color water = new Color (0, 100, 200); g.setColor (water); g.fillRect(100, 100, 300, 300); } }




Reply With Quote