Skip to content

Commit dcb0bac

Browse files
committedDec 20, 2020
updated
1 parent 7447284 commit dcb0bac

10 files changed

+602
-1
lines changed
 

Diff for: ‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Rustam_Z🚀, 9.10.2020
1515
- Java Exceptions:
1616
- https://www.javatpoint.com/exception-handling-in-java
1717

18-
- Design Patterns, SOLID Principles- https://youtu.be/A1PWJB98qcw
18+
- Design Patterns, SOLID Principles - https://youtu.be/A1PWJB98qcw
1919

2020
- [Java Swing](java-swing)
2121

Diff for: ‎javafx-tutorial/ButtonExperiments.java

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import javafx.application.Application;
2+
import javafx.event.ActionEvent;
3+
import javafx.event.EventHandler;
4+
import javafx.scene.Scene;
5+
import javafx.scene.control.Button;
6+
import javafx.scene.control.Label;
7+
import javafx.scene.layout.HBox;
8+
import javafx.stage.Stage;
9+
10+
public class ButtonExperiments extends Application {
11+
12+
@Override
13+
public void start(Stage primaryStage) throws Exception {
14+
primaryStage.setTitle("HBox Experiment 1");
15+
16+
Label label = new Label("Not clicked");
17+
Button button = new Button("Click");
18+
19+
button.setOnAction(value -> {
20+
label.setText("Clicked!");
21+
System.out.println("Button Clicked!");
22+
});
23+
24+
HBox hbox = new HBox(button, label);
25+
26+
Scene scene = new Scene(hbox, 200, 100);
27+
primaryStage.setScene(scene);
28+
primaryStage.show();
29+
30+
}
31+
32+
public static void main(String[] args) {
33+
Application.launch(args);
34+
}
35+
}
36+
37+

Diff for: ‎javafx-tutorial/EventFiltersExample.java

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import javafx.application.Application;
2+
import static javafx.application.Application.launch;
3+
import javafx.event.EventHandler;
4+
5+
import javafx.scene.Group;
6+
import javafx.scene.Scene;
7+
import javafx.scene.input.MouseEvent;
8+
import javafx.scene.paint.Color;
9+
import javafx.scene.shape.Circle;
10+
11+
import javafx.scene.text.Font;
12+
import javafx.scene.text.FontWeight;
13+
import javafx.scene.text.Text;
14+
import javafx.stage.Stage;
15+
16+
public class EventFiltersExample extends Application {
17+
@Override
18+
public void start(Stage stage) {
19+
//Drawing a Circle
20+
Circle circle = new Circle();
21+
22+
//Setting the position of the circle
23+
circle.setCenterX(300.0f);
24+
circle.setCenterY(135.0f);
25+
26+
//Setting the radius of the circle
27+
circle.setRadius(25.0f);
28+
29+
//Setting the color of the circle
30+
circle.setFill(Color.BROWN);
31+
32+
//Setting the stroke width of the circle
33+
circle.setStrokeWidth(20);
34+
35+
//Setting the text
36+
Text text = new Text("Click on the circle to change its color");
37+
38+
//Setting the font of the text
39+
text.setFont(Font.font(null, FontWeight.BOLD, 15));
40+
41+
//Setting the color of the text
42+
text.setFill(Color.CRIMSON);
43+
44+
//setting the position of the text
45+
text.setX(150);
46+
text.setY(50);
47+
48+
//Creating the mouse event handler
49+
EventHandler<MouseEvent> eventHandler = new EventHandler<MouseEvent>() {
50+
@Override
51+
public void handle(MouseEvent e) {
52+
System.out.println("Hello World");
53+
circle.setFill(Color.DARKSLATEBLUE);
54+
}
55+
};
56+
//Registering the event filter
57+
circle.addEventFilter(MouseEvent.MOUSE_CLICKED, eventHandler);
58+
59+
//Creating a Group object
60+
Group root = new Group(circle, text);
61+
62+
//Creating a scene object
63+
Scene scene = new Scene(root, 600, 300);
64+
65+
//Setting the fill color to the scene
66+
scene.setFill(Color.LAVENDER);
67+
68+
//Setting title to the Stage
69+
stage.setTitle("Event Filters Example");
70+
71+
//Adding scene to the stage
72+
stage.setScene(scene);
73+
74+
//Displaying the contents of the stage
75+
stage.show();
76+
}
77+
public static void main(String args[]){
78+
launch(args);
79+
}
80+
}

Diff for: ‎javafx-tutorial/JavaFXLayoutDemo.java

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*import javafx.application.Application;
2+
import javafx.scene.Group;
3+
import javafx.scene.Scene;
4+
import javafx.scene.paint.Color;
5+
import javafx.scene.shape.Rectangle;
6+
import javafx.stage.Stage;
7+
8+
public class JavaFXLayoutDemo extends Application {
9+
10+
@Override
11+
public void start(Stage stage) {
12+
Group root = new Group();
13+
Scene scene = new Scene(root, 500, 500, Color.BLACK);
14+
15+
Rectangle r = new Rectangle(25,25,250,250);
16+
r.setFill(Color.BLUE);
17+
root.getChildren().add(r);
18+
19+
stage.setTitle("JavaFX Scene Graph Demo");
20+
stage.setScene(scene);
21+
stage.show();
22+
}
23+
24+
public static void main(String[] args) {
25+
launch(args);
26+
}
27+
}*/
28+
29+
30+
import javafx.application.Application;
31+
import javafx.scene.Group;
32+
import javafx.scene.Scene;
33+
import javafx.scene.paint.Color;
34+
import javafx.scene.shape.Rectangle;
35+
import javafx.stage.Stage;
36+
import javafx.scene.control.Label;
37+
import javafx.scene.control.Button;
38+
import javafx.scene.control.TextField;
39+
import javafx.scene.layout.HBox;
40+
import javafx.scene.layout.VBox;
41+
42+
public class JavaFXLayoutDemo extends Application {
43+
44+
@Override
45+
public void start(Stage stage) {
46+
47+
Label lblName = new Label("What is your Name ?");
48+
TextField tfName = new TextField("Type your name ");
49+
Button btOk = new Button("Ok");
50+
51+
HBox group = new HBox();
52+
53+
group.getChildren().add(lblName);
54+
group.getChildren().add(tfName);
55+
group.getChildren().add(btOk);
56+
57+
Scene scene = new Scene(group,500, 500);
58+
59+
stage.setTitle("JavaFX Scene Graph Demo");
60+
stage.setScene(scene);
61+
stage.show();
62+
}
63+
64+
public static void main(String[] args) {
65+
launch(args);
66+
}
67+
}

Diff for: ‎javafx-tutorial/JavaFX_Tutorial_-_Jakob_Jenkov.docx

1.92 MB
Binary file not shown.

Diff for: ‎javafx-tutorial/MyFxApp.java

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
3+
import javafx.application.Application;
4+
import javafx.stage.Stage;
5+
6+
public class MyFxApp extends Application {
7+
8+
@Override
9+
public void start(Stage primaryStage) throws Exception {
10+
primaryStage.setTitle("My First JavaFX App");
11+
12+
primaryStage.show();
13+
}
14+
15+
}
16+
17+
*/
18+
19+
20+
/*
21+
import javafx.application.Application;
22+
import javafx.stage.Stage;
23+
24+
public class MyFxApp extends Application {
25+
26+
@Override
27+
public void start(Stage primaryStage) throws Exception {
28+
primaryStage.setTitle("My First JavaFX App");
29+
30+
primaryStage.show();
31+
}
32+
33+
public static void main(String[] args) {
34+
Application.launch(args);
35+
}
36+
37+
38+
}
39+
*/
40+
41+
import javafx.application.Application;
42+
import javafx.scene.Scene;
43+
import javafx.scene.control.Label;
44+
import javafx.stage.Stage;
45+
46+
public class MyFxApp extends Application {
47+
48+
@Override
49+
public void start(Stage primaryStage) throws Exception {
50+
primaryStage.setTitle("My First JavaFX App");
51+
52+
Label label = new Label("Hello World, JavaFX !");
53+
Scene scene = new Scene(label, 400, 200);
54+
primaryStage.setScene(scene);
55+
56+
primaryStage.show();
57+
}
58+
59+
public static void main(String[] args) {
60+
Application.launch(args);
61+
}
62+
}

Diff for: ‎javafx-tutorial/install Run javaFX apps.txt

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Download an appropriate JavaFX runtime for your operating system and unzip it to a desired location. For this tutorial, we will be using JavaFX .
2+
3+
Add an environment variable pointing to the lib directory of the runtime: (e.g. you have download and unziped "javafx-sdk-11.0.2")
4+
5+
6+
set PATH_TO_FX="C:\Program Files\javafx-sdk-11.0.2\lib"
7+
8+
You can now compile and run JavaFX applications from the command line using the JavaFX runtime.
9+
10+
Compile the application (e.g. use HelloFX.java from this sample) using:
11+
12+
javac --module-path %PATH_TO_FX% --add-modules javafx.controls HelloFX.java
13+
14+
Run the application (e.g. use HelloFX.java from this sample) using:
15+
16+
java --module-path %PATH_TO_FX% --add-modules javafx.controls HelloFX
17+
18+
reference : https://openjfx.io/openjfx-docs/#install-javafx
Binary file not shown.

