Skip to content

Commit e084821

Browse files
Exercícios de JavaFX
1 parent 1daa9f1 commit e084821

30 files changed

+1112
-0
lines changed

exercicios-javafx/.classpath

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-12">
5+
<attributes>
6+
<attribute name="module" value="true"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/JavaFX13">
10+
<attributes>
11+
<attribute name="module" value="true"/>
12+
</attributes>
13+
</classpathentry>
14+
<classpathentry kind="lib" path="lib/controlsfx-11.0.1.jar">
15+
<attributes>
16+
<attribute name="module" value="true"/>
17+
</attributes>
18+
</classpathentry>
19+
<classpathentry kind="output" path="bin"/>
20+
</classpath>

exercicios-javafx/.project

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+
<projectDescription>
3+
<name>exercicios-javafx</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=12
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=12
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
11+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12+
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
13+
org.eclipse.jdt.core.compiler.release=enabled
14+
org.eclipse.jdt.core.compiler.source=12
925 KB
Binary file not shown.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
.conteudo {
2+
-fx-background-color: #000;
3+
-fx-font-family: Oswald;
4+
}
5+
6+
.titulo {
7+
-fx-text-fill: #48b2ee;
8+
-fx-font-size: 36px;
9+
}
10+
11+
.numero {
12+
-fx-text-fill: #eee;
13+
-fx-font-size: 28px;
14+
}
15+
16+
.botoes {
17+
-fx-background-color: #fff;
18+
-fx-text-fill: #48b2ee;
19+
-fx-font-size: 28px;
20+
-fx-min-width: 60px;
21+
-fx-min-height: 60px;
22+
-fx-background-radius: 30px;
23+
}
24+
25+
.verde {
26+
-fx-text-fill: #4bdb82;
27+
}
28+
29+
.vermelho {
30+
-fx-text-fill: #ee4139;
31+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package basico;
2+
3+
import javafx.application.Application;
4+
import javafx.geometry.Pos;
5+
import javafx.scene.Scene;
6+
import javafx.scene.control.Button;
7+
import javafx.scene.control.Label;
8+
import javafx.scene.layout.HBox;
9+
import javafx.scene.layout.VBox;
10+
import javafx.stage.Stage;
11+
12+
public class Contador extends Application {
13+
14+
private int contador = 0;
15+
16+
private void atualizarLabelNumero(Label label) {
17+
label.setText(Integer.toString(contador));
18+
19+
label.getStyleClass().remove("verde");
20+
label.getStyleClass().remove("vermelho");
21+
22+
if(contador > 0) {
23+
label.getStyleClass().add("verde");
24+
} else if(contador < 0) {
25+
label.getStyleClass().add("vermelho");
26+
}
27+
}
28+
29+
@Override
30+
public void start(Stage primaryStage) throws Exception {
31+
32+
Label labelTitulo = new Label("Contador");
33+
labelTitulo.getStyleClass().add("titulo");
34+
35+
Label labelNumero = new Label("0");
36+
labelNumero.getStyleClass().add("numero");
37+
38+
Button botaoDecremento = new Button("-");
39+
botaoDecremento.getStyleClass().add("botoes");
40+
botaoDecremento.setOnAction(e -> {
41+
contador--;
42+
atualizarLabelNumero(labelNumero);
43+
});
44+
45+
Button botaoIncremento = new Button("+");
46+
botaoIncremento.getStyleClass().add("botoes");
47+
botaoIncremento.setOnAction(e -> {
48+
contador++;
49+
atualizarLabelNumero(labelNumero);
50+
});
51+
52+
HBox boxBotoes = new HBox();
53+
boxBotoes.setAlignment(Pos.CENTER);
54+
boxBotoes.setSpacing(10);
55+
boxBotoes.getChildren().add(botaoDecremento);
56+
boxBotoes.getChildren().add(botaoIncremento);
57+
58+
VBox boxConteudo = new VBox();
59+
boxConteudo.getStyleClass().add("conteudo");
60+
boxConteudo.setSpacing(10);
61+
boxConteudo.setAlignment(Pos.CENTER);
62+
boxConteudo.getChildren().add(labelTitulo);
63+
boxConteudo.getChildren().add(labelNumero);
64+
boxConteudo.getChildren().add(boxBotoes);
65+
66+
String caminhoDoCss = getClass()
67+
.getResource("/basico/Contador.css").toExternalForm();
68+
69+
Scene cenaPrincipal = new Scene(boxConteudo, 400, 400);
70+
cenaPrincipal.getStylesheets().add(caminhoDoCss);
71+
cenaPrincipal.getStylesheets().add("https://fonts.googleapis.com/css?family=Oswald");
72+
73+
primaryStage.setScene(cenaPrincipal);
74+
primaryStage.show();
75+
}
76+
77+
public static void main(String[] args) {
78+
launch(args);
79+
}
80+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package basico;
2+
3+
import javafx.application.Application;
4+
import javafx.geometry.Pos;
5+
import javafx.scene.Scene;
6+
import javafx.scene.control.Button;
7+
import javafx.scene.layout.HBox;
8+
import javafx.stage.Stage;
9+
10+
public class PrimeiroFX extends Application {
11+
12+
@Override
13+
public void start(Stage primaryStage) throws Exception {
14+
15+
Button botaoA = new Button("A");
16+
Button botaoB = new Button("B");
17+
Button botaoC = new Button("C");
18+
19+
botaoA.setOnAction(e -> System.out.println("A"));
20+
botaoB.setOnAction(e -> System.out.println("B"));
21+
botaoC.setOnAction(e -> System.exit(0));
22+
23+
HBox box = new HBox();
24+
box.setAlignment(Pos.CENTER);
25+
box.setSpacing(10);
26+
box.getChildren().add(botaoA);
27+
box.getChildren().add(botaoB);
28+
box.getChildren().add(botaoC);
29+
30+
Scene unicaCena = new Scene(box, 150, 100);
31+
32+
primaryStage.setScene(unicaCena);
33+
primaryStage.show();
34+
}
35+
36+
public static void main(String[] args) {
37+
launch(args);
38+
}
39+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package basico;
2+
3+
import javafx.application.Application;
4+
import javafx.geometry.Pos;
5+
import javafx.scene.Scene;
6+
import javafx.scene.control.Button;
7+
import javafx.scene.layout.HBox;
8+
import javafx.stage.Stage;
9+
10+
public class Wizard extends Application {
11+
12+
private Stage janela;
13+
private Scene passo1;
14+
private Scene passo2;
15+
private Scene passo3;
16+
17+
@Override
18+
public void start(Stage primaryStage) throws Exception {
19+
janela = primaryStage;
20+
21+
criarPasso1();
22+
criarPasso2();
23+
criarPasso3();
24+
25+
janela.setScene(passo1);
26+
janela.setTitle("Wizard :: Passo 01");
27+
janela.show();
28+
}
29+
30+
private void criarPasso1() {
31+
Button proximoPasso = new Button("Ir p/ Passo 2 >>");
32+
proximoPasso.setOnAction(e -> {
33+
janela.setScene(passo2);
34+
janela.setTitle("Wizard :: Passo 02");
35+
});
36+
37+
HBox box = new HBox();
38+
box.setAlignment(Pos.CENTER);
39+
box.getChildren().add(proximoPasso);
40+
41+
passo1 = new Scene(box, 400, 400);
42+
}
43+
44+
private void criarPasso2() {
45+
Button passoAnterior = new Button("<< Voltar p/ Passo 1");
46+
passoAnterior.setOnAction(e -> {
47+
janela.setScene(passo1);
48+
janela.setTitle("Wizard :: Passo 01");
49+
});
50+
51+
Button proximoPasso = new Button("Ir p/ Passo 3 >>");
52+
proximoPasso.setOnAction(e -> {
53+
janela.setScene(passo3);
54+
janela.setTitle("Wizard :: Passo 03");
55+
});
56+
57+
HBox box = new HBox();
58+
box.setAlignment(Pos.CENTER);
59+
box.getChildren().add(passoAnterior);
60+
box.getChildren().add(proximoPasso);
61+
62+
passo2 = new Scene(box, 400, 400);
63+
}
64+
65+
private void criarPasso3() {
66+
Button passoAnterior = new Button("<< Voltar p/ Passo 2");
67+
passoAnterior.setOnAction(e -> {
68+
janela.setScene(passo2);
69+
});
70+
71+
Button proximoPasso = new Button("Finalizar!");
72+
proximoPasso.setOnAction(e -> {
73+
System.exit(0);
74+
});
75+
76+
HBox box = new HBox();
77+
box.setAlignment(Pos.CENTER);
78+
box.getChildren().add(passoAnterior);
79+
box.getChildren().add(proximoPasso);
80+
81+
passo3 = new Scene(box, 400, 400);
82+
}
83+
84+
public static void main(String[] args) {
85+
launch(args);
86+
}
87+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package calculadora;
2+
3+
import javafx.application.Application;
4+
import javafx.scene.Scene;
5+
import javafx.scene.paint.Color;
6+
import javafx.scene.text.Font;
7+
import javafx.stage.Stage;
8+
import javafx.stage.StageStyle;
9+
10+
public class App extends Application {
11+
12+
private double posX = 0;
13+
private double posY = 0;
14+
15+
@Override
16+
public void start(Stage primaryStage) throws Exception {
17+
Font.loadFont(getClass().getResource("/calculadora/Roboto.ttf").toExternalForm(), 10);
18+
String css = getClass().getResource("/calculadora/Calculadora.css").toExternalForm();
19+
20+
Scene principal = new Scene(new Calculadora(), 230, 320);
21+
principal.setFill(Color.TRANSPARENT);
22+
principal.getStylesheets().add(css);
23+
24+
principal.setOnMousePressed(event -> {
25+
posX = primaryStage.getX() - event.getScreenX();
26+
posY = primaryStage.getY() - event.getScreenY();
27+
});
28+
29+
principal.setOnMouseDragged(e -> {
30+
primaryStage.setX(e.getScreenX() + posX);
31+
primaryStage.setY(e.getScreenY() + posY);
32+
});
33+
34+
primaryStage.setScene(principal);
35+
primaryStage.initStyle(StageStyle.TRANSPARENT);
36+
primaryStage.show();
37+
}
38+
39+
public static void main(String[] args) {
40+
launch(args);
41+
}
42+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package calculadora;
2+
3+
import javafx.scene.control.Button;
4+
import javafx.scene.layout.HBox;
5+
6+
public class BarraTitulo extends HBox {
7+
8+
private Button botaoFechar = new Button("");
9+
10+
public BarraTitulo() {
11+
getStyleClass().add("barra-titulo");
12+
13+
botaoFechar.setOnAction(e -> System.exit(0));
14+
15+
setOnMouseEntered(e -> botaoFechar.setText("×"));
16+
setOnMouseExited(e -> botaoFechar.setText(""));
17+
18+
botaoFechar.getStyleClass().add("botao-fechar");
19+
getChildren().add(botaoFechar);
20+
}
21+
}

0 commit comments

Comments
 (0)