diff --git a/src/game/GameBoardTable.java b/src/game/GameBoardTable.java new file mode 100644 index 0000000000000000000000000000000000000000..60240495cb23a5dcc18e5a625735fb961f7f1eb4 --- /dev/null +++ b/src/game/GameBoardTable.java @@ -0,0 +1,17 @@ +package game; + +import javax.swing.*; +import javax.swing.table.TableModel; + +public class GameBoardTable extends JTable { + public GameBoardTable (TableModel model){ + super(model); + + int height = getRowHeight(); + for (int i = 0; i<model.getColumnCount(); i++){ + getColumnModel().getColumn(i).setPreferredWidth(height); + } + + setDefaultRenderer(Boolean.class, new GameCellRenderer()); + } +} diff --git a/src/game/GameCellRenderer.java b/src/game/GameCellRenderer.java new file mode 100644 index 0000000000000000000000000000000000000000..a86c3912d74b1c026be56c32f905d15ca370a042 --- /dev/null +++ b/src/game/GameCellRenderer.java @@ -0,0 +1,29 @@ +package game; + +import javax.swing.*; +import javax.swing.table.TableCellRenderer; +import java.awt.*; + +public class GameCellRenderer implements TableCellRenderer { + private TableCellRenderer defaultRenderer; + + public GameCellRenderer() { + defaultRenderer = new JTable().getDefaultRenderer(Object.class); + } + + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, + boolean hasFocus, int row, int column) { + + Component component = defaultRenderer.getTableCellRendererComponent(table, null, + false, false, row, column); + + + if ((boolean) table.getValueAt(row, column)) { + component.setBackground(Color.DARK_GRAY); + } else { + component.setBackground(Color.WHITE); + } + + return component; + } +} diff --git a/src/game/GameModel.java b/src/game/GameModel.java index d1b14428a067ee8e1a2f3738afd1aebb36909dee..dafc77e31d890684eb84c186f92e515109ca98fa 100644 --- a/src/game/GameModel.java +++ b/src/game/GameModel.java @@ -72,7 +72,6 @@ public class GameModel extends AbstractTableModel { public void setValueAt(Object aValue, int rowIndex, int columnIndex) { board.get(rowIndex, columnIndex).setAlive((boolean) aValue); - } public void step() { diff --git a/src/game/GameWindow.java b/src/game/GameWindow.java index 33c718275f8093a7a683c6a376cbdbd092ea61b4..d184d4d99a29b19d6dfbb158017a85130d160dc6 100644 --- a/src/game/GameWindow.java +++ b/src/game/GameWindow.java @@ -7,6 +7,8 @@ import java.awt.*; public class GameWindow extends JFrame { + //TODO JMenu + private GameModel model; private JTable table; JFileChooser fileChooser; @@ -14,18 +16,14 @@ public class GameWindow extends JFrame { public GameWindow(GameModel model){ super("Game of Life"); this.model = model; - table = new JTable(model); + table = new GameBoardTable(model); fileChooser = new JFileChooser(); FileFilter filter = new FileNameExtensionFilter("JSON File (.json)", "json"); fileChooser.setFileFilter(filter); - //table.setPreferredSize(new Dimension(300, 300)); //TODO igazodjon a táblához setLayout(new BorderLayout()); add(table, BorderLayout.CENTER); - //setSize(300, 300); TODO törölni - - JPanel bottomPanel = new JPanel(); JButton startButton = new JButton("Start"); JButton stopButton = new JButton("Stop");