Advertisement
Vita_Harvey

Region_C

Feb 4th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.55 KB | None | 0 0
  1. package csc143.sudoku;
  2.  
  3. import javax.swing.*;
  4. import csc143.sudoku.*;
  5. import java.awt.*;
  6. import java.awt.event.*;
  7. /**
  8.  * @author Vita Wiebe
  9.  * @version Feb. 4, 2019
  10.  */
  11.  
  12. /**
  13.  * Designs a JPanel-type object representing a "region" of the Sudoku board.
  14.  * Is used to regulate the shading schemata of the final SudokuBoard object.
  15.  */
  16. public class Region extends JPanel implements SelectedCell  {
  17.    
  18.     // A field to hold a Cell instance while populating Region.
  19.     private Cell cell;
  20.    
  21.    // Our class fields.
  22.     private int rows;
  23.     private int columns;
  24.     private int size;
  25.    
  26.     // selectedRow/Column keep track of the row/column of the currently selected cell object.
  27.     private int selectedRow;
  28.     private int selectedColumn;
  29.    
  30.     private SudokuBase b;
  31.        
  32.    /** Our class constructor.  Designs a Region object of Cells, which will in turn be
  33.     * added to the board to make the overarching schemata of our SudokuBoard.    
  34.     * @param Cell cell.
  35.     */
  36.    public Region(SudokuStub b) {
  37.    
  38.       // Gets the number of rows and columns from the SudokuBase/Stub object.
  39.       rows = b.getRows();
  40.       columns = b.getColumns();
  41.       size = b.getSize();
  42.                    
  43.       // Instantiate b, our SudokuStub/Base/Core object.
  44.       this.b = new SudokuStub(rows, columns);
  45.        
  46.       setLayout(new GridLayout(this.rows, this.columns, 0, 0));
  47.        
  48.       // Iterate thru loops and populate "region" with cells made using
  49.       // our Cell helper class.        
  50.       for (int row = 0; row < rows; row++) {
  51.      
  52.          for (int col = 0; col < columns; col++) {
  53.          
  54.             // make new cell, to be added to "region" JPanel
  55.             Cell cell = new Cell();                                  
  56.             add(cell);              
  57.          }
  58.       }          
  59.    }
  60.    
  61.    /**
  62.     * Set the selected cell to the given row and column.
  63.     * @param row The indicated row
  64.     * @param col The indicated column
  65.     */
  66.    @Override
  67.    public void setSelected(int row, int col) {
  68.       this.selectedRow = row;
  69.       this.selectedColumn = col;
  70.      
  71.    
  72.    }
  73.    
  74.    /**
  75.     * Retrive the row of the currently selected cell.
  76.     * @return The row in which the selected cell is located.
  77.     */
  78.    public int getSelectedRow() {
  79.       return this.selectedRow;
  80.    }  
  81.    
  82.    /**
  83.     * Retrive the column of the currently selected cell.
  84.     * @return The column in which the selected cell is located.
  85.     */
  86.    public int getSelectedColumn(){
  87.       return this.selectedColumn;
  88.    }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement