Skip to content

Commit a9d5157

Browse files
author
Rajeev Kumar Singh
committed
Project renaming
1 parent 6cb17c4 commit a9d5157

File tree

14 files changed

+501
-0
lines changed

14 files changed

+501
-0
lines changed

javafx-css-demo-app/Readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
JavaFX CSS Demo Example
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package sample;
2+
3+
import javafx.application.Application;
4+
import javafx.fxml.FXMLLoader;
5+
import javafx.scene.Parent;
6+
import javafx.scene.Scene;
7+
import javafx.stage.Stage;
8+
9+
10+
public class CSSDemoApplication extends Application {
11+
12+
@Override
13+
public void start(Stage primaryStage) throws Exception {
14+
Parent root = FXMLLoader.load(getClass().getResource("css_demo.fxml"));
15+
Scene scene = new Scene(root, 800, 500);
16+
scene.getStylesheets().add(getClass().getResource("demo.css").toExternalForm());
17+
primaryStage.setScene(scene);
18+
primaryStage.show();
19+
}
20+
21+
public static void main(String[] args) {
22+
launch(args);
23+
}
24+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?import javafx.scene.layout.BorderPane?>
2+
<?import javafx.scene.layout.HBox?>
3+
<?import javafx.scene.layout.VBox?>
4+
<?import javafx.scene.control.Label?>
5+
<?import javafx.scene.control.Button?>
6+
<?import javafx.scene.image.ImageView?>
7+
<?import javafx.scene.image.Image?>
8+
<BorderPane>
9+
<top>
10+
<BorderPane styleClass="header-section">
11+
<left>
12+
<Label id="header-text" text="Application Header"></Label>
13+
</left>
14+
<right>
15+
<Button id="account" text="Account">
16+
<graphic>
17+
<ImageView fitHeight="24" fitWidth="24" pickOnBounds="true" preserveRatio="true">
18+
<image>
19+
<Image url="@javafx_account_example.png" />
20+
</image>
21+
</ImageView>
22+
</graphic>
23+
</Button>
24+
</right>
25+
</BorderPane>
26+
</top>
27+
<left>
28+
<VBox styleClass="sidebar-section">
29+
<children>
30+
<Label text="Sidebar Item1"></Label>
31+
<Label text="Sidebar Item2"></Label>
32+
<Label text="Sidebar Item3"></Label>
33+
<Label text="Sidebar Item4"></Label>
34+
</children>
35+
</VBox>
36+
</left>
37+
<center>
38+
<VBox styleClass="content-section">
39+
<children>
40+
<Label id="content-header" text="Content header"></Label>
41+
<Label id="content">
42+
<text>
43+
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
44+
</text>
45+
</Label>
46+
</children>
47+
</VBox>
48+
</center>
49+
<bottom>
50+
<HBox id="footer-section">
51+
<children>
52+
<Label text="Copyright 2017 CalliCoder"></Label>
53+
</children>
54+
</HBox>
55+
</bottom>
56+
</BorderPane>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
.root {
2+
-fx-font-size: 14px;
3+
-fx-font-family: sans-serif;
4+
-fx-background-color: #ffffff;
5+
}
6+
7+
.header-section {
8+
-fx-padding: 10px;
9+
-fx-font-size: 20px;
10+
-fx-background-color: teal;
11+
}
12+
13+
.header-section Label {
14+
-fx-text-fill: #ffffff;
15+
-fx-padding: 10px;
16+
}
17+
18+
#account {
19+
-fx-background-color: transparent;
20+
-fx-text-fill: #ffffff;
21+
-fx-font-size: 16px;
22+
-fx-cursor: hand;
23+
}
24+
25+
.sidebar-section {
26+
-fx-min-width: 200px;
27+
-fx-pref-width: 200px;
28+
-fx-max-width: 200px;
29+
-fx-border-width: 1;
30+
-fx-border-color: transparent #E8E8E8 transparent transparent;
31+
}
32+
33+
.sidebar-section Label {
34+
-fx-font-size: 18px;
35+
-fx-padding: 10 15 10 15;
36+
-fx-border-width: 1;
37+
-fx-border-color: transparent transparent #E8E8E8 transparent;
38+
-fx-min-width: 200px;
39+
-fx-pref-width: 200px;
40+
-fx-max-width: 200px;
41+
}
42+
43+
.content-section {
44+
-fx-padding: 10 20 10 20;
45+
-fx-wrap-text: true;
46+
47+
}
48+
49+
#content-header {
50+
-fx-font-size: 18px;
51+
-fx-padding: 0 0 10 0;
52+
-fx-font-weight: 700;
53+
}
54+
55+
#content {
56+
-fx-wrap-text: true;
57+
-fx-font-size: 16px;
58+
}
59+
60+
#footer-section {
61+
-fx-alignment: center;
62+
-fx-padding: 10 10 10 10;
63+
-fx-border-width: 1;
64+
-fx-border-color: #E8E8E8 transparent transparent transparent;
65+
}
Loading

