public class PictureYourSolution
extends java.lang.Object
| Modifier and Type | Field | Description |
|---|---|---|
private static int |
BEST_PANEL_HEIGHT |
The optimal panel height for the header
|
private static int |
COLS |
The number of columns on the chess board
|
private static java.awt.Color |
DARK_BLUE |
A custom dark blue color to be used for the qs and the header
|
private static java.awt.Color |
DARK_COLOR |
The dark color for the chess board (my custom marigold color)
|
private javax.swing.JPanel |
grid |
The grid panel
|
private javax.swing.JPanel |
header |
The header panel
|
private static java.awt.Color |
HEADER_COLOR |
The color of the header (my custom dark blue color)
|
private static java.lang.String |
HEADER_TEXT |
The de facto title that will be printed on the header JLabel
|
private javax.swing.JLabel |
headerText |
The text to be written on the header
|
private static int |
HEIGHT |
The height of the JFrame
|
private static java.awt.Color |
LIGHT_COLOR |
The light color for the chess board
|
private static java.awt.Color |
MARIGOLD |
The color of the chess square panels that will be put on the chess board - also
just a lovely yellow color
|
private static int |
MAX_PANEL_HEIGHT |
The maximum panel height for the header
|
private static int |
MIN_PANEL_HEIGHT |
The minimum panel height for the header
|
private static java.awt.Font |
PANEL_FONT |
The custom font to be used in the panels
|
private static java.awt.Color |
PANEL_TEXT_COLOR |
The text color to be used on the panel
|
private boolean[][] |
queens |
A boolean array of queens that will be keep track of the current solution in
terms of a boolean array, rather than a Queen[]
|
private static int |
ROWS |
The number of rows on the chess board
|
private ChessSquarePanel[][] |
squares |
A 2d array of ChessSquarePanels which will display the chess board
|
private static java.lang.String |
TITLE |
The title for the board
|
private static int |
WIDTH |
The width of the JFrame
|
private javax.swing.JFrame |
window |
The window in which all the graphical components will be held
|
| Constructor | Description |
|---|---|
PictureYourSolution(boolean[][] qs) |
Creates a PictureYourSolution object with a boolean[][] of queens that
should represent a viable solution.
|
| Modifier and Type | Method | Description |
|---|---|---|
private void |
buildFrame() |
Builds the JFrame window to be used including setting its size and layout
|
private javax.swing.JPanel |
buildGridPanel() |
Builds and returns the grid panel representing the chess board using
the queens field.
|
private javax.swing.JPanel |
buildHeaderPanel() |
Builds and returns a viable headerPanel including instantiating one, setting size and
background color, creating and setting the fields of a JPanel, then adding that JPanel in.
|
private java.awt.Color |
getRightColor(int r,
int c) |
Returns which color should be used for each square on the chess board
using the row and column of that square
|
private boolean |
getRightFlag(int r,
int c) |
Returns whether this square should have a queen on it or not
depending on the information in the queens array.
|
static void |
main(java.lang.String[] args) |
|
private static boolean[][] |
mySolution() |
A private method that simply creates a boolean array that represents the first solution that
I found, which was found without using a computer program.
|
static boolean[][] |
queenToBooleanArray(java.util.ArrayList<Queen> queens) |
Converts a Queen ArrayList to a boolean array.
|
void |
resetHeader(java.lang.String hText) |
Resets the header text using the passed-in hText
|
void |
resetSquares(boolean[][] qs) |
Resets the chess board squares using queens, which represents a different solution.
|
void |
setVisibility(boolean visible) |
Sets the window panel's visibility
|
private static final java.awt.Color MARIGOLD
private static final java.awt.Color DARK_BLUE
private static final int ROWS
private static final int COLS
private static final int HEIGHT
private static final int WIDTH
private static final java.awt.Color LIGHT_COLOR
private static final java.awt.Color DARK_COLOR
private static final java.awt.Color HEADER_COLOR
private static final java.awt.Font PANEL_FONT
private static final int MIN_PANEL_HEIGHT
private static final int MAX_PANEL_HEIGHT
private static final int BEST_PANEL_HEIGHT
private static final java.lang.String HEADER_TEXT
private static final java.awt.Color PANEL_TEXT_COLOR
private static final java.lang.String TITLE
private javax.swing.JFrame window
private javax.swing.JPanel header
private javax.swing.JPanel grid
private javax.swing.JLabel headerText
private ChessSquarePanel[][] squares
private boolean[][] queens
PictureYourSolution(boolean[][] qs)
qs - the solution to be displayedpublic void setVisibility(boolean visible)
visible - if true, sets the JFrame to visible, else makes it disappearpublic void resetSquares(boolean[][] qs)
qs - the new solution to be displayed, represented as a boolean 2d arraypublic void resetHeader(java.lang.String hText)
hText - the new text to set the header toprivate void buildFrame()
private javax.swing.JPanel buildHeaderPanel()
private javax.swing.JPanel buildGridPanel()
private java.awt.Color getRightColor(int r,
int c)
r - the row of the square in questionc - the column of the square in questionprivate boolean getRightFlag(int r,
int c)
r - the row in questionc - the column in questionprivate static boolean[][] mySolution()
public static boolean[][] queenToBooleanArray(java.util.ArrayList<Queen> queens)
queens - the Queen ArrayList to be convertedpublic static void main(java.lang.String[] args)