Skip to content

Commit 70fadbc

Browse files
committed
Format Java code
1 parent 6abfd0c commit 70fadbc

File tree

11 files changed

+269
-228
lines changed

11 files changed

+269
-228
lines changed
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module com.example.javafxtextcountergroovy {
2-
requires javafx.controls;
3-
requires javafx.fxml;
4-
requires org.apache.groovy;
2+
requires javafx.controls;
3+
requires javafx.fxml;
4+
requires org.apache.groovy;
55

6+
opens com.example.javafxtextcountergroovy to javafx.fxml;
67

7-
opens com.example.javafxtextcountergroovy to javafx.fxml;
8-
exports com.example.javafxtextcountergroovy;
9-
}
8+
exports com.example.javafxtextcountergroovy;
9+
}
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
package com.example.javafxtextcounter;
22

3+
import java.io.IOException;
34
import javafx.application.Application;
45
import javafx.fxml.FXMLLoader;
56
import javafx.scene.Scene;
67
import javafx.stage.Stage;
78

8-
import java.io.IOException;
9-
109
public class FXMLFileTextCounterApplication extends Application {
11-
@Override
12-
public void start(Stage stage) throws IOException {
13-
FXMLLoader fxmlLoader = new FXMLLoader(
14-
FXMLFileTextCounterApplication.class.getResource("fxml-file-text-counter.fxml"));// load FXML file
15-
// resource
16-
Scene scene = new Scene(fxmlLoader.load(), 480, 400);// set application size to 480x400
17-
stage.setTitle("Text Counter from a File");// set the title of stage
18-
stage.setScene(scene);// set the stage to a scene
19-
stage.show();// show the stage
20-
}
2110

22-
public static void main(String[] args) {
23-
launch();// launch the application by running the program
24-
}
11+
@Override
12+
public void start(Stage stage) throws IOException {
13+
FXMLLoader fxmlLoader = new FXMLLoader(
14+
FXMLFileTextCounterApplication.class.getResource(
15+
"fxml-file-text-counter.fxml")); // load FXML file resource
16+
Scene scene = new Scene(fxmlLoader.load(), 480, 400); // set application size to 480x400
17+
stage.setTitle("Text Counter from a File"); // set the title of stage
18+
stage.setScene(scene); // set the stage to a scene
19+
stage.show(); // show the stage
20+
}
21+
22+
public static void main(String[] args) {
23+
launch(); // launch the application by running the program
24+
}
2525
}

java/javafx-textcounter/src/main/java/com/example/javafxtextcounter/FXMLFileTextCounterController.java

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,40 @@
77
import javafx.stage.FileChooser;
88

99
public class FXMLFileTextCounterController {
10-
public Button selectFile;// button to select file
11-
public Label textCountResult;// text counter output result
12-
static BufferedReader reader = null;// initialize reader
13-
String textContent = "";// initialize empty text content string
1410

15-
public void calculateTextCount(ActionEvent actionEvent) {
16-
String textContent = "";// initialize empty text content string
17-
FileChooser fileChooser = new FileChooser();// create a new file chooser
18-
fileChooser.setTitle("Select a file");
19-
fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("Text Files", "*.txt"));// choose .txt
20-
// text files
21-
File fileSelected = fileChooser.showOpenDialog(null);// show file dialog
22-
if (fileSelected != null) {
23-
try (BufferedReader reader = new BufferedReader(new FileReader(fileSelected))) {
24-
String line;
25-
while ((line = reader.readLine()) != null) {
26-
textContent += line + "\n";// read text from file every line
27-
}
28-
} catch (IOException e) {
29-
throw new RuntimeException(e);// throw runtime exception
30-
}
11+
public Button selectFile; // button to select file
12+
public Label textCountResult; // text counter output result
13+
static BufferedReader reader = null; // initialize reader
14+
String textContent = ""; // initialize empty text content string
15+
16+
public void calculateTextCount(ActionEvent actionEvent) {
17+
String textContent = ""; // initialize empty text content string
18+
FileChooser fileChooser = new FileChooser(); // create a new file chooser
19+
fileChooser.setTitle("Select a file");
20+
fileChooser
21+
.getExtensionFilters()
22+
.addAll(new FileChooser.ExtensionFilter("Text Files", "*.txt")); // choose .txt text files
23+
File fileSelected = fileChooser.showOpenDialog(null); // show file dialog
24+
if (fileSelected != null) {
25+
try (
26+
BufferedReader reader = new BufferedReader(new FileReader(fileSelected))) {
27+
String line;
28+
while ((line = reader.readLine()) != null) {
29+
textContent += line + "\n"; // read text from file every line
3130
}
32-
int chars = textContent.length();// get the length of opened text file in characters
33-
int words = textContent.trim().split("\\s+").length;// get the length of opened text file in words
34-
int lines = textContent.trim().split("\\r?\\n").length;// get the length of opened text file in lines
35-
textCountResult.setText("Characters: " + String.format("%,d", chars) + "\nWords: " + String.format("%,d", words)
36-
+ "\nLines: " + String.format("%,d", lines));// update text counter output
31+
} catch (IOException e) {
32+
throw new RuntimeException(e); // throw runtime exception
33+
}
3734
}
35+
int chars = textContent.length(); // get the length of opened text file in characters
36+
int words = textContent.trim().split("\\s+").length; // get the length of opened text file in words
37+
int lines = textContent.trim().split("\\r?\\n").length; // get the length of opened text file in lines
38+
textCountResult.setText(
39+
"Characters: " +
40+
String.format("%,d", chars) +
41+
"\nWords: " +
42+
String.format("%,d", words) +
43+
"\nLines: " +
44+
String.format("%,d", lines)); // update text counter output
45+
}
3846
}
Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
package com.example.javafxtextcounter;
22

3+
import java.io.IOException;
34
import javafx.application.Application;
45
import javafx.fxml.FXMLLoader;
56
import javafx.scene.Scene;
67
import javafx.stage.Stage;
78

8-
import java.io.IOException;
9-
109
public class FXMLTextCounterApplication extends Application {
11-
@Override
12-
public void start(Stage stage) throws IOException {
13-
FXMLLoader fxmlLoader = new FXMLLoader(FXMLTextCounterApplication.class.getResource("fxml-text-counter.fxml"));// load
14-
// FXML
15-
// file
16-
// resource
17-
Scene scene = new Scene(fxmlLoader.load(), 480, 400);// set application size to 480x400
18-
stage.setTitle("Text Counter");// set the title of stage
19-
stage.setScene(scene);// set the stage to a scene
20-
stage.show();// show the stage
21-
}
2210

23-
public static void main(String[] args) {
24-
launch();// launch the application by running the program
25-
}
26-
}
11+
@Override
12+
public void start(Stage stage) throws IOException {
13+
FXMLLoader fxmlLoader = new FXMLLoader(
14+
FXMLTextCounterApplication.class.getResource("fxml-text-counter.fxml")); // load FXML file resource
15+
Scene scene = new Scene(fxmlLoader.load(), 480, 400); // set application size to 480x400
16+
stage.setTitle("Text Counter"); // set the title of stage
17+
stage.setScene(scene); // set the stage to a scene
18+
stage.show(); // show the stage
19+
}
20+
21+
public static void main(String[] args) {
22+
launch(); // launch the application by running the program
23+
}
24+
}

java/javafx-textcounter/src/main/java/com/example/javafxtextcounter/FXMLTextCounterController.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,21 @@
66
import javafx.scene.control.TextArea;
77

88
public class FXMLTextCounterController {
9-
public TextArea textContent;// text box area
10-
public Button updateText;// button to update entered text from text box
11-
public Label textCountResult;// text counter output result
129

13-
public void calculateTextCount(ActionEvent actionEvent) {// update a text count result when button is clicked
14-
int chars = textContent.getLength();// get the length of text area in characters
15-
int words = textContent.getText().trim().split("\\s+").length;// get the length of text area in words
16-
int lines = textContent.getText().split("\\r?\\n").length;// get the length of text area in lines
17-
textCountResult.setText("Characters: " + String.format("%,d", chars) + "\nWords: " + String.format("%,d", words)
18-
+ "\nLines: " + String.format("%,d", lines));// update text counter output
19-
}
20-
}
10+
public TextArea textContent; // text box area
11+
public Button updateText; // button to update entered text from text box
12+
public Label textCountResult; // text counter output result
13+
14+
public void calculateTextCount(ActionEvent actionEvent) { // update a text count result when button is clicked
15+
int chars = textContent.getLength(); // get the length of text area in characters
16+
int words = textContent.getText().trim().split("\\s+").length; // get the length of text area in words
17+
int lines = textContent.getText().split("\\r?\\n").length; // get the length of text area in lines
18+
textCountResult.setText(
19+
"Characters: " +
20+
String.format("%,d", chars) +
21+
"\nWords: " +
22+
String.format("%,d", words) +
23+
"\nLines: " +
24+
String.format("%,d", lines)); // update text counter output
25+
}
26+
}

java/javafx-textcounter/src/main/java/com/example/javafxtextcounter/FileTextCounterJavaFX.java

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,50 @@
1111

1212
public class FileTextCounterJavaFX extends Application {
1313

14-
public static void main(String[] args) {
15-
launch(args);// launch the application by running the program
16-
}
14+
public static void main(String[] args) {
15+
launch(args); // launch the application by running the program
16+
}
1717

18-
public void start(Stage primaryStage) throws FileNotFoundException {
19-
FlowPane root = new FlowPane();
20-
Scene scene = new Scene(root, 480, 400);// set the application size to 480x400
21-
Button selectFile = new Button("Select file");// select the file from the dialog box
22-
primaryStage.setScene(scene);// set the scene
23-
primaryStage.setTitle("Text Counter Application");// set the title of stage
24-
Label textCountResult = new Label("Characters: 0\nWords: 0\nLines: 0");// set the default text counter output
25-
selectFile.setOnAction((event) -> {
26-
String textContent = "";// initialize empty text content string
27-
FileChooser fileChooser = new FileChooser();// create a new file chooser
28-
fileChooser.setTitle("Select a file");
29-
fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("Text Files", "*.txt"));// choose
30-
// .txt
31-
// text
32-
// files
33-
File fileSelected = fileChooser.showOpenDialog(null);// show file dialog
34-
if (fileSelected != null) {
35-
try (BufferedReader reader = new BufferedReader(new FileReader(fileSelected))) {
36-
String line;
37-
while ((line = reader.readLine()) != null) {
38-
textContent += line + "\n";// read text from a file every line
39-
}
40-
} catch (IOException e) {
41-
throw new RuntimeException(e);// throw runtime exception
42-
}
43-
}
44-
int chars = textContent.length();// get the length of opened text file in characters
45-
int words = textContent.trim().split("\\s+").length;// get the length of opened text file in words
46-
int lines = textContent.trim().split("\\r?\\n").length;// get the length of opened text file in lines
47-
textCountResult.setText("Characters: " + String.format("%,d", chars) + "\nWords: "
48-
+ String.format("%,d", words) + "\nLines: " + String.format("%,d", lines));// update text counter
49-
// output
50-
});
51-
root.getChildren().addAll(selectFile, textCountResult);// add all components to the stage
52-
primaryStage.show();// show the stage
53-
}
18+
public void start(Stage primaryStage) throws FileNotFoundException {
19+
FlowPane root = new FlowPane();
20+
Scene scene = new Scene(root, 480, 400); // set the application size to 480x400
21+
Button selectFile = new Button("Select file"); // select the file from the dialog box
22+
primaryStage.setScene(scene); // set the scene
23+
primaryStage.setTitle("Text Counter Application"); // set the title of stage
24+
Label textCountResult = new Label("Characters: 0\nWords: 0\nLines: 0"); // set the default text counter output
25+
selectFile.setOnAction(event -> {
26+
String textContent = ""; // initialize empty text content string
27+
FileChooser fileChooser = new FileChooser(); // create a new file chooser
28+
fileChooser.setTitle("Select a file");
29+
fileChooser
30+
.getExtensionFilters()
31+
.addAll(new FileChooser.ExtensionFilter("Text Files", "*.txt")); // choose .txt
32+
// text files
33+
File fileSelected = fileChooser.showOpenDialog(null); // show file dialog
34+
if (fileSelected != null) {
35+
try (
36+
BufferedReader reader = new BufferedReader(
37+
new FileReader(fileSelected))) {
38+
String line;
39+
while ((line = reader.readLine()) != null) {
40+
textContent += line + "\n"; // read text from a file every line
41+
}
42+
} catch (IOException e) {
43+
throw new RuntimeException(e); // throw runtime exception
44+
}
45+
}
46+
int chars = textContent.length(); // get the length of opened text file in characters
47+
int words = textContent.trim().split("\\s+").length; // get the length of opened text file in words
48+
int lines = textContent.trim().split("\\r?\\n").length; // get the length of opened text file in lines
49+
textCountResult.setText(
50+
"Characters: " +
51+
String.format("%,d", chars) +
52+
"\nWords: " +
53+
String.format("%,d", words) +
54+
"\nLines: " +
55+
String.format("%,d", lines)); // update text counter output
56+
});
57+
root.getChildren().addAll(selectFile, textCountResult); // add all components to the stage
58+
primaryStage.show(); // show the stage
59+
}
5460
}

java/javafx-textcounter/src/main/java/com/example/javafxtextcounter/TextCounterJavaFX.java

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,31 @@
1010

1111
public class TextCounterJavaFX extends Application {
1212

13-
public static void main(String[] args) {
14-
launch(args);// launch the application by running the program
15-
}
13+
public static void main(String[] args) {
14+
launch(args); // launch the application by running the program
15+
}
1616

17-
public void start(Stage primaryStage) {
18-
FlowPane root = new FlowPane();
19-
Scene scene = new Scene(root, 480, 400);// set the application size to 480x400
20-
primaryStage.setScene(scene);// set the scene
21-
primaryStage.setTitle("Text Counter Application");// set title of stage
22-
TextArea textContent = new TextArea();// text box area
23-
Button updateText = new Button("Calculate text count");
24-
Label textCountResult = new Label("Characters: 0\nWords: 0\nLines: 0");// set to default text counter output
25-
updateText.setOnAction((event) -> {// calculate text count when button is clicked
26-
int chars = textContent.getLength();// get the length of text area in characters
27-
int words = textContent.getText().trim().split("\\s+").length;// get the length of text area in words
28-
int lines = textContent.getText().split("\\r?\\n").length;// get the length of text area in lines
29-
textCountResult.setText("Characters: " + String.format("%,d", chars) + "\nWords: "
30-
+ String.format("%,d", words) + "\nLines: " + String.format("%,d", lines));// update text counter
31-
// output
32-
});
33-
root.getChildren().addAll(textContent, updateText, textCountResult);// add all components to the stage
34-
primaryStage.show();// show the stage
35-
}
17+
public void start(Stage primaryStage) {
18+
FlowPane root = new FlowPane();
19+
Scene scene = new Scene(root, 480, 400); // set the application size to 480x400
20+
primaryStage.setScene(scene); // set the scene
21+
primaryStage.setTitle("Text Counter Application"); // set title of stage
22+
TextArea textContent = new TextArea(); // text box area
23+
Button updateText = new Button("Calculate text count");
24+
Label textCountResult = new Label("Characters: 0\nWords: 0\nLines: 0"); // set to default text counter output
25+
updateText.setOnAction(event -> { // calculate text count when button is clicked
26+
int chars = textContent.getLength(); // get the length of text area in characters
27+
int words = textContent.getText().trim().split("\\s+").length; // get the length of text area in words
28+
int lines = textContent.getText().split("\\r?\\n").length; // get the length of text area in lines
29+
textCountResult.setText(
30+
"Characters: " +
31+
String.format("%,d", chars) +
32+
"\nWords: " +
33+
String.format("%,d", words) +
34+
"\nLines: " +
35+
String.format("%,d", lines)); // update text counter output
36+
});
37+
root.getChildren().addAll(textContent, updateText, textCountResult); // add all components to the stage
38+
primaryStage.show(); // show the stage
39+
}
3640
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module com.example.javafxtextcounter {
2-
requires javafx.controls;
3-
requires javafx.fxml;
2+
requires javafx.controls;
3+
requires javafx.fxml;
44

5+
opens com.example.javafxtextcounter to javafx.fxml;
56

6-
opens com.example.javafxtextcounter to javafx.fxml;
7-
exports com.example.javafxtextcounter;
8-
}
7+
exports com.example.javafxtextcounter;
8+
}

0 commit comments

Comments
 (0)