Skip to content

Commit e8334b9

Browse files
authored
Add files via upload
1 parent 7bb2e90 commit e8334b9

15 files changed

Lines changed: 147 additions & 100 deletions

File tree

Campeonato/pom.xml

Lines changed: 28 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -12,97 +12,52 @@
1212
<properties>
1313
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1414
<mainClass>application.MainApp</mainClass>
15+
<maven.compiler.source>1.8</maven.compiler.source>
16+
<maven.compiler.target>1.8</maven.compiler.target>
1517
</properties>
1618

1719
<organization>
1820
<!-- Used as the 'Vendor' for JNLP generation -->
1921
<name>Your Organisation</name>
2022
</organization>
2123

22-
<build>
24+
<build>
2325
<plugins>
2426
<plugin>
25-
<groupId>org.apache.maven.plugins</groupId>
26-
<artifactId>maven-dependency-plugin</artifactId>
27-
<version>2.6</version>
27+
<artifactId>maven-assembly-plugin</artifactId>
28+
<version>2.5.3</version>
29+
<configuration>
30+
<descriptorRefs>
31+
<descriptorRef>jar-with-dependencies</descriptorRef>
32+
</descriptorRefs>
33+
<archive>
34+
<manifest>
35+
<mainClass>${mainClass}</mainClass>
36+
</manifest>
37+
</archive>
38+
</configuration>
2839
<executions>
2940
<execution>
30-
<id>unpack-dependencies</id>
41+
<id>make-assembly</id>
3142
<phase>package</phase>
3243
<goals>
33-
<goal>unpack-dependencies</goal>
44+
<goal>single</goal>
3445
</goals>
35-
<configuration>
36-
<excludeScope>system</excludeScope>
37-
<excludeGroupIds>junit,org.mockito,org.hamcrest</excludeGroupIds>
38-
<outputDirectory>${project.build.directory}/classes</outputDirectory>
39-
</configuration>
4046
</execution>
4147
</executions>
4248
</plugin>
43-
<plugin>
44-
<groupId>org.codehaus.mojo</groupId>
45-
<artifactId>exec-maven-plugin</artifactId>
46-
<version>1.2.1</version>
47-
<executions>
48-
<execution>
49-
<id>unpack-dependencies</id>
50-
51-
<phase>package</phase>
52-
<goals>
53-
<goal>exec</goal>
54-
</goals>
55-
<configuration>
56-
<executable>${java.home}/../bin/javafxpackager</executable>
57-
<arguments>
58-
<argument>-createjar</argument>
59-
<argument>-nocss2bin</argument>
60-
<argument>-appclass</argument>
61-
<argument>${mainClass}</argument>
62-
<argument>-srcdir</argument>
63-
<argument>${project.build.directory}/classes</argument>
64-
<argument>-outdir</argument>
65-
<argument>${project.build.directory}</argument>
66-
<argument>-outfile</argument>
67-
<argument>${project.build.finalName}.jar</argument>
68-
</arguments>
69-
</configuration>
70-
</execution>
71-
<execution>
72-
<id>default-cli</id>
73-
<goals>
74-
<goal>exec</goal>
75-
</goals>
76-
<configuration>
77-
<executable>${java.home}/bin/java</executable>
78-
<commandlineArgs>${runfx.args}</commandlineArgs>
79-
</configuration>
80-
</execution>
81-
</executions>
82-
</plugin>
83-
<plugin>
84-
<groupId>org.apache.maven.plugins</groupId>
85-
<artifactId>maven-compiler-plugin</artifactId>
86-
<version>3.1</version>
87-
<configuration>
88-
<source>1.7</source>
89-
<target>1.7</target>
90-
<compilerArguments>
91-
<bootclasspath>${sun.boot.class.path}${path.separator}${java.home}/lib/jfxrt.jar</bootclasspath>
92-
</compilerArguments>
93-
</configuration>
94-
</plugin>
95-
<plugin>
96-
<groupId>org.apache.maven.plugins</groupId>
97-
<artifactId>maven-surefire-plugin</artifactId>
98-
<version>2.16</version>
99-
<configuration>
100-
<additionalClasspathElements>
101-
<additionalClasspathElement>${java.home}/lib/jfxrt.jar</additionalClasspathElement>
102-
</additionalClasspathElements>
103-
</configuration>
104-
</plugin>
49+
50+
10551
</plugins>
10652
</build>
53+
54+
<dependencies>
55+
<dependency>
56+
<groupId>org.json</groupId>
57+
<artifactId>json</artifactId>
58+
<version>20141113</version>
59+
<type>jar</type>
60+
</dependency>
61+
</dependencies>
10762

10863
</project>

Campeonato/src/main/java/model/Jogo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public byte getGolB() {
6363

6464
public void setGolB(byte golB) {
6565
this.golB = golB;
66-
}
66+
}
6767

