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 accessible mode.
|
private java.awt.Color |
borderColorLight
Border color of the dark squares in accessible 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
Default number of empty cells at startup.
|
private Element[][] |
elements
All cells ordered from left to right
|
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 |
fontWeight
Default font weight of the numbers
|
private static java.awt.Color |
HIGHLIGHT_BG_COLOR |
private javax.swing.ImageIcon |
icon
the game's icon
|
private boolean |
isSpeechPlayable
Voice output
|
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 |
private javax.swing.JMenuBar |
menubar
The game's menu bar
|
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 of highlighting a mistake before resetting the display to
the status before entering the wrong number.
|
private boolean |
mistakeHint
Give a hint if a false number is inserted.
|
private int |
mistakes
Count the number of mistakes to display it on the status bar
|
private PropertiesManager |
pm
Storing the configuration settings
|
private int |
quadRows
Number of cells in a row, a column or a square - min. 3
|
private int |
rowElements
Number of rows and cols in the entire game
|
private int |
scaler
Change to scale the font and border size - greater number means smaller
font
|
private StatusBar |
status
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 |
clearHintLabels()
Clears all hint labels
|
boolean |
getContrast() |
int |
getDifficulty() |
private int |
getEmptyCells()
Counts the number of empty cells.
|
SudokuEngine |
getEngine() |
int |
getFaktor() |
int |
getFieldSize() |
int |
getFontWeight() |
java.lang.String |
getMistakeDelay() |
boolean |
getMistakeHint() |
boolean |
getSpeechPlayable() |
StatusBar |
getStatus() |
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 the
mistake.
|
private void |
highlightMistake(int row,
int col,
int quad,
int mistake,
int value)
Markiert falsche Zahlenbelegungen durch farbige Kennzeichnung der
horizontalen, vertikalen oder Teilquadrat-Elemente in denen bereits mit
der jeweiligen Zahl belegte Felder vorkommen.
|
void |
highlightNumber(java.lang.String number)
Ermittelt alle eingegebenen Zahlen, die
number entsprechen
und markiert den Hintergrund von deren Zellen nachdem zunächst alle
Hintergründe auf die Default-Farbe zurückgesetzt wurden. |
private void |
initGUI()
Initializes the gui
|
private void |
initMainPanel()
Creates an array of elements that represent the the games number fields.
|
private void |
initMenubar()
Create a menubar
|
(package private) void |
initNewSudoku()
Aus dem Menu heraus das Sudoku neu belegen
|
void |
keyPressed(java.awt.event.KeyEvent e) |
void |
keyReleased(java.awt.event.KeyEvent e)
Event-Handling
|
void |
keyTyped(java.awt.event.KeyEvent arg0) |
private void |
loadProperties()
Lädt die eingestellten Eigenschaften des Sudokus aus der
Optionen-Datei und castet sie in den notwendigen Datentyp.
|
private boolean |
makeConfigFile()
Erzeugt eine Speicherdatei falls diese nicht vorhanden ist.
|
private void |
manageHints(int row,
int col,
int quad,
int value) |
(package private) void |
open()
Lädt eine gespeicherte Belegung.
|
(package private) void |
playSound(java.lang.String soundFile)
Soundausgabe des fertig gelösten Sudokus
|
void |
print()
Druckt das Sudoku aus
|
private void |
reloadElementFont()
Reloads the font of all elements if the component is resized or the
font-weight is changed.
|
(package private) void |
save()
Speichert die aktuelle Belegung.
|
private void |
setComponentSize()
Centers the component and sets its size to
faktor . |
(package private) void |
setContrast(boolean selected)
Set the accessible mode with high contrast
|
(package private) void |
setDifficulty(int difficulty) |
void |
setElementsDefaultColors()
Controlls the changing of the 9 square's background color.
|
(package private) void |
setFaktor(int faktor) |
(package private) void |
setFontWeight(boolean weight)
Steuert den Schriftschnitt des Sudokus
|
(package private) void |
setMistakeDelay(java.lang.String delay)
Steuert die Dauer der Anzeige der Fehlerdarstellung
|
(package private) void |
setMistakeHint(boolean selected)
Give a hint if a false value is inserted
|
(package private) void |
setSpeechPlayable(boolean speech) |
(package private) void |
setSuccessSoundPlayable(boolean aku) |
void |
setTooltipFont()
Sets the tooltip font depending on
contrast . |
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 setting them to the
gui.
|
private boolean |
verifySuccess()
Prüft, ob das Sudoku korrekt gelöst ist.
|
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 quadRows
private int scaler
private int difficulty
private int mistakeDelay
private int fontWeight
private boolean contrast
private boolean mistakeHint
private boolean isSuccessSoundPlayable
private boolean isSpeechPlayable
private final int rowElements
private int mistakes
private int faktor
private Element[][] elements
private StatusBar status
private javax.swing.JMenuBar menubar
private javax.swing.ImageIcon icon
private java.awt.Font defaultTooltipFont
private SudokuEngine engine
private PropertiesManager pm
private PrintablePanel mainPanel
void updateSudoku(byte[][] arr)
arr
- byte[][]
the number array used to initialize the
game.private void initGUI()
private void initMainPanel()
private void reloadElementFont()
private void setComponentSize()
faktor
.private void initMenubar()
private void loadProperties()
private int getEmptyCells()
int
the number of empty cellsvoid open()
Config.CONFIG_DIR
- im Heimatverzeichnis des Nutzers in
der Datei .sudoku
abgelegt.void save()
.sudoku
abgelegt.private boolean makeConfigFile()
true
wenn die Datei vorhanden ist oder erfolgreich
angelegt wurde.public void print()
public int getFieldSize()
public int getFaktor()
public int getFontWeight()
public boolean getContrast()
public boolean getMistakeHint()
public boolean getSuccessSoundPlayable()
public boolean getSpeechPlayable()
public java.lang.String getMistakeDelay()
public SudokuEngine getEngine()
public int getDifficulty()
public StatusBar getStatus()
void setDifficulty(int difficulty)
void setFaktor(int faktor)
void setFontWeight(boolean weight)
weight
- , boolean wenn true wird die Schrift fett dargestellt, sonst
normal (plain)public void setTooltipFont()
contrast
.true
the game's tooltips are shown much larger according
to SudokuConstants.TOOLTIP_FONT
otherwise the default font is set.void setMistakeDelay(java.lang.String delay)
delay
- String
, String-Repräsentanz des numerischen
Anzeigewertes in Millisekunden.void setContrast(boolean selected)
selected
- boolean
, checkbox status in options dialogvoid setMistakeHint(boolean selected)
selected
- boolean
, checkbox status in options dialogvoid setSuccessSoundPlayable(boolean aku)
void setSpeechPlayable(boolean speech)
void initNewSudoku()
private boolean verifySuccess()
false
if there is any field entry that does not
match the value of the appropriate result array's index,
otherwise true
.void playSound(java.lang.String soundFile)
soundFile
- String
the sound fileprivate void handleMistake(Element el)
highlightMistake(int, int, int, int, int)
el
- Element
, the Element-Object causing the mistake.public void handleInput(Element el)
el
- Element
private void clearHintLabels()
public void switchView()
private void manageHints(int row, int col, int quad, int value)
private void highlightMistake(int row, int col, int quad, int mistake, int value)
mistakeFgColor
gekennzeichnet.row
- int
, Nummer der Reihe bei '0' beginnendcol
- int
, Nummer der Spalte bei '0' beginnendquad
- int
, Nummer des Quadrats bei '0' beginnendmistake
- int
, numerisch kodierter Wert des Fehlerortes
Dabei bedeuten:
value
- int
, Wert der falschen Zahl
See also SudokuEngine.check(int, int, int)
public void highlightNumber(java.lang.String number)
number
entsprechen
und markiert den Hintergrund von deren Zellen nachdem zunächst alle
Hintergründe auf die Default-Farbe zurückgesetzt wurden.number
- String
, der soeben eingegebene Wert der aktuellen
Zelle, wie er durch den KeyListener zurück gegeben wurde.public void setElementsDefaultColors()
switchColors
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