|
@ -8,9 +8,9 @@ import java.awt.event.MouseListener; |
|
|
|
|
|
|
|
|
public class GameField extends JPanel { |
|
|
public class GameField extends JPanel { |
|
|
|
|
|
|
|
|
private Notes[][] noteField; |
|
|
|
|
|
|
|
|
// private Notes[][] noteField; |
|
|
private Field[][] gameField; |
|
|
private Field[][] gameField; |
|
|
private JLabel[][] labelField; |
|
|
|
|
|
|
|
|
// private JLabel[][] labelField; |
|
|
|
|
|
|
|
|
private Field activePanel = null; |
|
|
private Field activePanel = null; |
|
|
|
|
|
|
|
@ -18,17 +18,17 @@ public class GameField extends JPanel { |
|
|
private static final Color colorOnEntered = new Color(0, 0, 255, 100); |
|
|
private static final Color colorOnEntered = new Color(0, 0, 255, 100); |
|
|
private static final Color colorOnWhenActive = new Color(0, 255, 150, 200); |
|
|
private static final Color colorOnWhenActive = new Color(0, 255, 150, 200); |
|
|
|
|
|
|
|
|
public Notes[][] getNoteField() { |
|
|
|
|
|
return noteField; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// public Notes[][] getNoteField() { |
|
|
|
|
|
// return noteField; |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
public JPanel[][] getGameField() { |
|
|
|
|
|
|
|
|
public Field[][] getGameField() { |
|
|
return gameField; |
|
|
return gameField; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public JLabel[][] getLabelField() { |
|
|
|
|
|
return labelField; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// public JLabel[][] getLabelField() { |
|
|
|
|
|
// return labelField; |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
public Field getActivePanel() { |
|
|
public Field getActivePanel() { |
|
|
return activePanel; |
|
|
return activePanel; |
|
@ -49,49 +49,28 @@ public class GameField extends JPanel { |
|
|
this.setLayout(null); |
|
|
this.setLayout(null); |
|
|
|
|
|
|
|
|
gameField = new Field[nrOfFields][]; |
|
|
gameField = new Field[nrOfFields][]; |
|
|
labelField = new JLabel[nrOfFields][]; |
|
|
|
|
|
noteField = new Notes[nrOfFields][]; |
|
|
|
|
|
|
|
|
// labelField = new JLabel[nrOfFields][]; |
|
|
|
|
|
// noteField = new Notes[nrOfFields][]; |
|
|
|
|
|
|
|
|
int gapi = 0, gapj = 0; |
|
|
int gapi = 0, gapj = 0; |
|
|
|
|
|
|
|
|
for (int i = 0, addI = 1; i < nrOfFields; i++) { |
|
|
for (int i = 0, addI = 1; i < nrOfFields; i++) { |
|
|
|
|
|
|
|
|
gameField[i] = new Field[nrOfFields]; |
|
|
gameField[i] = new Field[nrOfFields]; |
|
|
labelField[i] = new JLabel[nrOfFields]; |
|
|
|
|
|
noteField[i] = new Notes[nrOfFields]; |
|
|
|
|
|
|
|
|
// labelField[i] = new JLabel[nrOfFields]; |
|
|
|
|
|
// noteField[i] = new Notes[nrOfFields]; |
|
|
|
|
|
|
|
|
for (int j = 0, addJ = 1; j < nrOfFields; j++) { |
|
|
for (int j = 0, addJ = 1; j < nrOfFields; j++) { |
|
|
|
|
|
|
|
|
|
|
|
gameField[i][j] = new Field(i, j, size); |
|
|
|
|
|
gameField[i][j].setBackground(colorDefault); |
|
|
|
|
|
|
|
|
gameField[i][j] = new Field(); |
|
|
|
|
|
gameField[i][j].setMyY(j); |
|
|
|
|
|
gameField[i][j].setMyX(i); |
|
|
|
|
|
gameField[i][j] = new Field(); |
|
|
|
|
|
gameField[i][j].setBorder(new LineBorder(Color.BLACK, 2)); |
|
|
|
|
|
gameField[i][j].setLayout(null); |
|
|
|
|
|
gameField[i][j].setBounds( |
|
|
gameField[i][j].setBounds( |
|
|
j * size + border*(j+1), |
|
|
j * size + border*(j+1), |
|
|
i * size + border*(i+1), |
|
|
i * size + border*(i+1), |
|
|
size, size); |
|
|
size, size); |
|
|
gameField[i][j].setBackground(colorDefault); |
|
|
|
|
|
gameField[i][j].setVisible(true); |
|
|
|
|
|
this.add(gameField[i][j]); |
|
|
|
|
|
|
|
|
|
|
|
noteField[i][j] = new Notes(size); |
|
|
|
|
|
noteField[i][j].setBounds(border, border, size-2*border, size-2*border); |
|
|
|
|
|
gameField[i][j].add(noteField[i][j]); |
|
|
|
|
|
|
|
|
|
|
|
JLabel lf = labelField[i][j]; |
|
|
|
|
|
gameField[i][j].setMyJLabel(lf); |
|
|
|
|
|
labelField[i][j] = new JLabel("", SwingConstants.CENTER); |
|
|
|
|
|
labelField[i][j].setBounds(0, 0, size, size); |
|
|
|
|
|
labelField[i][j].setBackground(Color.GREEN); |
|
|
|
|
|
labelField[i][j].setForeground(Color.MAGENTA); |
|
|
|
|
|
labelField[i][j].setVisible(false); |
|
|
|
|
|
labelField[i][j].setFont(new Font("Times new Roman", Font.BOLD, 25)); |
|
|
|
|
|
|
|
|
|
|
|
labelField[i][j].setBackground(Color.CYAN); |
|
|
|
|
|
labelField[i][j].setText("0"); |
|
|
|
|
|
|
|
|
this.add(gameField[i][j]); |
|
|
|
|
|
|
|
|
gameField[i][j].addMouseListener(new MouseListener() { |
|
|
gameField[i][j].addMouseListener(new MouseListener() { |
|
|
|
|
|
|
|
@ -102,6 +81,7 @@ public class GameField extends JPanel { |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void mousePressed(MouseEvent e) { |
|
|
public void mousePressed(MouseEvent e) { |
|
|
|
|
|
|
|
|
Field component = (Field) e.getComponent(); |
|
|
Field component = (Field) e.getComponent(); |
|
|
|
|
|
|
|
|
if (activePanel == null) { |
|
|
if (activePanel == null) { |
|
@ -135,26 +115,31 @@ public class GameField extends JPanel { |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
gameField[i][j].add(labelField[i][j]); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void setValue(int x, int y, int value) { |
|
|
public void setValue(int x, int y, int value) { |
|
|
|
|
|
|
|
|
if (value > 0 && value < 10) { |
|
|
|
|
|
if (x > -1 && x < 9 && y > -1 && y < 9) { |
|
|
|
|
|
labelField[y][x].setText(String.valueOf(value)); |
|
|
|
|
|
labelField[y][x].setVisible(true); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
JLabel jLabel = gameField[y][x].getjLabel(); |
|
|
|
|
|
jLabel.setText(String.valueOf(value)); |
|
|
|
|
|
jLabel.setVisible(true); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public int getValue(int x, int y) { |
|
|
public int getValue(int x, int y) { |
|
|
|
|
|
|
|
|
if (x > -1 && x < 9 && y > -1 && y < 9) { |
|
|
if (x > -1 && x < 9 && y > -1 && y < 9) { |
|
|
Integer value = Integer.valueOf(labelField[y][x].getText()); |
|
|
|
|
|
return value; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JLabel jLabel = gameField[y][x].getjLabel(); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
Integer value = Integer.valueOf(jLabel.getText()); |
|
|
|
|
|
return value; |
|
|
|
|
|
|
|
|
|
|
|
} catch (NumberFormatException e) { |
|
|
|
|
|
return -1; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
return -1; |
|
|
return -1; |
|
|
} |
|
|
} |
|
@ -163,22 +148,20 @@ public class GameField extends JPanel { |
|
|
|
|
|
|
|
|
if (value > 0 && value < 10) { |
|
|
if (value > 0 && value < 10) { |
|
|
if (x > -1 && x < 9 && y > -1 && y < 9) { |
|
|
if (x > -1 && x < 9 && y > -1 && y < 9) { |
|
|
noteField[x][y].setHint(value); |
|
|
|
|
|
|
|
|
gameField[x][y].setHint(value); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void unsetHint(int x, int y, int value) { |
|
|
public void unsetHint(int x, int y, int value) { |
|
|
if (noteField[x][y].isSet(value)) { |
|
|
|
|
|
setHint(x, y, value); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
gameField[x][y].unsetHint(value); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void unsetAllHintsFromField(int x, int y) { |
|
|
public void unsetAllHintsFromField(int x, int y) { |
|
|
|
|
|
|
|
|
for (int j = 1; j < 10; j++) { |
|
|
for (int j = 1; j < 10; j++) { |
|
|
|
|
|
|
|
|
noteField[x][y].unsetHint(j); |
|
|
|
|
|
|
|
|
gameField[x][y].unsetHints(); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|