Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Lab 12:

...

Download the support code for the Sudoku assignment. Try to understand first the Sudoku class and the JUnit test classes. Then look over the Row and PartialSolution classes to understand how a game board is represented as Java objects.

Exercises

1. Look at the implementation of the toString() function of the PartialSolution class. This implementation has problems of performance and functionality (does not work correctly in all cases). What are these problems? Write a new implementation for the toString() function that avoids both problems.

2. Write a function that tests if a PartialSolution is a descendent of another PartialSolution (a descendent is "included" in its parent). Write Junit tests for this function.

...

Graphical User Interfaces (GUI's) in Java

For most of the relevant Information on how to build GUIs in Java, see the following reference:  Java GUI Programming Primer

The content below discusses material not explicitly covered in the above reference.

Basic structure of a simple GUI application:

Code Block

import java.awt.*;
import javax.swing.*
import java.awt.event.*;

class MyGUIApp extends JFrame {
    /**
     * Constructor for the GUI.
     */
    public MyGUIApp() {
        // initialize fields here.

        initGUI();  // initialize the GUI components
    }

    /**
     * Actually start the GUI
     */
    public void start() {
       // Do any last second initializations, if needed.
       setVisible(true);  // Make the GUI visible
    }

    /**
     * Initialize the GUI components
     */
    private void initGUI() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Causes the application to end if the GUI frame is closed.

        // instantiate, initialize and connect all the GUI's components here.

    }

    /**
     * Main method that starts the app.
     * In general, this would not be in this class but rather in a separate "controller" class
     * with slightly different coding (as required for a true Model-View-Controller system).
     * We put it here for now, for simplicity's sake only.
     */
    public static void main(String[] args) {
         MyGUIApp view = new MyGUIApp();  // instantiate the GUI but don't show it yet.
         // Model classes would be instantiated here plus any other required objects.
         view.start();  // Start the application by making the GUI visible.
    }
}