|
|
@ -3,6 +3,8 @@ package src; |
|
|
|
import javax.swing.*; |
|
|
|
import javax.swing.border.LineBorder; |
|
|
|
import java.awt.*; |
|
|
|
import java.awt.event.MouseEvent; |
|
|
|
import java.awt.event.MouseListener; |
|
|
|
|
|
|
|
public class GameField extends JPanel { |
|
|
|
|
|
|
@ -10,6 +12,12 @@ public class GameField extends JPanel { |
|
|
|
private JPanel[][] gameField; |
|
|
|
private JLabel[][] labelField; |
|
|
|
|
|
|
|
private JPanel activePanel = null; |
|
|
|
|
|
|
|
private static final Color colorDefault = new Color(0, 0, 255, 255); |
|
|
|
private static final Color colorOnEntered = new Color(0, 0, 255, 100); |
|
|
|
private static final Color colorOnWhenActive = new Color(0, 255, 150, 200); |
|
|
|
|
|
|
|
public Notes[][] getNoteField() { |
|
|
|
return noteField; |
|
|
|
} |
|
|
@ -22,6 +30,10 @@ public class GameField extends JPanel { |
|
|
|
return labelField; |
|
|
|
} |
|
|
|
|
|
|
|
public JPanel getActivePanel() { |
|
|
|
return activePanel; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* represents the game filed of sudoku |
|
|
|
* @param widthHeight describes the field size in pixels which will be seperated into single sudoku fields |
|
|
@ -49,6 +61,7 @@ public class GameField extends JPanel { |
|
|
|
|
|
|
|
for (int j = 0, addJ = 1; j < nrOfFields; j++) { |
|
|
|
|
|
|
|
JPanel panel = gameField[i][j]; |
|
|
|
gameField[i][j] = new JPanel(); |
|
|
|
gameField[i][j].setBorder(new LineBorder(Color.BLACK, 2)); |
|
|
|
gameField[i][j].setLayout(null); |
|
|
@ -64,6 +77,7 @@ public class GameField extends JPanel { |
|
|
|
noteField[i][j].setBounds(border, border, size-2*border, size-2*border); |
|
|
|
gameField[i][j].add(noteField[i][j]); |
|
|
|
|
|
|
|
JLabel lf = labelField[i][j]; |
|
|
|
labelField[i][j] = new JLabel("", SwingConstants.CENTER); |
|
|
|
labelField[i][j].setBounds(0, 0, size, size); |
|
|
|
labelField[i][j].setBackground(Color.GREEN); |
|
|
@ -74,6 +88,47 @@ public class GameField extends JPanel { |
|
|
|
labelField[i][j].setBackground(Color.CYAN); |
|
|
|
labelField[i][j].setText("0"); |
|
|
|
|
|
|
|
gameField[i][j].addMouseListener(new MouseListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
public void mouseClicked(MouseEvent e) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void mousePressed(MouseEvent e) { |
|
|
|
JPanel component = (JPanel) e.getComponent(); |
|
|
|
if (activePanel == null) { |
|
|
|
activePanel = component; |
|
|
|
} else { |
|
|
|
activePanel.setBackground(colorDefault); |
|
|
|
activePanel = component; |
|
|
|
} |
|
|
|
component.setBackground(colorOnWhenActive); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void mouseReleased(MouseEvent e) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void mouseEntered(MouseEvent e) { |
|
|
|
JPanel component = (JPanel) e.getComponent(); |
|
|
|
if (component != activePanel) { |
|
|
|
component.setBackground(colorOnEntered); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void mouseExited(MouseEvent e) { |
|
|
|
JPanel component = (JPanel) e.getComponent(); |
|
|
|
if (!component.getBackground().equals(colorOnWhenActive)) { |
|
|
|
component.setBackground(colorDefault); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
gameField[i][j].add(labelField[i][j]); |
|
|
|
|
|
|
|
} |
|
|
|