basic nav bar implemented and documentation added.
This commit is contained in:
+29
-5
@@ -9,16 +9,26 @@ import java.awt.Dimension;
|
||||
* Runner class for the Sudoku App, managing the GUI and coordinating internal logic.
|
||||
*/
|
||||
public class App extends JFrame {
|
||||
private Settings settings;
|
||||
// GUI fields
|
||||
private Nav nav;
|
||||
|
||||
// Data fields
|
||||
private Settings settings;
|
||||
private SudokuChecker checker;
|
||||
|
||||
/**
|
||||
* Create a new App object, initializing the GUI and internal logic.
|
||||
*/
|
||||
public App() {
|
||||
super("Sudoku");
|
||||
settings = new Settings();
|
||||
nav = new Nav(settings, false);
|
||||
initSetup();
|
||||
add(createApp());
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic JFrame setup for the GUI.
|
||||
* Basic JFrame settings and setup for the GUI.
|
||||
*/
|
||||
private void initSetup() {
|
||||
// TODO: These are just some default values, these should use the values from Settings.
|
||||
@@ -36,17 +46,31 @@ public class App extends JFrame {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the root JPanel holding all other GUI components.
|
||||
*
|
||||
* @return JPanel
|
||||
*/
|
||||
private JPanel createApp() {
|
||||
// TODO: Create the root JPanel holding all other GUI components.
|
||||
|
||||
return null;
|
||||
JPanel root = new JPanel();
|
||||
root.add(nav);
|
||||
return root;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the Sudoku App in a command-line interface for debugging core logic.
|
||||
*/
|
||||
public static void cli() {
|
||||
Nav nav = new Nav(new Settings());
|
||||
Nav nav = new Nav(new Settings(), true);
|
||||
SudokuChecker check = new SudokuChecker(nav.getLoadedGrid());
|
||||
}
|
||||
|
||||
/**
|
||||
* Main method for the Sudoku App.
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
if(args.length == 0)
|
||||
new App().setVisible(true);
|
||||
|
||||
+51
-10
@@ -4,6 +4,8 @@ import java.io.FileNotFoundException;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JButton;
|
||||
|
||||
/**
|
||||
* The Nav class represents the Navigation bar at the top of the JFrame window.
|
||||
@@ -53,22 +55,57 @@ public class Nav extends JPanel {
|
||||
*
|
||||
* @param Settings
|
||||
*/
|
||||
public Nav(Settings s) {
|
||||
public Nav(Settings s, boolean cli) {
|
||||
super();
|
||||
this.s = s;
|
||||
System.out.println("Welcome to the Sudoku Solver!");
|
||||
|
||||
if(cli) {
|
||||
System.out.println("Welcome to the Sudoku Solver!");
|
||||
|
||||
Scanner in = new Scanner(System.in);
|
||||
System.out.print(
|
||||
"Enter the name of the input file (do not " +
|
||||
"include the file extension): "
|
||||
);
|
||||
String inputFilename = in.nextLine();
|
||||
in.close();
|
||||
Scanner in = new Scanner(System.in);
|
||||
System.out.print(
|
||||
"Enter the name of the input file (do not " +
|
||||
"include the file extension): "
|
||||
);
|
||||
String inputFilename = in.nextLine();
|
||||
in.close();
|
||||
|
||||
openFile(inputFilename);
|
||||
openFile(inputFilename);
|
||||
} else {
|
||||
// TODO: Create the GUI for the Nav bar.
|
||||
createGUI();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the GUI for the Nav bar.
|
||||
*
|
||||
* This method is called when the Nav object is created in the App
|
||||
* class if the program is not being run in the command-line for
|
||||
* debugging purposes.
|
||||
*/
|
||||
private void createGUI() {
|
||||
JComboBox<String> fileOptions = new JComboBox<String>();
|
||||
fileOptions.addItem("New");
|
||||
fileOptions.addItem("Open");
|
||||
fileOptions.addItem("Save");
|
||||
fileOptions.addItem("Exit");
|
||||
|
||||
JLabel elapsedTime = new JLabel("Elapsed Time: 00:00:00");
|
||||
|
||||
JButton solve = new JButton("Solve");
|
||||
|
||||
add(fileOptions);
|
||||
add(elapsedTime);
|
||||
add(solve);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given the user's selection from the JComboBox, perform the appropriate
|
||||
* action.
|
||||
*
|
||||
* @param String
|
||||
*/
|
||||
private void newFile() {
|
||||
int defaultOption = s.getNewFileProperties();
|
||||
|
||||
@@ -106,6 +143,10 @@ public class Nav extends JPanel {
|
||||
createGrid(f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the currently open .sdku file with any changes the user has made.
|
||||
* This needs to pull the current state of the grid from the Board JPanel.
|
||||
*/
|
||||
private void saveFile() {
|
||||
// TODO: Get the current Cell[][] from the Board JPanel
|
||||
// TODO: Write to a file.
|
||||
|
||||
@@ -11,6 +11,10 @@ public class Settings {
|
||||
private int newFileProperties;
|
||||
private String defaultDirectory;
|
||||
|
||||
/**
|
||||
* Create a new Settings object, initializing the default settings
|
||||
* or reading in the settings from a file if it exists.
|
||||
*/
|
||||
public Settings() {
|
||||
// TODO: Read in a file from the master default directory and populate
|
||||
// settings, effectively toggles. If the file does not exist,
|
||||
|
||||
+10
-32
@@ -5,43 +5,21 @@ import java.util.Scanner;
|
||||
|
||||
|
||||
/**
|
||||
* A Sudoku puzzle is a 9x9 grid of numbers, where each row, column, and 3x3 subgrid contains the numbers 1-9 exactly once.
|
||||
* The SudokuChecker class is responsible for checking the validity of a given Sudoku puzzle solution.
|
||||
*
|
||||
* The goal of this challenge is to write a program that can solve Sudoku puzzles.
|
||||
*
|
||||
* Given an input .sdku file (a plain-text file containing the initial state of a Sudoku puzzle), find the solution to the puzzle and write the solution to a new .sdku file.
|
||||
*
|
||||
* The input file will contain 9 lines, each containing 9 characters. Each character will be a digit (1-9) or a period (.), representing an empty cell.
|
||||
*
|
||||
* The output file should contain the same 9x9 grid, with the empty cells filled in with the correct numbers.
|
||||
*
|
||||
* For example, given the following input file:
|
||||
*
|
||||
* 53..7....
|
||||
* 6..195...
|
||||
* .98....6.
|
||||
* 8...6...3
|
||||
* 4..8.3..1
|
||||
* 7...2...6
|
||||
* .6....28.
|
||||
* ...419..5
|
||||
* ....8..79
|
||||
*
|
||||
* The output file should be:
|
||||
*
|
||||
* 534678912
|
||||
* 672195348
|
||||
* 198342567
|
||||
* 859761423
|
||||
* 426853791
|
||||
* 713924856
|
||||
* 961537284
|
||||
* 287419635
|
||||
* 345286179
|
||||
* The SudokuChecker class is also responsible for solving a given Sudoku puzzle.
|
||||
*/
|
||||
public class SudokuChecker {
|
||||
private Cell[][] grid;
|
||||
|
||||
/**
|
||||
* Create a new SudokuChecker object, initializing the grid to the given 9x9 grid of numbers.
|
||||
* This should either check each cell as the user inputs a value, or be used to check the validity of a
|
||||
* puzzle when the user requests it.
|
||||
*
|
||||
* TODO: Currently, this class is not used in the GUI. It is only used in the command-line interface.
|
||||
* @param grid
|
||||
*/
|
||||
public SudokuChecker(Cell[][] grid) {
|
||||
this.grid = grid;
|
||||
solve();
|
||||
|
||||
Reference in New Issue
Block a user