Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package csc143.sudoku;
- import javax.swing.*;
- import csc143.sudoku.*;
- import java.awt.*;
- import java.awt.event.*;
- /**
- * @author Vita Wiebe
- * @version Feb. 4, 2019
- */
- /**
- * Designs a JPanel-type object representing a "region" of the Sudoku board.
- * Is used to regulate the shading schemata of the final SudokuBoard object.
- */
- public class Region extends JPanel implements SelectedCell {
- // A field to hold a Cell instance while populating Region.
- private Cell cell;
- // Our class fields.
- private int rows;
- private int columns;
- private int size;
- // selectedRow/Column keep track of the row/column of the currently selected cell object.
- private int selectedRow;
- private int selectedColumn;
- private SudokuBase b;
- /** Our class constructor. Designs a Region object of Cells, which will in turn be
- * added to the board to make the overarching schemata of our SudokuBoard.
- * @param Cell cell.
- */
- public Region(SudokuStub b) {
- // Gets the number of rows and columns from the SudokuBase/Stub object.
- rows = b.getRows();
- columns = b.getColumns();
- size = b.getSize();
- // Instantiate b, our SudokuStub/Base/Core object.
- this.b = new SudokuStub(rows, columns);
- setLayout(new GridLayout(this.rows, this.columns, 0, 0));
- // Iterate thru loops and populate "region" with cells made using
- // our Cell helper class.
- for (int row = 0; row < rows; row++) {
- for (int col = 0; col < columns; col++) {
- // make new cell, to be added to "region" JPanel
- Cell cell = new Cell();
- add(cell);
- }
- }
- }
- /**
- * Set the selected cell to the given row and column.
- * @param row The indicated row
- * @param col The indicated column
- */
- @Override
- public void setSelected(int row, int col) {
- this.selectedRow = row;
- this.selectedColumn = col;
- }
- /**
- * Retrive the row of the currently selected cell.
- * @return The row in which the selected cell is located.
- */
- public int getSelectedRow() {
- return this.selectedRow;
- }
- /**
- * Retrive the column of the currently selected cell.
- * @return The column in which the selected cell is located.
- */
- public int getSelectedColumn(){
- return this.selectedColumn;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement