public class SudokuGUI
extends javax.swing.JFrame
implements java.awt.event.KeyListener, javax.sound.sampled.LineListener
javax.swing.JFrame.AccessibleJFrame
java.awt.Window.AccessibleAWTWindow, java.awt.Window.Type
Modifier and Type | Field and Description |
---|---|
private static java.awt.Color |
BG_COLOR_DARK |
private static java.awt.Color |
BG_COLOR_DARK_ACCESS |
private static java.awt.Color |
BG_COLOR_LIGHT |
private static java.awt.Color |
BG_COLOR_LIGHT_ACCESS |
private static java.awt.Color |
BORDER_COLOR |
private static java.awt.Color |
BORDER_COLOR_DARK_ACCESS |
private static java.awt.Color |
BORDER_COLOR_LIGHT_ACCESS |
private java.awt.Color |
borderColorDark
Border color of the light squares in accessibility mode.
|
private java.awt.Color |
borderColorLight
Border color of the dark squares in accessibility mode.
|
private boolean |
contrast
Show accessibility mode.
|
private java.awt.Color |
darkBgColor
Background color of the dark squares.
|
private java.awt.Color |
darkFgColor
Foreground color of the dark squares.
|
private java.awt.Font |
defaultTooltipFont
The font used to display tooltips
|
private int |
difficulty
Number of empty cells at startup.
|
private Element[][] |
elements
Array of all element cells ordered from the upper left to the lower right
|
private int |
elementsInRow
Number of rows or columns in the entire game.
|
private SudokuEngine |
engine
The business logic
|
private int |
faktor
Used to scale font and gui by the application's options dialog's slider.
|
private static java.awt.Color |
FG_COLOR |
private static java.awt.Color |
FG_COLOR_DARK_ACCESS |
private static java.awt.Color |
FG_COLOR_LIGHT_ACCESS |
private int |
fontScale
Scales the font and border size.
|
private int |
fontWeight
Default font weight of the entered numbers
|
private int |
gameElements
Number of elements in the entire game.
|
private static java.awt.Color |
HIGHLIGHT_BG_COLOR |
private boolean |
hintMode
The game's mode,
true if the hint mode is enabled otherwise
false . |
private javax.swing.ImageIcon |
icon
The program icon
|
private boolean |
isSpeechPlayable
Play a voice output if
true . |
private boolean |
isSuccessSoundPlayable
Play a sound when finishing the game successfully
|
private java.awt.Color |
lightBgColor
Background color of the light squares.
|
private java.awt.Color |
lightFgColor
Foreground color of the light squares.
|
private PrintablePanel |
mainPanel
A printable
JPanel |
private static java.awt.Color |
MISTAKE_BG_COLOR |
private static java.awt.Color |
MISTAKE_BG_COLOR_ACCESS |
private static java.awt.Color |
MISTAKE_FG_COLOR |
private static java.awt.Color |
MISTAKE_FG_COLOR_ACCESS |
private int |
mistakeDelay
Milliseconds a mistake is highlighted before resetting the display to the
default appearance after entering a wrong number.
|
private boolean |
mistakeHint
Give a hint if a false number is entered.
|
private int |
mistakes
Count the number of mistakes to display it on the status bar.
|
private PropertiesManager |
pm
The configuration settings are stored in properties.
|
private int |
squareRowElements
Number of cells in a square's row or column.
|
private StatusBar |
statusBar
The game's status bar
|
accessibleContext, EXIT_ON_CLOSE, rootPane, rootPaneCheckingEnabled
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Constructor and Description |
---|
SudokuGUI() |
Modifier and Type | Method and Description |
---|---|
private void |
checkForMistake(Element el,
byte value)
Checks in
b exists in row, column or square to which
el belongs. |
private void |
clearHintLabels()
Clears all hint labels
|
(package private) boolean |
getContrast()
Provides the current contrast settings.
|
int |
getDifficulty() |
Element[][] |
getElements() |
int |
getElementsInRow() |
SudokuEngine |
getEngine() |
int |
getFaktor() |
(package private) int |
getFilledCellsCount()
Counts the number of cells filled with digits.
|
(package private) int |
getFontWeight() |
(package private) java.lang.String |
getMistakeDelay() |
(package private) boolean |
getMistakeHint()
Provides the current mistake hint settings.
|
(package private) boolean |
getSpeechPlayable() |
int |
getSquareRowElements() |
(package private) boolean |
getSuccessSoundPlayable() |
void |
handleInput(Element el)
Coordinates the number handling of an element.
|
private void |
handleMistake(Element el)
Activates a timer, that schedules the reset of the gui after showing a
mistake.
|
(package private) void |
help()
Manages the activity of the help button.
|
private void |
highlightMistake(int row,
int col,
int quad,
int mistake,
int value)
Responsible for the highlighting of the participating row/col/square if a
mistake occurs.
|
void |
highlightNumber(java.lang.String number)
Searches for all occurences of
number and highlights its
background. |
private void |
initGUI()
Creates and initializes the gui
|
private void |
initMainPanel()
Creates the main panel of the game.
|
private void |
initMenubar()
Create a menuBar
|
(package private) void |
initNewSudoku()
Create a new Sudoku game
|
private void |
initStatusBar()
Create a status bar
|
void |
keyPressed(java.awt.event.KeyEvent e) |
void |
keyReleased(java.awt.event.KeyEvent e)
Event-Handling
|
void |
keyTyped(java.awt.event.KeyEvent arg0) |
(package private) void |
load()
Reloads a previously saved Sudoku from
Config.CONFIG_DIR which is
saved in a hidden file Config.SAVE_FILE . |
private void |
loadProperties()
Loads the game's properties from the configuration file.
|
private boolean |
makeConfigFile()
Creates a file to save the settings of the game
|
private void |
manageHints(int row,
int col,
int quad,
int value)
If a digit already occures in an elements hint text remove it.
|
(package private) void |
playSound(java.lang.String soundFile)
Play
soundFile when a digit is enterd or the game is
finished successfully |
void |
print()
Prints the current state of the game's
mainPanel as image. |
(package private) void |
reloadElementFont()
Reloads the font of all elements if the component is resized or the
font-weight has changed.
|
(package private) void |
resizeGUI(int faktor)
Resizes the gui depending on
faktor . |
(package private) void |
save()
Saves the current state of the game in
Config.SAVE_FILE located in the sudoku's
configuration directory. |
private void |
setComponentSizeAndPosition(javax.swing.JFrame frame)
Sets the component's size depending on
faktor and centers it on
the screen. |
void |
setContrast(boolean selected)
Set the accessible mode with high contrast
|
(package private) void |
setDifficulty(int difficulty)
Sets the
difficulty of the game |
void |
setElementsDefaultColors()
Controlls the changing of the 9 square's background color.
|
(package private) void |
setFaktor(int faktor)
Sets the factor for resizing the the game's gui including the font scale
of the elements.
|
void |
setFontWeight(boolean weight)
Controlls the game's font weight
|
(package private) void |
setHintMode(boolean mode)
Sets the game's mode.
|
(package private) void |
setMistakeDelay(java.lang.String delay)
Saves the time settings mistake hints are shown.
|
(package private) void |
setMistakeHint(boolean selected)
Display a hint if a false value is inserted
|
(package private) void |
setSpeechPlayable(boolean speech)
If
true while setting a number a sound is played speaking
the entered digit. |
(package private) void |
setSuccessSoundPlayable(boolean aku)
If
true a sound is played, when the game is finished
successfully. |
void |
setTooltipFont()
Sets the tooltip font depending on
contrast . |
(package private) void |
showSolution() |
private void |
showSuccess(java.lang.String s)
If enabled a sound is played when the correct number is written or if the
game ist finished correctly.
|
private void |
switchContrastColors(boolean selected)
Changes the background and foreground color depending on the state of the
contrast mode.
|
void |
switchView()
Switches the element's view from number view to comment view and vice
versa.
|
void |
update(javax.sound.sampled.LineEvent event) |
(package private) void |
updateSudoku(byte[][] arr)
Updates the game generating a new set of numbers and sets them to the
gui.
|
private boolean |
verifySuccess()
Sums up all entry values row by row and compares each row's result with
the sum of 1 to
elementsInRow . |
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setBackground, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setOpacity, setResizable, setShape, setState, setTitle, setUndecorated
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBackground, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOpacity, getOwnedWindows, getOwner, getOwnerlessWindows, getShape, getToolkit, getType, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isAutoRequestFocus, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isOpaque, isShowing, isValidateRoot, pack, paint, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setAutoRequestFocus, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocation, setLocation, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setType, setVisible, show, toBack, toFront
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusDownCycle, validate, validateTree
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resize, resize, revalidate, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
private static final java.awt.Color FG_COLOR
private static final java.awt.Color FG_COLOR_LIGHT_ACCESS
private static final java.awt.Color FG_COLOR_DARK_ACCESS
private static final java.awt.Color BG_COLOR_LIGHT
private static final java.awt.Color BG_COLOR_LIGHT_ACCESS
private static final java.awt.Color BG_COLOR_DARK
private static final java.awt.Color BG_COLOR_DARK_ACCESS
private static final java.awt.Color BORDER_COLOR
private static final java.awt.Color BORDER_COLOR_LIGHT_ACCESS
private static final java.awt.Color BORDER_COLOR_DARK_ACCESS
private static final java.awt.Color MISTAKE_BG_COLOR
private static final java.awt.Color MISTAKE_BG_COLOR_ACCESS
private static final java.awt.Color MISTAKE_FG_COLOR
private static final java.awt.Color MISTAKE_FG_COLOR_ACCESS
private static final java.awt.Color HIGHLIGHT_BG_COLOR
private java.awt.Color lightBgColor
switchContrastColors(boolean)
private java.awt.Color darkBgColor
switchContrastColors(boolean)
private java.awt.Color lightFgColor
switchContrastColors(boolean)
private java.awt.Color darkFgColor
switchContrastColors(boolean)
private java.awt.Color borderColorLight
switchContrastColors(boolean)
private java.awt.Color borderColorDark
switchContrastColors(boolean)
private final int squareRowElements
private final int elementsInRow
private final int gameElements
private int difficulty
private int mistakeDelay
private int fontWeight
private final int fontScale
private boolean contrast
private boolean mistakeHint
private boolean isSuccessSoundPlayable
private boolean isSpeechPlayable
true
.private int mistakes
private int faktor
private boolean hintMode
true
if the hint mode is enabled otherwise
false
. @see #help()private Element[][] elements
Element
private final javax.swing.ImageIcon icon
private final java.awt.Font defaultTooltipFont
private final SudokuEngine engine
SudokuEngine
private PropertiesManager pm
PropertiesManager
private PrintablePanel mainPanel
JPanel
PrintablePanel
private void initGUI()
private void initMainPanel()
SudokuEngine.getStartArray()
private void initMenubar()
private void initStatusBar()
void reloadElementFont()
void resizeGUI(int faktor)
faktor
. Called when the gui is
resized.faktor
- int
private void setComponentSizeAndPosition(javax.swing.JFrame frame)
faktor
and centers it on
the screen.frame,
- the JFrame
to be handledprivate void loadProperties()
int getFilledCellsCount()
int
the number of not empty cellsvoid help()
void load()
Config.CONFIG_DIR
which is
saved in a hidden file Config.SAVE_FILE
.SudokuEngine.resultArray
.save()
void save()
Config.SAVE_FILE
located in the sudoku's
configuration directory. Each element is stored in a separate line as a
two digit number. The second digit represent the result array's values,
the first one represents the current entry in the specified field.load()
public void print()
mainPanel
as image.private boolean makeConfigFile()
true
if the file was successfully created or exists
already.public Element[][] getElements()
Element[][]
all elements organized as
Element[row][column]public int getFaktor()
int
the factor that is used for resizing the gamevoid setFaktor(int faktor)
faktor
- int
the numeric factor used for resizingsetComponentSizeAndPosition(JFrame)
int getFontWeight()
int
the font weightSudokuConstants.FONT_WEIGHT
public void setFontWeight(boolean weight)
weight
- - if true
the font is shown bold, otherwise plainfontWeight
boolean getContrast()
true
a high
contrast mode is shown.boolean
the current contrast settingspublic void setContrast(boolean selected)
selected
- boolean
, checkbox statusBar in options dialogboolean getMistakeHint()
true
the row,
column and square where the mistake occures, are highlighted for a time,
which is defined by
SudokuConstants.MISTAKE_DELAY
boolean, true
if the hints are shownvoid setMistakeHint(boolean selected)
selected
- boolean
, checkbox statusBar in options dialogboolean getSuccessSoundPlayable()
boolean
if true
a success sound will be
played when the game is finished successfullyvoid setSuccessSoundPlayable(boolean aku)
true
a sound is played, when the game is finished
successfully. The value is set to isSuccessSoundPlayable
and
stored within the game's properties.aku
- boolean
boolean getSpeechPlayable()
boolean
if true
the entered digit is
spokenvoid setSpeechPlayable(boolean speech)
true
while setting a number a sound is played speaking
the entered digit. The value is set to isSuccessSoundPlayable
and stored within the game's properties.speech
- boolean, true
if a speech sound should be playedjava.lang.String getMistakeDelay()
String
the number of milliseconds a mistake hint is
shown.void setMistakeDelay(java.lang.String delay)
delay,
- a String
, denoting the milliseconds the mistake
hints are shown.void setHintMode(boolean mode)
true
the game is played in hint
mode. That means that one field can display multiple digits i.e. for
memory reasons. If false
the normal puzzle mode is
displayed.mode
- boolean
the game's modepublic int getDifficulty()
int
the difficulty of the gamedifficulty
void setDifficulty(int difficulty)
difficulty
of the gamedifficulty
- int
the difficultypublic int getElementsInRow()
int
the number of elements in one row/columnelementsInRow
public int getSquareRowElements()
int
the number of elements in one row/column of one
element square. Defaults to 3.public SudokuEngine getEngine()
SudokuEngine
, an instance of the game's business
logicpublic void setTooltipFont()
contrast
.true
the game's tooltips are shown much larger according
to SudokuConstants.TOOLTIP_FONT
otherwise the default font is
loaded.void playSound(java.lang.String soundFile)
soundFile
when a digit is enterd or the game is
finished successfullysoundFile
- String
the name of the sound filevoid initNewSudoku()
void updateSudoku(byte[][] arr)
arr
- byte[][]
the number array used to initialize the
game.void showSolution()
private boolean verifySuccess()
elementsInRow
.true
if all the rows are filled out properly so that
each row contains one example of all required numbers.private void showSuccess(java.lang.String s)
s
- String
, the name of the number's sound file
whithout extension.playSound(String)
,
isSpeechPlayable
,
isSuccessSoundPlayable
private void handleMistake(Element el)
el
- Element
, the Element-Object causing the mistake.highlightMistake(int, int, int,
int, int)
private void highlightMistake(int row, int col, int quad, int mistake, int value)
checkForMistake(Element, byte)
. According to the location of its
occurance, whether the double entry is in a row, a column, square or
multiple of these, mistake
is given and the associated
fields are highlighted by MISTAKE_FG_COLOR
and
MISTAKE_BG_COLOR
.row
- int
, row number starting with '0'col
- int
, column number starting with '0'quad
- int
, square number starting with '0'mistake
- int
, number of the kind of local match
value
- int
, Wert der falschen ZahlSudokuEngine.check(int, int, int)
private void checkForMistake(Element el, byte value)
b
exists in row, column or square to which
el
belongs. If mistake hints are to be shown, the row,
column or square containing the double number will be highlighted.el
- The Element
belonging to the row, column or
square with the doubled valuevalue
- byte
The value to be tested for double occurencepublic void handleInput(Element el)
el
- Element
private void clearHintLabels()
private void manageHints(int row, int col, int quad, int value)
row
- int
the rowcol
- int
the columnquad
- int
the squarevalue
- int
the digitpublic void switchView()
public void highlightNumber(java.lang.String number)
number
and highlights its
background.number
- String
, the number of the current cell.public void setElementsDefaultColors()
switchContrastColors(boolean)
private void switchContrastColors(boolean selected)
selected
- boolean
, true
will switch to
contrast mode. The background is set to black and white.
Mistake's highlighting will be red. If selected
is false
the background and foreground colors are
set to default.public void keyReleased(java.awt.event.KeyEvent e)
keyReleased
in interface java.awt.event.KeyListener
public void keyTyped(java.awt.event.KeyEvent arg0)
keyTyped
in interface java.awt.event.KeyListener
public void keyPressed(java.awt.event.KeyEvent e)
keyPressed
in interface java.awt.event.KeyListener
public void update(javax.sound.sampled.LineEvent event)
update
in interface javax.sound.sampled.LineListener