p.p1 loadListener = new LoadBtnListener(); btnLoad.addActionListener(loadListener); RunBtnListener runListener

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; background-color: #ffffff; min-height: 14.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #ba2da2; background-color: #ffffff}
p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff; min-height: 13.0px}
span.s1 {color: #ba2da2}
span.s2 {color: #000000}
span.s3 {color: #d12f1b}
span.Apple-tab-span {white-space:pre}

package sudoku;

We Will Write a Custom Essay Specifically
For You For Only $13.90/page!


order now

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import javax.swing.*;

public class Sudoku extends JFrame {

private static String INITIAL_BOARD =
            “8156….4/” +
            “6…75.8./” +
            “….9…./” +
            “9…417../” +
            “.4…..2./” +
            “..623…8/” +
            “….5…./” +
            “.5.91…6/” +
            “1….7895”;
    
    
    private SudokuModel        _sudokuLogic = new SudokuModel(INITIAL_BOARD);
    private SudokuBoardDisplay _sudokuBoard = new SudokuBoardDisplay(_sudokuLogic);

    Thread queryThread;

public Sudoku() {
JButton btnLoad = new JButton(“Load”);
JButton btnRun = new JButton(“Run”);
JButton btnInterrupt = new JButton(“Interrupt”);
JButton btnClear = new JButton(“Clear”);
JButton btnQuit = new JButton(“Quit”);

QuitBtnListener quitListener = new QuitBtnListener();
btnQuit.addActionListener(quitListener);

ClearBtnListener clearListener = new ClearBtnListener();
btnClear.addActionListener(clearListener);

LoadBtnListener loadListener = new LoadBtnListener();
btnLoad.addActionListener(loadListener);

RunBtnListener runListener = new RunBtnListener();
btnRun.addActionListener(runListener);

InterruptBtnListener interruptListener = new InterruptBtnListener();
btnInterrupt.addActionListener(interruptListener);

JPanel controlPanel = new JPanel();
controlPanel.add(btnLoad);
controlPanel.add(btnRun);
controlPanel.add(btnInterrupt);
controlPanel.add(btnClear);
controlPanel.add(btnQuit);

        JPanel content = new JPanel();
        content.setLayout(new BorderLayout());
        
        
        content.add(controlPanel, BorderLayout.NORTH);
        content.add(_sudokuBoard, BorderLayout.CENTER);
        content.add(_sudokuBoard.console, BorderLayout.SOUTH);

        
        setContentPane(content);
        setTitle(“Sudoku”);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setResizable(true);
        pack();
        setLocationRelativeTo(null);
}

public static void main(String args) {
        new Sudoku().setVisible(true);
    }

    
   private class QuitBtnListener implements ActionListener {
   @Override
      public void actionPerformed(ActionEvent e) {
      Sudoku.this.dispatchEvent(new WindowEvent(Sudoku.this, WindowEvent.WINDOW_CLOSING));
      }
   }

    
   private class ClearBtnListener implements ActionListener {
   @Override
      public void actionPerformed(ActionEvent e) {
      _sudokuBoard.clear();
      }
   }

    
   private class LoadBtnListener implements ActionListener {
   @Override
      public void actionPerformed(ActionEvent e) {
      _sudokuBoard.openPuzzle();
      }
   }

    
   private class RunBtnListener implements ActionListener {
   @Override
      public void actionPerformed(ActionEvent e) {
      queryThread = new Thread() {
      public void run() {
      _sudokuBoard.solve();
      }
};
      queryThread.start();
      }
   }

   private class InterruptBtnListener implements ActionListener {
   @Override
      public void actionPerformed(ActionEvent e) {
      queryThread.interrupt();
      }
   }
}