-
Notifications
You must be signed in to change notification settings - Fork 0
/
Field.java
63 lines (56 loc) · 1.49 KB
/
Field.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package GamingPortal;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
/**
* This class represents a field on the SudokuPanel.
*
* @author Eric Beijer
*/
public class Field extends JLabel {
private int x; // X position in game.
private int y; // Y position in game.
/**
* Constructs the label and sets x and y positions in game.
*
* @param x X position in game.
* @param y Y position in game.
*/
public Field(int x, int y) {
super("", CENTER);
this.x = x;
this.y = y;
setPreferredSize(new Dimension(40, 40));
setBorder(BorderFactory.createLineBorder(Color.GRAY));
setFont(new Font(Font.DIALOG, Font.PLAIN, 20));
setOpaque(true);
}
/**
* Sets number and foreground color according to userInput.
*
* @param number Number to be set.
* @param userInput Boolean indicating number is user input or not.
*/
public void setNumber(int number, boolean userInput) {
setForeground(userInput ? Color.BLUE : Color.BLACK);
setText(number > 0 ? number + "" : "");
}
/**
* Returns x position in game.
*
* @return X position in game.
*/
public int getFieldX() {
return x;
}
/**
* Return y position in game.
*
* @return Y position in game.
*/
public int getFieldY() {
return y;
}
}