Skip to content

Commit 54196c9

Browse files
authored
Add files via upload
1 parent d1af7cd commit 54196c9

11 files changed

Lines changed: 221 additions & 45 deletions

File tree

Campeonato/nbactions.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<actions>
3+
<action>
4+
<actionName>run</actionName>
5+
<packagings>
6+
<packaging>jar</packaging>
7+
</packagings>
8+
<goals>
9+
<goal>process-classes</goal>
10+
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
11+
</goals>
12+
<properties>
13+
<exec.args>-classpath %classpath application.MainApp</exec.args>
14+
<exec.executable>java</exec.executable>
15+
</properties>
16+
</action>
17+
</actions>

Campeonato/src/main/java/utilit/Dados.java

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,35 @@ public void gravaJogoTime(Time time) {
6969
System.out.println(e.getMessage());
7070
}
7171
}
72+
73+
public void gravaTodosJson(List<Time> lstPrinc) {
74+
try {
75+
String nomeArq = "C:\\dados\\campeonato.json";
76+
77+
File file = new File(nomeArq);
78+
file.createNewFile();
79+
FileWriter fw = new FileWriter(file.getAbsoluteFile());
80+
BufferedWriter bw = new BufferedWriter(fw);
81+
82+
JSONObject eJSON = new JSONObject();
83+
84+
for (Time t: lstPrinc) {
85+
for (Jogo j : t.getJogos()) {
86+
if (j.timeA.equals(t.getNome())) {
87+
eJSON.put("timeA", j.getTimeA());
88+
eJSON.put("golA", j.getGolA());
89+
eJSON.put("timeB", j.getTimeB());
90+
eJSON.put("golB", j.getGolB());
91+
bw.write(eJSON.toString() + "\n");
92+
}
93+
}
94+
}
95+
96+
bw.close();
97+
} catch (Exception e) {
98+
System.out.println(e.getMessage());
99+
}
100+
}
72101

73102
public List<Jogo> lerJogoTime(Time time) {
74103
List<Jogo> info = new ArrayList<>();
@@ -119,6 +148,36 @@ private void analisa(Jogo jg) {
119148
posTimeB.addGolContra(jg.getGolA());
120149

121150
}
151+
152+
public List<Time> lerJSON() {
153+
lstTimes.clear();
154+
Jogo jogoTmp;
155+
String linha;
156+
try {
157+
br = new BufferedReader(new FileReader("C:\\dados\\campeonato.json"));
158+
while ((linha = br.readLine()) != null) {
159+
JSONObject eJSON = new JSONObject(linha);
160+
Integer golA = eJSON.getInt("golA");
161+
Integer golB = eJSON.getInt("golB");
162+
String timeA = eJSON.getString("timeA");
163+
String timeB = eJSON.getString("timeB");
164+
jogoTmp = new Jogo(timeA, golA.byteValue(),
165+
timeB, golB.byteValue());
166+
167+
analisa(jogoTmp);
168+
}
169+
ordena();
170+
System.out.println(lstTimes.size());
171+
byte i = 1;
172+
for (Time t : lstTimes) {
173+
t.setClas(i);
174+
i++;
175+
}
176+
} catch (Exception e) {
177+
System.out.println("Erro ao abrir arquivo!" + e.getMessage());
178+
}
179+
return lstTimes;
180+
}
122181

123182
public void ordena() {
124183
Time timeAux;
@@ -139,6 +198,26 @@ public void ordena() {
139198
i++;
140199
}
141200
}
201+
202+
public void ordenaAleat(List<Time> lstCmpAleat) {
203+
Time timeAux;
204+
int i, j;
205+
i = 1;
206+
while (i <= lstCmpAleat.size() - 1) {
207+
j = i;
208+
while ((j > 0) && ((lstCmpAleat.get(j - 1).getPontos() < lstCmpAleat.get(j).getPontos())
209+
|| ((lstCmpAleat.get(j - 1).getPontos() == lstCmpAleat.get(j).getPontos())
210+
&& (lstCmpAleat.get(j - 1).getVitorias() < lstCmpAleat.get(j).getVitorias()))
211+
|| ((lstCmpAleat.get(j - 1).getVitorias() == lstCmpAleat.get(j).getVitorias())
212+
&& (lstCmpAleat.get(j - 1).getSaldo() < lstCmpAleat.get(j).getSaldo())))) {
213+
timeAux = lstCmpAleat.get(j - 1);
214+
lstCmpAleat.set(j - 1, lstCmpAleat.get(j));
215+
lstCmpAleat.set(j, timeAux);
216+
j--;
217+
}
218+
i++;
219+
}
220+
}
142221

143222
public List<Time> ler() {
144223
String linha;
@@ -168,5 +247,9 @@ public List<Time> ler() {
168247
}
169248
return lstTimes;
170249
}
250+
251+
public void limpaListaTimes() {
252+
lstTimes.clear();
253+
}
171254

172255
}

