Created
June 11, 2023 18:31
-
-
Save odds-get-evened/74ef78ac04a0df28cbaa92a2db3aa526 to your computer and use it in GitHub Desktop.
Grid Window
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.mintaka5.ui; | |
import javax.swing.*; | |
import java.awt.*; | |
public class GridWindow extends JFrame { | |
private final int[][] theGrid; | |
private int[] dimensions = {10, 10}; | |
public GridWindow(int[][] randGrid, int[] dims) { | |
super("grids"); | |
theGrid = randGrid; | |
dimensions = dims; | |
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
setDefaultLookAndFeelDecorated(true); | |
setLocationByPlatform(true); | |
setLayout(new BorderLayout()); | |
add(new IslandsGridPanel(), BorderLayout.CENTER); | |
setSize(1024, 640); | |
setVisible(true); | |
} | |
private class IslandsGridPanel extends JPanel { | |
public IslandsGridPanel() { | |
} | |
public void paint(Graphics g) { | |
g.setColor(Color.BLUE); | |
for(int i=0; i<theGrid.length; i++) { | |
for(int j=0; j<theGrid[i].length; j++) { | |
if(theGrid[i][j] == 1) g.setColor(Color.GREEN); | |
else g.setColor(Color.BLUE); | |
int x = i*dimensions[0]; | |
int y = j*dimensions[1]; | |
g.fillRect(x, y, dimensions[0], dimensions[1]); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment