-
Notifications
You must be signed in to change notification settings - Fork 0
/
GiraRoulette.java
127 lines (105 loc) · 4.19 KB
/
GiraRoulette.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import javax.swing.*;
import java.awt.*;
import java.util.Random;
public class GiraRoulette extends JFrame {
private int saldo;
private String name;
private Color coloreScelto;
private int puntata;
private JLabel mainLabel = new JLabel();
private JLabel titleLabel = new JLabel();
private JLabel percentageLabel = new JLabel();
private Font titleFont = new Font("LEMON MILK", Font.BOLD, 50);
private ImageIcon background = new ImageIcon("backgrounds/rouletteLoading.png");
private Font buttonsFont = new Font("LEMON MILK", Font.BOLD, 20);
private JProgressBar bar = new JProgressBar(0, 100);
public GiraRoulette(Color coloreScelto, int puntata, String name, int saldo) {
this.coloreScelto = coloreScelto;
this.puntata = puntata;
this.name=name;
this.saldo=saldo;
String temp = null;
if (coloreScelto.equals(Color.RED)) temp = "Rosso";
if (coloreScelto.equals(Color.BLACK)) temp = "Nero";
if (coloreScelto.equals(Color.GREEN)) temp = "Verde";
this.setTitle("Colore scelto: " + temp + " - Puntata: " + this.puntata + "$");
this.setResizable(false);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setSize(1300, 900);
this.setLayout(null);
this.setLocationRelativeTo(null);
this.setVisible(true);
mainLabel.setBounds(0, 0, 1300, 900);
mainLabel.setIcon(background);
titleLabel.setBounds(400, 303, 499, 105);
titleLabel.setFont(titleFont);
titleLabel.setText("GIRANDO...");
titleLabel.setForeground(Color.WHITE);
titleLabel.setHorizontalAlignment(JLabel.CENTER);
percentageLabel.setBounds(250, 396, 800, 30);
percentageLabel.setFont(buttonsFont.deriveFont(Font.BOLD, 18));
percentageLabel.setForeground(Color.WHITE);
percentageLabel.setHorizontalAlignment(JLabel.CENTER);
bar.setValue(0);
bar.setVisible(true);
bar.setFont(buttonsFont);
bar.setBounds(250, 441, 800, 50);
bar.setStringPainted(false);
bar.setBackground(Color.WHITE);
bar.setForeground(Color.WHITE);
this.add(bar);
this.add(percentageLabel);
this.add(titleLabel);
this.add(mainLabel);
fillProgressBar();
}
private void fillProgressBar() {
SwingWorker<Void, Integer> worker = new SwingWorker<Void, Integer>() {
@Override
protected Void doInBackground() throws Exception {
Random random = new Random();
for (int i = 0; i <= 100; i++) {
publish(i);
Thread.sleep(random.nextInt(91) + 10);
}
return null;
}
@Override
protected void process(java.util.List<Integer> chunks) {
int progress = chunks.get(chunks.size() - 1);
bar.setValue(progress);
percentageLabel.setText(progress + "%");
}
@Override
protected void done() {
dispose();
//Gira Roulette
Random random = new Random();
int x = random.nextInt(0, 101);
Color risultato=null;
int guadagno=0;
if(x==0) risultato = Color.GREEN;
if(x>0 && x<50) risultato = Color.RED;
if(x>=50) risultato = Color.BLACK;
if(coloreScelto == risultato){
if(coloreScelto==Color.GREEN) guadagno = puntata*25;
else guadagno = puntata*2;
}
else{
guadagno = puntata*-1;
}
int finalGuadagno = guadagno;
SwingUtilities.invokeLater(() -> {
Results results = new Results(puntata, finalGuadagno,saldo,name);
results.setVisible(true);
});
try {
Thread.sleep(100); // Pausa di 1 secondo per caricare correttamente il frame
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
};
worker.execute();
}
}