Campeonato/src/main/java/view/PrincipalController.java

Lines changed: 92 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import java.net.URL;
55
import java.util.ArrayList;
66
import java.util.List;
7+
import java.util.Random;
78
import java.util.ResourceBundle;
89
import javafx.collections.FXCollections;
9-
import javafx.event.ActionEvent;
1010
import javafx.event.Event;
1111
import javafx.fxml.FXML;
1212
import javafx.fxml.Initializable;
@@ -28,30 +28,31 @@ public class PrincipalController implements Initializable {
2828
private Dados dados;
2929
private List<Time> lstPrinc = new ArrayList<Time>();
3030
private List<Jogo> listaTemp = new ArrayList<Jogo>();
31+
private List<Time> lstCmpAleat = new ArrayList<Time>();
3132

3233
@FXML
3334
public TableView<Time> tblVwTimes;
34-
35+
3536
@FXML
3637
public TableView<Jogo> tblVwJogos;
37-
38+
3839
@FXML
3940
public Label lbNomeTime;
40-
41+
4142
@FXML
4243
public StackPane pnJogos;
4344

4445
@FXML
4546
public RadioButton rdBtnDefalt;
46-
47+
4748
public Time timeSel;
48-
49+
4950
@FXML
5051
private void btnFecharClick() {
5152
pnJogos.setVisible(false);
5253
tblVwTimes.requestFocus();
53-
}
54-
54+
}
55+
5556
@FXML
5657
public void tblVwClick(Event event) {
5758
MouseEvent me = null;
@@ -61,78 +62,89 @@ public void tblVwClick(Event event) {
6162
pnJogos.setVisible(true);
6263
timeSel = tblVwTimes.getSelectionModel().getSelectedItem();
6364
lbNomeTime.setText(timeSel.getNome());
64-
65+
6566
tblVwJogos.setItems(FXCollections.observableList(timeSel.getJogos()));
6667
}
67-
}
68-
68+
}
69+
6970
}
70-
71+
7172
@FXML
7273
public void btnFecharJogo() {
7374
pnJogos.setVisible(false);
7475
rdBtnDefalt.setSelected(true);
7576
}
76-
77+
7778
@FXML
78-
private void btnSalvarJsonClick() {
79-
dados.gravaJogoTime(timeSel);
79+
private void btnSalvarJsonClick() {
80+
dados.gravaJogoTime(timeSel);
8081
}
81-
82+
8283
@FXML
8384
public void btnLerJogosTimeClick() {
8485
timeSel.setJogos(dados.lerJogoTime(timeSel));
8586
tblVwJogos.setItems(FXCollections.observableList(timeSel.getJogos()));
8687
}
87-
88+
8889
@FXML
8990
private void btnLimparClick() {
9091
timeSel.getJogos().clear();
9192
tblVwJogos.setItems(FXCollections.observableList(timeSel.getJogos()));
9293
}
93-
94+
95+
@FXML
96+
private void btnLimpaCampClick() {
97+
lstPrinc.clear();
98+
dados.limpaListaTimes();
99+
lstCmpAleat.clear();
100+
tblVwTimes.setItems(FXCollections.observableList(lstPrinc));
101+
}
102+
94103
@FXML
95104
public void rdBtnTodos() {
96105
tblVwJogos.setItems(FXCollections.observableList(timeSel.getJogos()));
97106
}
98-
107+
99108
@FXML
100109
public void rdBtnVit() {
101110
listaTemp.clear();
102111
for (Jogo j : timeSel.getJogos()) {
103112
if (j.timeA.equals(timeSel.getNome())) {
104-
if(j.golA > j.getGolB())
105-
listaTemp.add(j);
106-
} else
107-
if(j.golA < j.getGolB())
113+
if (j.golA > j.getGolB()) {
108114
listaTemp.add(j);
115+
}
116+
} else if (j.golA < j.getGolB()) {
117+
listaTemp.add(j);
118+
}
109119
}
110120
tblVwJogos.setItems(FXCollections.observableList(listaTemp));
111121
}
112-
122+
113123
@FXML
114124
public void rdBtnEmp() {
115125
listaTemp.clear();
116126
for (Jogo j : timeSel.getJogos()) {
117-
if(j.golA == j.getGolB())
127+
if (j.golA == j.getGolB()) {
118128
listaTemp.add(j);
129+
}
119130
}
120131
tblVwJogos.setItems(FXCollections.observableList(listaTemp));
121132
}
122-
133+
123134
@FXML
124135
public void rdBtnDer() {
125136
listaTemp.clear();
126137
for (Jogo j : timeSel.getJogos()) {
127138
if (j.timeA.equals(timeSel.getNome())) {
128-
if(j.golA < j.getGolB())
129-
listaTemp.add(j);
130-
} else
131-
if(j.golA > j.getGolB())
139+
if (j.golA < j.getGolB()) {
132140
listaTemp.add(j);
141+
}
142+
} else if (j.golA > j.getGolB()) {
143+
listaTemp.add(j);
144+
}
133145
}
134146
tblVwJogos.setItems(FXCollections.observableList(listaTemp));
135-
}
147+
}
136148