Diff for: ‎lab-07-javafx/CalculatorJavaFX.java

+190
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
/*
2+
By Rustam Zokirov,
3+
U1910049
4+
Lab: #7
5+
Calculator Application
6+
*/
7+
8+
import javafx.application.Application;
9+
import javafx.scene.Scene;
10+
import javafx.stage.Stage;
11+
import javafx.scene.control.Button;
12+
import javafx.scene.control.Label;
13+
import javafx.scene.control.TextField;
14+
import javafx.scene.layout.GridPane;
15+
import javafx.scene.layout.HBox;
16+
import javafx.event.EventHandler;
17+
import javafx.event.ActionEvent;
18+
19+
public class CalculatorJavaFX extends Application {
20+
String value;
21+
String math;
22+
double num1, num2, result;
23+
24+
@Override
25+
public void start(Stage primaryStage) throws Exception {
26+
// Text Field
27+
TextField jtfSpace = new TextField();
28+
29+
// Button Field
30+
Button bOne = new Button("1");
31+
Button bTwo = new Button("2");
32+
Button bThree = new Button("3");
33+
Button bFour = new Button("4");
34+
Button bFive = new Button("5");
35+
Button bSix = new Button("6");
36+
Button bSeven = new Button("7");
37+
Button bEight = new Button("8");
38+
Button bNine = new Button("9");
39+
Button bZero = new Button("0");
40+
Button bAdd = new Button("+");
41+
Button bSub = new Button("-");
42+
Button bMul = new Button("*");
43+
Button bDiv = new Button("/");
44+
Button bEqual = new Button("=");
45+
Button bDot = new Button(".");
46+
47+
bOne.setOnAction(new EventHandler<ActionEvent>(){
48+
@Override
49+
public void handle(ActionEvent event) {
50+
jtfSpace.setText(jtfSpace.getText() + "1");
51+
}
52+
});
53+
bTwo.setOnAction(new EventHandler<ActionEvent>(){
54+
@Override
55+
public void handle(ActionEvent event) {
56+
jtfSpace.setText(jtfSpace.getText() + "2");
57+
}
58+
});
59+
bThree.setOnAction(new EventHandler<ActionEvent>(){
60+
@Override
61+
public void handle(ActionEvent event) {
62+
jtfSpace.setText(jtfSpace.getText() + "3");
63+
}
64+
});
65+
bFour.setOnAction(new EventHandler<ActionEvent>(){
66+
@Override
67+
public void handle(ActionEvent event) {
68+
jtfSpace.setText(jtfSpace.getText() + "4");
69+
}
70+
});
71+
bFive.setOnAction(new EventHandler<ActionEvent>(){
72+
@Override
73+
public void handle(ActionEvent event) {
74+
jtfSpace.setText(jtfSpace.getText() + "5");
75+
}
76+
});
77+
bSix.setOnAction(new EventHandler<ActionEvent>(){
78+
@Override
79+
public void handle(ActionEvent event) {
80+
jtfSpace.setText(jtfSpace.getText() + "6");
81+
}
82+
});
83+
bSeven.setOnAction(new EventHandler<ActionEvent>(){
84+
@Override
85+
public void handle(ActionEvent event) {
86+
jtfSpace.setText(jtfSpace.getText() + "7");
87+
}
88+
});
89+
bEight.setOnAction(new EventHandler<ActionEvent>(){
90+
@Override
91+
public void handle(ActionEvent event) {
92+
jtfSpace.setText(jtfSpace.getText() + "8");
93+
}
94+
});
95+
bNine.setOnAction(new EventHandler<ActionEvent>(){
96+
@Override
97+
public void handle(ActionEvent event) {
98+
jtfSpace.setText(jtfSpace.getText() + "9");
99+
}
100+
});
101+
bZero.setOnAction(new EventHandler<ActionEvent>(){
102+
@Override
103+
public void handle(ActionEvent event) {
104+
jtfSpace.setText(jtfSpace.getText() + "0");
105+
}
106+
});
107+
bDot.setOnAction(new EventHandler<ActionEvent>(){
108+
@Override
109+
public void handle(ActionEvent event) {
110+
jtfSpace.setText(jtfSpace.getText() + ".");
111+
}
112+
});
113+
bAdd.setOnAction(new EventHandler<ActionEvent>(){
114+
@Override
115+
public void handle(ActionEvent event) {
116+
math = "Add";
117+
value = jtfSpace.getText();
118+
num1 = Double.parseDouble(value);
119+
jtfSpace.setText("");
120+
}
121+
});
122+
bSub.setOnAction(new EventHandler<ActionEvent>(){
123+
@Override
124+
public void handle(ActionEvent event) {
125+
math = "Sub";
126+
value = jtfSpace.getText();
127+
num1 = Double.parseDouble(value);
128+
jtfSpace.setText("");
129+
}
130+
});
131+
bMul.setOnAction(new EventHandler<ActionEvent>(){
132+
@Override
133+
public void handle(ActionEvent event) {
134+
math = "Mul";
135+
value = jtfSpace.getText();
136+
num1 = Double.parseDouble(value);
137+
jtfSpace.setText("");
138+
}
139+
});
140+
bDiv.setOnAction(new EventHandler<ActionEvent>(){
141+
@Override
142+
public void handle(ActionEvent event) {
143+
math = "Div";
144+
value = jtfSpace.getText();
145+
num1 = Double.parseDouble(value);
146+
jtfSpace.setText("");
147+
}
148+
});
149+
150+
bEqual.setOnAction(new EventHandler<ActionEvent>(){
151+
@Override
152+
public void handle(ActionEvent event) {
153+
value = jtfSpace.getText();
154+
num2 = Double.parseDouble(value);
155+
switch (math) {
156+
case "Div": result = num1 / num2;
157+
case "Mul": result = num1 * num2;
158+
case "Add": result = num1 + num2;
159+
case "Sub": result = num1 - num2;
160+
}
161+
jtfSpace.setText("" + result);
162+
}
163+
});
164+
165+
GridPane root=new GridPane();
166+
HBox root2_1 = new HBox();
167+
HBox root2_2 = new HBox();
168+
HBox root2_3 = new HBox();
169+
HBox root2_4 = new HBox();
170+
Scene scene = new Scene(root, 150, 135);
171+
172+
root.addRow(0, jtfSpace);
173+
root.addRow(1, root2_4);
174+
root.addRow(2, root2_3);
175+
root.addRow(3, root2_2);
176+
root.addRow(4, root2_1);
177+
root2_1.getChildren().addAll(bZero, bDot, bEqual, bAdd);
178+
root2_2.getChildren().addAll(bOne, bTwo, bThree, bSub);
179+
root2_3.getChildren().addAll(bFour, bFive, bSix, bMul);
180+
root2_4.getChildren().addAll(bSeven, bEight, bNine, bDiv);
181+
182+
primaryStage.setScene(scene);
183+
primaryStage.setTitle("Calculator");
184+
primaryStage.show();
185+
}
186+
public static void main(String[] args) {
187+
Application.launch(args);
188+
}
189+
190+
}

Diff for: ‎lab-07-javafx/PrinterJavaFX.java

+147
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
/*
2+
By Rustam Zokirov,
3+
U1910049
4+
Lab: #7
5+
Printer Application
6+
*/
7+
8+
// import some libraries
9+
import javafx.application.Application;
10+
import javafx.stage.Stage;
11+
import javafx.scene.Scene;
12+
import javafx.scene.Group;
13+
import javafx.scene.layout.StackPane;
14+
import javafx.scene.text.Text;
15+
import javafx.scene.transform.Scale;
16+
import javafx.scene.control.TextArea;
17+
import javafx.scene.control.CheckBox;
18+
import javafx.scene.control.RadioButton;
19+
import javafx.scene.control.ComboBox;
20+
import javafx.scene.control.Button;
21+
import javafx.scene.control.Label;
22+
23+
public class PrinterJavaFX extends Application {
24+
25+
@Override
26+
public void start(Stage primaryStage) throws Exception {
27+
28+
Label labelPrinter = new Label("Printer: My Printer");
29+
labelPrinter.setLayoutX(30);
30+
labelPrinter.setLayoutY(10);
31+
labelPrinter.setPrefSize(150, 20);
32+
33+
Label txtQuality = new Label("Print Quality: ");
34+
txtQuality.setLayoutX(30);
35+
txtQuality.setLayoutY(100);
36+
txtQuality.setPrefSize(150, 20);
37+
38+
TextArea labelType = new TextArea();
39+
labelType.setLayoutX(25);
40+
labelType.setLayoutY(35);
41+
labelType.setPrefSize(50, 60);
42+
43+
TextArea txtSize = new TextArea();
44+
txtSize.setLayoutX(150);
45+
txtSize.setLayoutY(35);
46+
txtSize.setPrefSize(40, 60);
47+
48+
TextArea txtSpace = new TextArea();
49+
txtSpace.setLayoutX(270);
50+
txtSpace.setLayoutY(35);
51+
txtSpace.setPrefSize(50, 60);
52+
53+
CheckBox checkImage = new CheckBox("Image");
54+
checkImage.setLayoutX(75);
55+
checkImage.setLayoutY(37);
56+
checkImage.setPrefSize(70, 20);
57+
58+
CheckBox checkText = new CheckBox("Text");
59+
checkText.setLayoutX(75);
60+
checkText.setLayoutY(57);
61+
checkText.setPrefSize(70, 20);
62+
63+
CheckBox checkCode = new CheckBox("Code");
64+
checkCode.setLayoutX(75);
65+
checkCode.setLayoutY(77);
66+
checkCode.setPrefSize(70, 20);
67+
68+
CheckBox checkPrint = new CheckBox("Print to File");
69+
checkPrint.setLayoutX(220);
70+
checkPrint.setLayoutY(100);
71+
checkPrint.setPrefSize(100, 20);
72+
73+
RadioButton radioSelect = new RadioButton("Select");
74+
radioSelect.setLayoutX(190);
75+
radioSelect.setLayoutY(37);
76+
radioSelect.setPrefSize(70, 20);
77+
78+
RadioButton radioAll = new RadioButton("All");
79+
radioAll.setLayoutX(190);
80+
radioAll.setLayoutY(57);
81+
radioAll.setPrefSize(70, 20);
82+
83+
RadioButton radioApplet = new RadioButton("Applet");
84+
radioApplet.setLayoutX(190);
85+
radioApplet.setLayoutY(77);
86+
radioApplet.setPrefSize(70, 20);
87+
88+
ComboBox comboQuality = new ComboBox();
89+
comboQuality.getItems().add("High");
90+
comboQuality.getItems().add("Middle");
91+
comboQuality.getItems().add("Low");
92+
comboQuality.setLayoutX(115);
93+
comboQuality.setLayoutY(100);
94+
comboQuality.setPrefSize(75, 20);
95+
96+
Button buttonOk = new Button("OK");
97+
buttonOk.setLayoutX(330);
98+
buttonOk.setLayoutY(20);
99+
buttonOk.setPrefSize(80, 30);
100+
101+
Button buttonCancel = new Button("Cancel");
102+
buttonCancel.setLayoutX(330);
103+
buttonCancel.setLayoutY(50);
104+
buttonCancel.setPrefSize(80, 30);
105+
106+
Button buttonSetup = new Button("Setup...");
107+
buttonSetup.setLayoutX(330);
108+
buttonSetup.setLayoutY(80);
109+
buttonSetup.setPrefSize(80, 30);
110+
111+
Button buttonHelp = new Button("Help");
112+
buttonHelp.setLayoutX(330);
113+
buttonHelp.setLayoutY(110);
114+
buttonHelp.setPrefSize(80, 30);
115+
116+
Group root = new Group();
117+
118+
root.getChildren().add(labelPrinter);
119+
root.getChildren().add(txtQuality);
120+
root.getChildren().add(labelType);
121+
root.getChildren().add(txtSize);
122+
root.getChildren().add(txtSpace);
123+
root.getChildren().add(checkImage);
124+
root.getChildren().add(checkCode);
125+
root.getChildren().add(checkPrint);
126+
root.getChildren().add(checkText);
127+
root.getChildren().add(radioAll);
128+
root.getChildren().add(radioApplet);
129+
root.getChildren().add(radioSelect);
130+
root.getChildren().add(comboQuality);
131+
root.getChildren().add(buttonCancel);
132+
root.getChildren().add(buttonHelp);
133+
root.getChildren().add(buttonOk);
134+
root.getChildren().add(buttonSetup);
135+
136+
// New scene
137+
Scene scene = new Scene(root, 450, 200);
138+
139+
primaryStage.setScene(scene);
140+
primaryStage.setTitle("Printer");
141+
primaryStage.show();
142+
143+
}
144+
public static void main(String[] args) {
145+
launch(args); // running app
146+
}
147+
}

0 commit comments

Comments
 (0)
Please sign in to comment.