-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dice.java
34 lines (29 loc) · 1022 Bytes
/
Dice.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
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import java.awt.*;
import java.io.File;
import java.util.*;
public class Dice extends JPanel{
JLabel imageLabel = new JLabel();
int currentVal;
Border compound = BorderFactory.createCompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder());
public Dice(){
this.currentVal=currentVal;
this.add(imageLabel, BorderLayout.CENTER);
this.setBorder(compound);
this.setBackground(Color.white);
}
public int roll(){
int randRoll = new Random().nextInt(5)+1;
setBackgroundImage(randRoll);
currentVal=randRoll;
return randRoll;
}
public int getCurrentVal(){
return currentVal;
}
public void setBackgroundImage(int diceVal){
imageLabel.setIcon(new ImageIcon(new File("Images\\"+Integer.toString(diceVal)+".jpg").getAbsolutePath()));
}
}