|
@ -9,10 +9,10 @@ import java.awt.event.MouseListener; |
|
|
public class GameField extends JPanel { |
|
|
public class GameField extends JPanel { |
|
|
|
|
|
|
|
|
private Notes[][] noteField; |
|
|
private Notes[][] noteField; |
|
|
private JPanel[][] gameField; |
|
|
|
|
|
|
|
|
private Field[][] gameField; |
|
|
private JLabel[][] labelField; |
|
|
private JLabel[][] labelField; |
|
|
|
|
|
|
|
|
private JPanel activePanel = null; |
|
|
|
|
|
|
|
|
private Field activePanel = null; |
|
|
|
|
|
|
|
|
private static final Color colorDefault = new Color(100, 100, 255, 255); |
|
|
private static final Color colorDefault = new Color(100, 100, 255, 255); |
|
|
private static final Color colorOnEntered = new Color(0, 0, 255, 100); |
|
|
private static final Color colorOnEntered = new Color(0, 0, 255, 100); |
|
@ -30,7 +30,7 @@ public class GameField extends JPanel { |
|
|
return labelField; |
|
|
return labelField; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public JPanel getActivePanel() { |
|
|
|
|
|
|
|
|
public Field getActivePanel() { |
|
|
return activePanel; |
|
|
return activePanel; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -48,7 +48,7 @@ public class GameField extends JPanel { |
|
|
this.setVisible(true); |
|
|
this.setVisible(true); |
|
|
this.setLayout(null); |
|
|
this.setLayout(null); |
|
|
|
|
|
|
|
|
gameField = new JPanel[nrOfFields][]; |
|
|
|
|
|
|
|
|
gameField = new Field[nrOfFields][]; |
|
|
labelField = new JLabel[nrOfFields][]; |
|
|
labelField = new JLabel[nrOfFields][]; |
|
|
noteField = new Notes[nrOfFields][]; |
|
|
noteField = new Notes[nrOfFields][]; |
|
|
|
|
|
|
|
@ -56,14 +56,17 @@ public class GameField extends JPanel { |
|
|
|
|
|
|
|
|
for (int i = 0, addI = 1; i < nrOfFields; i++) { |
|
|
for (int i = 0, addI = 1; i < nrOfFields; i++) { |
|
|
|
|
|
|
|
|
gameField[i] = new JPanel[nrOfFields]; |
|
|
|
|
|
|
|
|
gameField[i] = new Field[nrOfFields]; |
|
|
labelField[i] = new JLabel[nrOfFields]; |
|
|
labelField[i] = new JLabel[nrOfFields]; |
|
|
noteField[i] = new Notes[nrOfFields]; |
|
|
noteField[i] = new Notes[nrOfFields]; |
|
|
|
|
|
|
|
|
for (int j = 0, addJ = 1; j < nrOfFields; j++) { |
|
|
for (int j = 0, addJ = 1; j < nrOfFields; j++) { |
|
|
|
|
|
|
|
|
JPanel panel = gameField[i][j]; |
|
|
|
|
|
gameField[i][j] = new JPanel(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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].setBorder(new LineBorder(Color.BLACK, 2)); |
|
|
gameField[i][j].setLayout(null); |
|
|
gameField[i][j].setLayout(null); |
|
|
gameField[i][j].setBounds( |
|
|
gameField[i][j].setBounds( |
|
@ -79,6 +82,7 @@ public class GameField extends JPanel { |
|
|
gameField[i][j].add(noteField[i][j]); |
|
|
gameField[i][j].add(noteField[i][j]); |
|
|
|
|
|
|
|
|
JLabel lf = labelField[i][j]; |
|
|
JLabel lf = labelField[i][j]; |
|
|
|
|
|
gameField[i][j].setMyJLabel(lf); |
|
|
labelField[i][j] = new JLabel("", SwingConstants.CENTER); |
|
|
labelField[i][j] = new JLabel("", SwingConstants.CENTER); |
|
|
labelField[i][j].setBounds(0, 0, size, size); |
|
|
labelField[i][j].setBounds(0, 0, size, size); |
|
|
labelField[i][j].setBackground(Color.GREEN); |
|
|
labelField[i][j].setBackground(Color.GREEN); |
|
@ -98,7 +102,8 @@ public class GameField extends JPanel { |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void mousePressed(MouseEvent e) { |
|
|
public void mousePressed(MouseEvent e) { |
|
|
JPanel component = (JPanel) e.getComponent(); |
|
|
|
|
|
|
|
|
Field component = (Field) e.getComponent(); |
|
|
|
|
|
|
|
|
if (activePanel == null) { |
|
|
if (activePanel == null) { |
|
|
activePanel = component; |
|
|
activePanel = component; |
|
|
} else { |
|
|
} else { |
|
@ -177,4 +182,9 @@ public class GameField extends JPanel { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public JLabel getActiveLabel(){ |
|
|
|
|
|
JLabel jLabel = getActivePanel().getjLabel(); |
|
|
|
|
|
return jLabel; |
|
|
|
|
|
} |
|
|
} |
|
|
} |