-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButtonNumber.java
More file actions
42 lines (33 loc) · 1.16 KB
/
ButtonNumber.java
File metadata and controls
42 lines (33 loc) · 1.16 KB
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
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JButton;
@SuppressWarnings("serial")
public class ButtonNumber extends JButton{
private int buttonNumber;
private MinesweeperIcons msIcons = null;
public ButtonNumber(int buttonNumber){
msIcons = FrontEnd.msIcons();
setButtonNumber(buttonNumber);
}
public void setButtonNumber(int buttonNumber){
if (buttonNumber >= MinesweeperIcons.QUESTION && buttonNumber <= MinesweeperIcons.NULL){
this.buttonNumber = buttonNumber;
}
}
public int getButtonNumber(){
return buttonNumber;
}
public void paintComponent(Graphics g){
super.paintComponent(g);
if (buttonNumber != MinesweeperIcons.NULL) {
ImageIcon icon = msIcons.getIcon(buttonNumber);
Image img = icon.getImage();
int x = MinesweeperUtils.roundToInt(getSize().getWidth() / 5);
int y = MinesweeperUtils.roundToInt(getSize().getHeight() / 5);
int width = MinesweeperUtils.roundToInt((3.0/5.0) * getSize().getWidth());
int height = MinesweeperUtils.roundToInt((3.0/5.0) * getSize().getHeight());
g.drawImage(img, x, y, width, height, this);
}
}
}