-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add annotations and fix errors while setting the text counter output …
…in Groovy
- Loading branch information
1 parent
59223c8
commit 151397d
Showing
8 changed files
with
27 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 6 additions & 3 deletions
9
...rc/main/groovy/com/example/javafxtextcountergroovy/GroovyFXMLTextCounterController.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,25 @@ | ||
package com.example.javafxtextcountergroovy | ||
|
||
import javafx.event.ActionEvent | ||
import javafx.fxml.FXML | ||
import javafx.scene.control.Button | ||
import javafx.scene.control.Label | ||
import javafx.scene.control.TextArea | ||
|
||
class GroovyFXMLTextCounterController { | ||
|
||
@FXML | ||
public TextArea textContent// text box area | ||
@FXML | ||
public Button updateText// button to update entered text from text box | ||
@FXML | ||
public Label textCountResult// text counter output result | ||
|
||
@FXML | ||
void calculateTextCount(ActionEvent actionEvent) { // update text counter result when button is clicked | ||
int chars = textContent.length// get the length of text area in characters | ||
int words = textContent.text.trim().split('\\s+').length// get the length of text area in words | ||
int lines = textContent.text.split('\\r?\\n').length// get the length of text area in lines | ||
textCountResult.text = 'Characters: ' + String.format('%,d', chars) + '\nWords: ' + String.format('%,d', words) | ||
+ '\nLines: ' + String.format('%,d', lines)// update text counter output | ||
textCountResult.text = 'Characters: ' + String.format('%,d', chars) + '\nWords: ' + String.format('%,d', words) + '\nLines: ' + String.format('%,d', lines)// update text counter output | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters