Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package csc143.sudoku;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- /**
- * @author Vita Wiebe
- * @version PA8
- * A helper class to make a cell inside a SudokuBoard object.
- */
- class Cell extends JPanel {
- int row;
- int column;
- private boolean clicked;
- private boolean hoveredOver;
- /** Our class constructor.
- * Determines size and shape of Cell object, which has
- * been standardized for the purposes of this assignment.
- * @param int row, used to keep board position.
- * @param int column, used to keep board position.
- */
- public Cell(int row, int column) {
- this.row = row;
- this.column = column;
- setPreferredSize(new Dimension(50, 50));
- add(new JLabel(row + ", " + column));
- setBackground(Color.YELLOW);
- clicked = false;
- hoveredOver = false;
- setOpaque(false);
- setEnabled(true);
- }
- public boolean isSelected() {
- return clicked;
- }
- public boolean isHoveredOver() {
- return hoveredOver;
- }
- public void select() {
- setBackground(Color.YELLOW);
- clicked = true;
- setOpaque(true);
- }
- public void deSelect() {
- clicked = false;
- if(hoveredOver) {
- setOpaque(true);
- setBackground(Color.CYAN);
- } else {
- setOpaque(false);
- }
- }
- public void hoveredOver() {
- hoveredOver = true;
- if(!clicked) {
- setBackground(Color.CYAN);
- }
- setOpaque(true);
- }
- public void notHoveredOver() {
- hoveredOver = false;
- if(!clicked) {
- setOpaque(false);
- }
- }
- /**
- * This method renders one 50x50 "cell" to add to cell array "cells".
- * @param g The Graphics object use to render
- */
- @Override
- public void paintComponent(java.awt.Graphics g) {
- // paint the underlying component
- super.paintComponent(g);
- // set the color of the outline
- g.setColor(Color.BLACK);
- g.drawRect(0, 0, 47, 47);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement