The code can be written and hacked with a text editor using javac to compile and java to run the application. This is where all the hard work is done to create the GUI.
It positions and monitors the push buttons. These machines had the correct Java runtime installed. If someone could spare the time, it would be nice to know if it works on Linux or Mac. All the classes are kept under a package called sudoku.
It can also paint itself based on the status on the cell. Instead of using a string such as "correct guess", "wrong guess", "no guess" or an int 1 for correct, 2 for wrong, 3 for no guess to represent the status of a cell, JDK 5 introduces a feature known as Enum or Enumeration to efficiently maintain a set of constants in a type-safe manner. Save the file as " CellStatus. Enum is indeed a special class. You can refer to the status as CellStatus.
The Puzzle class encapsulate a Sudoku puzzle. For simplicity, I hardcoded a puzzle. You may try to generate a puzzle automatically. The GameBoard contains 9x9 Cells , and a Puzzle. Study the above codes. Fill in the main method [TODO 1] , run the program, which shall produce the display. Some useful methods of JTextField are as follows. You can check the Java API for more methods.
Common colors are defined via constants such as Color. RED , Color. The user should call the first method, which uses the second method. I will describe the steps again. As you can see, this method is used to pass default values. This is the most common way of passing an integer by reference, instead of by value. A valid game has in every row, every column, and every region the numbers 1 to 9. Additionally, there should only be one solution existing.
To achieve this, all open fields are filled with the first valid value. Even after finding a solution, the search continues by putting the next valid value in an open field. If a second solution is found, then the search will be stopped and the method returns false. There will always be at least one solution hence game is an incomplete solution , so if there are less than two solutions, the game is valid and the method returns true. Step by step:. With checking user input, we compare each field in the game against the corresponding field in the solution.
The result is stored in a two dimensional boolean array. The selected number is also set to 0 meaning no number is selected. All observers are notified that the model has changed with the corresponding UpdateAction. There is not much to say about the view part, only the structure of the panels. The controllers react to user input and implement changes to the model. The model notifies it has been changed. The view responses to this notification and updates.
0コメント