137149
@FXML
138150
private void btnAbrirClick() {
@@ -148,7 +160,54 @@ private void btnAbrirClick() {
148160
tblVwTimes.setItems(FXCollections.observableList(lstPrinc));
149161

150162
}
151-
163+
164+
@FXML
165+
private void btnSalvarJson() {
166+
dados.gravaTodosJson(lstPrinc);
167+
}
168+
169+
@FXML
170+
private void btnLerJson() {
171+
final Stage stage = null;
172+
FileChooser fileChooser = new FileChooser();
173+
fileChooser.setTitle("Escolha o seu arquivo Txt");
174+
fileChooser.setInitialDirectory(new File("C:\\"));
175+
fileChooser.setInitialFileName("C:\\dados\\campeonato.txt");
176+
177+
dados = new Dados(String.valueOf(fileChooser.showOpenDialog(stage)));
178+
179+
tblVwTimes.setItems(FXCollections.observableList(dados.lerJSON()));
180+
}
181+
182+
@FXML
183+
private void btnAleatorioClick() {
184+
lstCmpAleat.clear();
185+
Random rand = new Random();
186+
Integer rd = rand.nextInt(lstPrinc.size());
187+
Time time;
188+
time = lstPrinc.get(rd);
189+
lstCmpAleat.add(time);
190+
for (Time t : lstCmpAleat)
191+
System.out.println(t.getNome());
192+
while (lstCmpAleat.size() < 15) {
193+
boolean rpt = false;
194+
for (Time t : lstCmpAleat) {
195+
if (t.getNome().equals(time.getNome()))
196+
rpt = true;
197+
}
198+
if (!rpt) lstCmpAleat.add(time);
199+
rd = rand.nextInt(lstPrinc.size());
200+
time = lstPrinc.get(rd);
201+
}
202+
dados.ordenaAleat(lstCmpAleat);
203+
byte i = 1;
204+
for (Time t : lstCmpAleat) {
205+
t.setClas(i);
206+
i++;
207+
}
208+
tblVwTimes.setItems(FXCollections.observableList(lstCmpAleat));
209+
}
210+
152211
@FXML
153212
private void btnSairClick() {
154213
System.exit(0);
@@ -162,5 +221,6 @@ public void initialize(URL url, ResourceBundle rb) {
162221
//lstPrinc = dados.ler();
163222
//tblVwTimes.setItems(FXCollections.observableList(lstPrinc));
164223
pnJogos.setVisible(false);
224+
165225
}
166226
}

Campeonato/src/main/resources/fxml/Principal.fxml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,22 @@
1313
<children>
1414
<VBox layoutX="164.0" layoutY="48.0" prefHeight="450.0" prefWidth="650.0" spacing="5.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
1515
<children>
16-
<HBox alignment="CENTER" spacing="500.0">
16+
<HBox alignment="CENTER" spacing="230.0">
1717
<children>
18-
<Button mnemonicParsing="false" onAction="#btnAbrirClick" text="Abrir" />
18+
<HBox alignment="CENTER" spacing="15.0">
19+
<children>
20+
<Button mnemonicParsing="false" onAction="#btnAbrirClick" text="Abrir" />
21+
<Button mnemonicParsing="false" onAction="#btnSalvarJson" text="Salvar JSON" />
22+
<Button mnemonicParsing="false" onAction="#btnLerJson" text="Ler JSON" />
23+
<Button mnemonicParsing="false" onAction="#btnLimpaCampClick" text="Limpar" />
24+
<Button mnemonicParsing="false" onAction="#btnAleatorioClick" text="Aleatorio" />
25+
</children>
26+
<opaqueInsets>
27+
<Insets />
28+
</opaqueInsets>
29+
</HBox>
1930
<Button mnemonicParsing="false" onAction="#btnSairClick" text="Sair" />
2031
</children>
21-
<opaqueInsets>
22-
<Insets />
23-
</opaqueInsets>
2432
<VBox.margin>
2533
<Insets top="5.0" />
2634
</VBox.margin>
@@ -89,7 +97,7 @@
8997
<Insets />
9098
</opaqueInsets>
9199
</VBox>
92-
<StackPane fx:id="pnJogos" prefHeight="450.0" prefWidth="660.0" style="-fx-background-color: f4f4f4;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
100+
<StackPane fx:id="pnJogos" opacity="0.0" prefHeight="450.0" prefWidth="660.0" style="-fx-background-color: f4f4f4;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
93101
<children>
94102
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0">
95103
<children>
-85 Bytes
Binary file not shown.
-69 Bytes
Binary file not shown.
73 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)