6868
@Override
6969
public String toString() {

Campeonato/src/main/java/model/Time.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ public List<Jogo> getJogos() {
152152
return jogos;
153153
}
154154

155+
public void setJogos(List<Jogo> jogos) {
156+
this.jogos = jogos;
157+
}
158+
155159
@Override
156160
public String toString() {
157161
return "Time{" + "nome=" + nome + ", ptos=" + getPontos() + '}';

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

Lines changed: 74 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@
66
package utilit;
77

88
import java.io.BufferedReader;
9+
import java.io.BufferedWriter;
10+
import java.io.File;
911
import java.io.FileReader;
12+
import java.io.FileWriter;
1013
import java.io.IOException;
1114
import java.util.ArrayList;
1215
import java.util.List;
1316
import model.Jogo;
1417
import model.Time;
18+
import org.json.JSONObject;
1519

1620
/**
1721
*
@@ -28,28 +32,76 @@ public class Dados {
2832
public Dados(String nomeArq) {
2933
this.nomeArq = nomeArq;
3034
}
31-
32-
private Time achaTime(String nomeBusca){
35+
36+
private Time achaTime(String nomeBusca) {
3337
for (Time t : lstTimes) {
3438
if (t.getNome().equals(nomeBusca)) {
3539
return t;
3640
}
3741
}
3842
Time novoTime = new Time(nomeBusca);
3943
lstTimes.add(novoTime);
40-
44+
4145
return novoTime;
4246
}
43-
44-
private void analisa (Jogo jg) {
47+
48+
public void gravaJogoTime(Time time) {
49+
try {
50+
String nomeArq = "C:\\dados\\" + time.getNome() + ".json";
51+
52+
File file = new File(nomeArq);
53+
file.createNewFile();
54+
FileWriter fw = new FileWriter(file.getAbsoluteFile());
55+
BufferedWriter bw = new BufferedWriter(fw);
56+
57+
JSONObject eJSON = new JSONObject();
58+
59+
for (Jogo j : time.getJogos()) {
60+
eJSON.put("timeA", j.getTimeA());
61+
eJSON.put("golA", j.getGolA());
62+
eJSON.put("timeB", j.getTimeB());
63+
eJSON.put("golB", j.getGolB());
64+
bw.write(eJSON.toString() + "\n");
65+
}
66+
67+
bw.close();
68+
} catch (Exception e) {
69+
System.out.println(e.getMessage());
70+
}
71+
}
72+
73+
public List<Jogo> lerJogoTime(Time time) {
74+
List<Jogo> info = new ArrayList<>();
75+
Jogo jogoTmp;
76+
String linha;
77+
try {
78+
br = new BufferedReader(new FileReader("C:\\dados\\" + time.getNome() + ".json"));
79+
while ((linha = br.readLine()) != null) {
80+
JSONObject eJSON = new JSONObject(linha);
81+
Integer golA = eJSON.getInt("golA");
82+
Integer golB = eJSON.getInt("golB");
83+
String timeA = eJSON.getString("timeA");
84+
String timeB = eJSON.getString("timeB");
85+
jogoTmp = new Jogo(timeA, golA.byteValue(),
86+
timeB, golB.byteValue());
87+
88+
info.add(jogoTmp);
89+
}
90+
} catch (Exception e) {
91+
System.out.println("Erro ao abrir arquivo!" + e.getMessage());
92+
}
93+
return info;
94+
}
95+
96+
private void analisa(Jogo jg) {
4597
Time posTimeA, posTimeB;
46-
98+
4799
posTimeA = achaTime(jg.getTimeA());
48100
posTimeB = achaTime(jg.getTimeB());
49-
101+
50102
posTimeA.getJogos().add(jg);
51103
posTimeB.getJogos().add(jg);
52-
104+
53105
if (jg.getGolA() > jg.getGolB()) { // A Venceu
54106
posTimeA.addVitoria();
55107
posTimeB.addDerrota();
@@ -60,50 +112,49 @@ private void analisa (Jogo jg) {
60112
posTimeA.addEmpate();
61113
posTimeB.addEmpate();
62114
}
63-
115+
64116
posTimeA.addGolPro(jg.getGolA());
65117
posTimeA.addGolContra(jg.getGolB());
66118
posTimeB.addGolPro(jg.getGolB());
67119
posTimeB.addGolContra(jg.getGolA());
68-
120+
69121
}
70-
122+
71123
public void ordena() {
72124
Time timeAux;
73125
int i, j;
74126
i = 1;
75127
while (i <= lstTimes.size() - 1) {
76-
j = i;
77-
while ((j > 0) && ((lstTimes.get(j - 1).getPontos() < lstTimes.get(j).getPontos()) ||
78-
((lstTimes.get(j - 1).getPontos() == lstTimes.get(j).getPontos()) &&
79-
(lstTimes.get(j - 1).getVitorias() < lstTimes.get(j).getVitorias())) ||
80-
((lstTimes.get(j - 1).getVitorias() == lstTimes.get(j).getVitorias()) &&
81-
(lstTimes.get(j - 1).getSaldo()< lstTimes.get(j).getSaldo()))))
82-
{
128+
j = i;
129+
while ((j > 0) && ((lstTimes.get(j - 1).getPontos() < lstTimes.get(j).getPontos())
130+
|| ((lstTimes.get(j - 1).getPontos() == lstTimes.get(j).getPontos())
131+
&& (lstTimes.get(j - 1).getVitorias() < lstTimes.get(j).getVitorias()))
132+
|| ((lstTimes.get(j - 1).getVitorias() == lstTimes.get(j).getVitorias())
133+
&& (lstTimes.get(j - 1).getSaldo() < lstTimes.get(j).getSaldo())))) {
83134
timeAux = lstTimes.get(j - 1);
84135
lstTimes.set(j - 1, lstTimes.get(j));
85136
lstTimes.set(j, timeAux);
86137
j--;
87-
}
138+
}
88139
i++;
89-
}
140+
}
90141
}
91142

92143
public List<Time> ler() {
93144
String linha;
94145
try {
95146
br = new BufferedReader(new FileReader(nomeArq));
96-
while ((linha = br.readLine()) != null) {
147+
while ((linha = br.readLine()) != null) {
97148
jgLinha = new Jogo(linha);
98149
analisa(jgLinha);
99150
}
100151
ordena();
101-
152+
102153
byte i = 1;
103154
for (Time t : lstTimes) {
104155
t.setClas(i);
105156
i++;
106-
}
157+
}
107158

108159
} catch (Exception e) {
109160

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,23 @@ public void btnFecharJogo() {
7474
rdBtnDefalt.setSelected(true);
7575
}
7676

77+
@FXML
78+
private void btnSalvarJsonClick() {
79+
dados.gravaJogoTime(timeSel);
80+
}
81+
82+
@FXML
83+
public void btnLerJogosTimeClick() {
84+
timeSel.setJogos(dados.lerJogoTime(timeSel));
85+
tblVwJogos.setItems(FXCollections.observableList(timeSel.getJogos()));
86+
}
87+
88+
@FXML
89+
private void btnLimparClick() {
90+
timeSel.getJogos().clear();
91+
tblVwJogos.setItems(FXCollections.observableList(timeSel.getJogos()));
92+
}
93+
7794
@FXML
7895
public void rdBtnTodos() {
7996
tblVwJogos.setItems(FXCollections.observableList(timeSel.getJogos()));

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,17 @@
141141
</TableColumn>
142142
</columns>
143143
</TableView>
144-
<Button mnemonicParsing="false" onAction="#btnFecharJogo" text="Fechar" />
144+
<HBox alignment="CENTER" spacing="10.0">
145+
<children>
146+
<Button mnemonicParsing="false" onAction="#btnSalvarJsonClick" text="Salvar Json" />
147+
<Button layoutX="241.0" layoutY="10.0" mnemonicParsing="false" onAction="#btnLerJogosTimeClick" text="Abrir Json" />
148+
<Button layoutX="273.0" layoutY="10.0" mnemonicParsing="false" onAction="#btnLimparClick" text="Limpar" />
149+
<Button layoutX="10.0" layoutY="10.0" mnemonicParsing="false" onAction="#btnFecharJogo" text="Fechar" />
150+
</children>
151+
<VBox.margin>
152+
<Insets bottom="5.0" top="5.0" />
153+
</VBox.margin>
154+
</HBox>
145155
</children>
146156
</VBox>
147157
</children>
76.9 KB
Binary file not shown.
2.88 KB
Binary file not shown.
0 Bytes
Binary file not shown.

Campeonato/target/classes/fxml/Principal.fxml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,17 @@
141141
</TableColumn>
142142
</columns>
143143
</TableView>
144-
<Button mnemonicParsing="false" onAction="#btnFecharJogo" text="Fechar" />
144+
<HBox alignment="CENTER" spacing="10.0">
145+
<children>
146+
<Button mnemonicParsing="false" onAction="#btnSalvarJsonClick" text="Salvar Json" />
147+
<Button layoutX="241.0" layoutY="10.0" mnemonicParsing="false" onAction="#btnLerJogosTimeClick" text="Abrir Json" />
148+
<Button layoutX="273.0" layoutY="10.0" mnemonicParsing="false" onAction="#btnLimparClick" text="Limpar" />
149+
<Button layoutX="10.0" layoutY="10.0" mnemonicParsing="false" onAction="#btnFecharJogo" text="Fechar" />
150+
</children>
151+
<VBox.margin>
152+
<Insets bottom="5.0" top="5.0" />
153+
</VBox.margin>
154+
</HBox>
145155
</children>
146156
</VBox>
147157
</children>

0 commit comments

Comments
 (0)