Ejemplo n.º 1
0
 private void doLoad() {
   if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
     try {
       SerGrid sg = LoadSaver.load(fc.getSelectedFile().getAbsolutePath());
       sGrid.setSerGrid(sg, gg.getGrid());
     } catch (Exception e) {
       e.printStackTrace();
       JOptionPane.showMessageDialog(
           this, "Sudoku game have not been saved!", "Error", JOptionPane.ERROR_MESSAGE);
     }
   }
   sGrid.repaint();
 }
Ejemplo n.º 2
0
  private void generateNewSud() {

    System.out.println("Inside generate sudoku");
    // ObjectInputStream ois = null;

    /*
     * switch(diff) { case GV.DIFF_EASY : jTextDiff.setText("Easy"); break;
     * case GV.DIFF_NORMAL : jTextDiff.setText("Normal"); break; case
     * GV.DIFF_HARD : jTextDiff.setText("Hard"); break; default :
     * jTextDiff.setText("Custom"); }
     */
    /*
     * try { System.out.println("Before new object stream");
     *
     * ois = new ObjectInputStream(socket.getInputStream());
     *
     * System.out.println("Before read object");
     *
     * gg = (GridGenerator) ois.readObject();
     * System.out.println("After read object");
     *
     * // gg.getGrid().resetGrid(); // gg.generate(diff, nD); //gg= }
     * catch(IOException e) { System.out.println("IO Exception");
     *
     * } catch (ClassNotFoundException e) {
     * System.out.println("Class not found Exception"); }
     */
    sinchronizeGrids();
    sGrid.repaint();
  }
Ejemplo n.º 3
0
 private void doSolve() {
   try {
     gg.solve();
     sinchronizeGrids();
     setGridToFinished();
     sGrid.repaint();
   } catch (NullPointerException e) {
     e.printStackTrace();
     JOptionPane.showMessageDialog(
         this, "Sudoku seems to be solved.", "Solved", JOptionPane.INFORMATION_MESSAGE);
   }
 }
Ejemplo n.º 4
0
  // ----------------------------------------------------------------------------------
  private void doOtherPersonWon() {
    JOptionPane.showMessageDialog(
        this, "Somebody else won!! :)", "Oops", JOptionPane.INFORMATION_MESSAGE);
    setGridToFinished();
    sGrid.repaint();

    // --------------------------------

    /*
     * //Send data over socket String text = "ClientWon"; out.println(text);
     * // textField.setText(new String(""));
     */
    // ----------------------------------
  }
Ejemplo n.º 5
0
  // ----------------------------------------------------------------------------------
  private void doNotSolved() {
    JOptionPane.showMessageDialog(
        this, "Sudoku not solved :)", "Damn", JOptionPane.INFORMATION_MESSAGE);
    setGridToFinished();
    sGrid.repaint();

    // --------------------------------

    /*
     * //Send data over socket String text = "ClientWon"; out.println(text);
     * // textField.setText(new String(""));
     */
    // ----------------------------------
  }
Ejemplo n.º 6
0
 private void doSave() {
   if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
     try {
       SerGrid sg = sGrid.getSerGrid();
       File file = fc.getSelectedFile();
       String aPath = file.getAbsolutePath();
       if (!aPath.toLowerCase().endsWith(".ssud")) {
         aPath = aPath + ".ssud";
         file = new File(aPath);
       }
       LoadSaver.save(sg, file);
       fc.setSelectedFile(file);
     } catch (Exception e) {
       e.printStackTrace();
       JOptionPane.showMessageDialog(
           this, "Sudoku game have not been saved!", "Error", JOptionPane.ERROR_MESSAGE);
     }
   }
 }
Ejemplo n.º 7
0
 private void doClear() {
   gg.getGrid().clearNoDefaultFields();
   sinchronizeGrids();
   sGrid.repaint();
 }
Ejemplo n.º 8
0
 private void doCreate() {
   gg.getGrid().resetGrid();
   sinchronizeGrids();
   sGrid.repaint();
 }
Ejemplo n.º 9
0
  private void initGUI() {

    all = new JPanel();
    all.setLayout(new BorderLayout());
    all.setBackground(GV.BORDER_COLOR);
    all.setBorder(BorderFactory.createTitledBorder(""));

    // BUTTONS UP
    butUp = new JPanel();
    BoxLayout bUpLayout = new BoxLayout(butUp, BoxLayout.X_AXIS);
    butUp.setLayout(bUpLayout);
    butUp.setBorder(new EtchedBorder());
    bUp = new JButton[10];
    {
      Dimension butUpDim = new Dimension(24, 24);

      bUp[0] = createButUp("star1.png", "star2.png", "Generate new Sudoku", butUpDim);
      butUp.add(bUp[0]);
      bUp[1] = createButUp("board1.png", "board2.png", "Create new Sudoku", butUpDim);
      butUp.add(bUp[1]);
      bUp[2] = createButUp("open1.png", "open2.png", "Open Sudoku", butUpDim);
      butUp.add(bUp[2]);
      bUp[3] = createButUp("disk1.png", "disk2.png", "Save Sudoku As", butUpDim);
      butUp.add(bUp[3]);

      // SEPARATOR
      createButUpSeparator();

      bUp[4] = createButUp("redo1.png", "redo2.png", "Redo", butUpDim);
      butUp.add(bUp[4]);
      setKeyAcceleratorButton(bUp[4], actButUp, "redo", 'Y', Event.CTRL_MASK);

      bUp[5] = createButUp("undo1.png", "undo2.png", "Undo", butUpDim);
      butUp.add(bUp[5]);
      setKeyAcceleratorButton(bUp[5], actButUp, "undo", 'Z', Event.CTRL_MASK);

      // SEPARATOR
      createButUpSeparator();

      bUp[6] = createButUp("bin1.png", "bin2.png", "Clear Sudoku", butUpDim);
      butUp.add(bUp[6]);

      bUp[7] = createButUp("help1.png", "help2.png", "Hint", butUpDim);
      butUp.add(bUp[7]);
      System.out.println("***********************************");

      bUp[8] = createButUp("tick1.png", "tick2.png", "Solve", butUpDim);
      butUp.add(bUp[8]);

      // SEPARATOR
      createButUpSeparator();

      // Difficulty
      butUp.add(Box.createRigidArea(GV.DIM_RA));
      JLabel diffLabel = new JLabel("Difficulty :  ");
      butUp.add(diffLabel);

      jTextDiff = new JTextField();
      jTextDiff.setEditable(false);
      jTextDiff.setText("Normal ");
      jTextDiff.setMaximumSize(new Dimension(60, 18));
      butUp.add(jTextDiff);

      butUp.add(Box.createRigidArea(new Dimension(85, 1)));
      bUp[9] = createButUp("cross1.png", "cross2.png", "<HTML>Close</HTML>", butUpDim);
      butUp.add(bUp[9]);
      setKeyAcceleratorButton(bUp[9], actButUp, "close", Event.ESCAPE, 0);
    }

    all.add(butUp, BorderLayout.NORTH);

    // GRID
    sGrid = new SudGrid(this);
    sGrid.setBorder(new LineBorder(new Color(238, 238, 238), 4, false));
    all.add(sGrid, BorderLayout.CENTER);

    // BUTONS DOWN
    butDown = new JPanel();
    BoxLayout butLayout = new BoxLayout(butDown, BoxLayout.X_AXIS);
    butDown.setLayout(butLayout);
    butDown.setBorder(new LineBorder(GV.BORDER_COLOR, 2, false));
    butDown.setBackground(GV.BORDER_COLOR);

    bDown = new JButton[9];
    {
      butDown.add(Box.createRigidArea(GV.DIM_RA));
      for (int i = 0; i < bDown.length; i++) {
        bDown[i] = new JButton();
        butDown.add(bDown[i]);
        bDown[i].setText("" + (i + 1));
        bDown[i].addActionListener(bHDown);
        butDown.add(Box.createRigidArea(GV.DIM_RA));
        bDown[i].setToolTipText("<HTML>Press" + (i + 1) + "<HTML>");
        setKeyAcceleratorButton(bDown[i], actButDown, "press" + (i + 1), 49 + i, 0);
        // bDown[i].setBackground(GlobalVars.BORDER_COLOR);
      }

      delBut = new JButton();
      delBut.addActionListener(bHDown);
      butDown.add(delBut);
      delBut.setText("Delete");
      delBut.setToolTipText("<HTML>Press D <HTML>");
      setKeyAcceleratorButton(delBut, actButDown, "delBut", 'D', 0);
      // delBut.setBackground(GlobalVars.BORDER_COLOR);

      lastBut = bDown[0];
      lastBut.setForeground(Color.BLUE);
      lastBut.requestFocus();
    }

    // FileChooser
    fc = new JFileChooser();
    fc.addChoosableFileFilter(
        new FileFilter() {
          public boolean accept(File f) {
            if (f.isDirectory()) return true;
            return f.getName().toLowerCase().endsWith(".ssud");
          }

          public String getDescription() {
            return GV.NAME + "Save File (*.ssud)";
          }
        });

    fc.setMultiSelectionEnabled(false);

    all.add(butDown, BorderLayout.SOUTH);
  }