javafx-hello-world/Readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## JavaFX Hello World Example with Lifecycle Methods
2+
3+
The Project contains a Simple JavaFX Hello World example with implementation of all the lifecycle methods.
4+
Compile and run `HelloWorldApplication.java` for running the program.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import javafx.application.Application;
2+
import javafx.geometry.Pos;
3+
import javafx.scene.Scene;
4+
import javafx.scene.control.Label;
5+
import javafx.stage.Stage;
6+
7+
public class HelloWorldApplication extends Application {
8+
9+
@Override
10+
public void init() throws Exception {
11+
super.init();
12+
System.out.println("Inside init() method! Perform necessary initializations here.");
13+
}
14+
15+
@Override
16+
public void start(Stage primaryStage) throws Exception {
17+
Label label = new Label("Hello World");
18+
label.setAlignment(Pos.CENTER);
19+
Scene scene = new Scene(label, 500, 350);
20+
21+
primaryStage.setTitle("Hello World Application");
22+
primaryStage.setScene(scene);
23+
primaryStage.show();
24+
}
25+
26+
@Override
27+
public void stop() throws Exception {
28+
super.stop();
29+
System.out.println("Inside stop() method! Destroy resources. Perform Cleanup.");
30+
}
31+
32+
public static void main(String[] args) {
33+
launch(args);
34+
}
35+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## JavaFX Registration Form Example
2+
3+
The Project explains how to create a Registration form in JavaFX.
4+
Compile and run `RegistrationFormApplication.java` for running the program.
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
import javafx.application.Application;
2+
import javafx.event.ActionEvent;
3+
import javafx.event.EventHandler;
4+
import javafx.geometry.HPos;
5+
import javafx.geometry.Insets;
6+
import javafx.geometry.Pos;
7+
import javafx.scene.Scene;
8+
import javafx.scene.control.*;
9+
import javafx.scene.layout.*;
10+
import javafx.scene.text.Font;
11+
import javafx.scene.text.FontWeight;
12+
import javafx.stage.Stage;
13+
import javafx.stage.Window;
14+
15+
public class RegistrationFormApplication extends Application {
16+
17+
@Override
18+
public void start(Stage primaryStage) throws Exception {
19+
primaryStage.setTitle("Registration Form JavaFX Application");
20+
21+
// Create the registration form grid pane
22+
GridPane gridPane = createRegistrationFormPane();
23+
// Add UI controls to the registration form grid pane
24+
addUIControls(gridPane);
25+
// Create a scene with registration form grid pane as the root node
26+
Scene scene = new Scene(gridPane, 800, 500);
27+
// Set the scene in primary stage
28+
primaryStage.setScene(scene);
29+
30+
primaryStage.show();
31+
}
32+
33+
34+
private GridPane createRegistrationFormPane() {
35+
// Instantiate a new Grid Pane
36+
GridPane gridPane = new GridPane();
37+
38+
// Position the pane at the center of the screen, both vertically and horizontally
39+
gridPane.setAlignment(Pos.CENTER);
40+
41+
// Set a padding of 20px on each side
42+
gridPane.setPadding(new Insets(40, 40, 40, 40));
43+
44+
// Set the horizontal gap between columns
45+
gridPane.setHgap(10);
46+
47+
// Set the vertical gap between rows
48+
gridPane.setVgap(10);
49+
50+
// Add Column Constraints
51+
52+
// columnOneConstraints will be applied to all the nodes placed in column one.
53+
ColumnConstraints columnOneConstraints = new ColumnConstraints(100, 100, Double.MAX_VALUE);
54+
columnOneConstraints.setHalignment(HPos.RIGHT);
55+
56+
// columnTwoConstraints will be applied to all the nodes placed in column two.
57+
ColumnConstraints columnTwoConstrains = new ColumnConstraints(200,200, Double.MAX_VALUE);
58+
columnTwoConstrains.setHgrow(Priority.ALWAYS);
59+
60+
gridPane.getColumnConstraints().addAll(columnOneConstraints, columnTwoConstrains);
61+
62+
return gridPane;
63+
}
64+
65+
private void addUIControls(GridPane gridPane) {
66+
// Add Header
67+
Label headerLabel = new Label("Registration Form");
68+
headerLabel.setFont(Font.font("Arial", FontWeight.BOLD, 24));
69+
gridPane.add(headerLabel, 0,0,2,1);
70+
GridPane.setHalignment(headerLabel, HPos.CENTER);
71+
GridPane.setMargin(headerLabel, new Insets(20, 0,20,0));
72+
73+
// Add Name Label
74+
Label nameLabel = new Label("Full Name : ");
75+
gridPane.add(nameLabel, 0,1);
76+
77+
// Add Name Text Field
78+
TextField nameField = new TextField();
79+
nameField.setPrefHeight(40);
80+
gridPane.add(nameField, 1,1);
81+
82+
83+
// Add Email Label
84+
Label emailLabel = new Label("Email ID : ");
85+
gridPane.add(emailLabel, 0, 2);
86+
87+
// Add Email Text Field
88+
TextField emailField = new TextField();
89+
emailField.setPrefHeight(40);
90+
gridPane.add(emailField, 1, 2);
91+
92+
// Add Password Label
93+
Label passwordLabel = new Label("Password : ");
94+
gridPane.add(passwordLabel, 0, 3);
95+
96+
// Add Password Field
97+
PasswordField passwordField = new PasswordField();
98+
passwordField.setPrefHeight(40);
99+
gridPane.add(passwordField, 1, 3);
100+
101+
// Add Submit Button
102+
Button submitButton = new Button("Submit");
103+
submitButton.setPrefHeight(40);
104+
submitButton.setDefaultButton(true);
105+
submitButton.setPrefWidth(100);
106+
gridPane.add(submitButton, 0, 4, 2, 1);
107+
GridPane.setHalignment(submitButton, HPos.CENTER);
108+
GridPane.setMargin(submitButton, new Insets(20, 0,20,0));
109+
110+
submitButton.setOnAction(new EventHandler<ActionEvent>() {
111+
@Override
112+
public void handle(ActionEvent event) {
113+
if(nameField.getText().isEmpty()) {
114+
showAlert(Alert.AlertType.ERROR, gridPane.getScene().getWindow(), "Form Error!", "Please enter your name");
115+
return;
116+
}
117+
if(emailField.getText().isEmpty()) {
118+
showAlert(Alert.AlertType.ERROR, gridPane.getScene().getWindow(), "Form Error!", "Please enter your email id");
119+
return;
120+
}
121+
if(passwordField.getText().isEmpty()) {
122+
showAlert(Alert.AlertType.ERROR, gridPane.getScene().getWindow(), "Form Error!", "Please enter a password");
123+
return;
124+
}
125+
126+
showAlert(Alert.AlertType.CONFIRMATION, gridPane.getScene().getWindow(), "Registration Successful!", "Welcome " + nameField.getText());
127+
}
128+
});
129+
}
130+
131+
private void showAlert(Alert.AlertType alertType, Window owner, String title, String message) {
132+
Alert alert = new Alert(alertType);
133+
alert.setTitle(title);
134+
alert.setHeaderText(null);
135+
alert.setContentText(message);
136+
alert.initOwner(owner);
137+
alert.show();
138+
}
139+
140+
public static void main(String[] args) {
141+
launch(args);
142+
}
143+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## JavaFX Registration Form example using FXML
2+
3+
The Project explains how to create a Registration form in JavaFX using FXML.
4+
Clone the Project, Import it into your favorite IDE and run `RegistrationFormApplication.java` for running the program.
5+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package javafx.example;
2+
3+
import javafx.scene.control.Alert;
4+
import javafx.stage.Window;
5+
6+
/**
7+
* Created by rajeevkumarsingh on 02/05/17.
8+
*/
9+
public class AlertHelper {
10+
11+
public static void showAlert(Alert.AlertType alertType, Window owner, String title, String message) {
12+
Alert alert = new Alert(alertType);
13+
alert.setTitle(title);
14+
alert.setHeaderText(null);
15+
alert.setContentText(message);
16+
alert.initOwner(owner);
17+
alert.show();
18+
}
19+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package javafx.example;
2+
3+
import javafx.application.Application;
4+
import javafx.fxml.FXMLLoader;
5+
import javafx.scene.Parent;
6+
import javafx.scene.Scene;
7+
import javafx.stage.Stage;
8+
9+
public class RegistrationFormApplication extends Application {
10+
11+
@Override
12+
public void start(Stage primaryStage) throws Exception{
13+
Parent root = FXMLLoader.load(getClass().getResource("registration_form.fxml"));
14+
primaryStage.setTitle("Registration Form Application");
15+
primaryStage.setScene(new Scene(root, 800, 500));
16+
primaryStage.show();
17+
}
18+
19+
20+
public static void main(String[] args) {
21+
launch(args);
22+
}
23+
}

0 commit comments

Comments
 (0)