fork download
  1. import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;
  3.  
  4. import javafx.application.Application;
  5. import javafx.application.Platform;
  6. import javafx.stage.Stage;
  7. import javafx.scene.Scene;
  8. import javafx.scene.layout.BorderPane;
  9. import javafx.scene.layout.GridPane;
  10. import javafx.scene.layout.HBox;
  11. import javafx.scene.control.TextArea;
  12. import javafx.scene.control.TextField;
  13. import javafx.scene.control.Button;
  14. import javafx.scene.control.Label;
  15. import javafx.scene.text.Font;
  16. import javafx.scene.text.FontWeight;
  17. import javafx.geometry.Insets;
  18. import javafx.geometry.Pos;
  19.  
  20.  
  21. public class RegexTest extends Application {
  22.  
  23. /* Define TextArea and TextField as instance variables
  24.   * so they can be used throughout the program. Not needed
  25.   * in this program, but fairly typical in more complex
  26.   * programs.
  27.   */
  28.  
  29. private TextField regexInput;
  30. private TextField titleInput;
  31. private TextArea contentInput;
  32. private TextArea output;
  33.  
  34. /**
  35.   * Start method builds the GUI and shows the window.
  36.   */
  37. public void start(Stage stage) {
  38. // Initial text for TextField.
  39. String regex = "Regex Input Here";
  40.  
  41. // Initial text for TextField.
  42. String title = "Enter Search Text Here";
  43.  
  44. // Initial text for TextArea
  45. String content = "Results Will Appear Here";
  46.  
  47. /* Create and configure the TextField and TextArea */
  48.  
  49. regexInput = new TextField(regex);
  50. regexInput.setFont( Font.font(null, FontWeight.BOLD, 20) );
  51. regexInput.setPrefColumnCount(20);
  52.  
  53.  
  54.  
  55. titleInput = new TextField(title);
  56. titleInput.setFont( Font.font(null, FontWeight.BOLD, 20) );
  57. titleInput.setPrefColumnCount(20);
  58.  
  59. contentInput = new TextArea();
  60. contentInput.setText(content);
  61. contentInput.setFont( Font.font(16) );
  62. contentInput.setPrefRowCount(6);
  63. contentInput.setPrefColumnCount(30);
  64.  
  65. /* A button that will clear the TextArea. It also selects all of the
  66.   * text in the TextField and gives the focus to the TextField. If the
  67.   * user just starts typing at that point, the old text will be deleted
  68.   * and replaced with what the user types.
  69.   */
  70.  
  71. Button quitButton = new Button("Quit");
  72. quitButton.setOnAction( e -> {
  73. Platform.exit();
  74. });
  75.  
  76. Button runButton = new Button("Run Regex");
  77. runButton.setOnAction( e -> {
  78. findAndReplace();
  79. });
  80.  
  81.  
  82.  
  83. HBox buttonBar = new HBox( 20, runButton, quitButton);
  84. buttonBar.setAlignment(Pos.CENTER);
  85.  
  86.  
  87. GridPane root = new GridPane();
  88.  
  89.  
  90. //Adding all elements along with labels
  91.  
  92.  
  93.  
  94. root.add(regexInput, 1, 0);
  95.  
  96.  
  97.  
  98. root.add(titleInput, 1, 1);
  99.  
  100.  
  101.  
  102. root.add(contentInput, 1, 2);
  103.  
  104.  
  105. root.setStyle("-fx-background-color: #444444");
  106.  
  107. root.add(buttonBar, 1, 3);
  108. BorderPane.setMargin(regexInput, new Insets(2,2,0,2));
  109. BorderPane.setMargin(contentInput, new Insets(2)); // Set margins around components
  110. BorderPane.setMargin(titleInput, new Insets(2,2,0,2));
  111.  
  112. /* Add the scene to the window and make it visible. */
  113.  
  114. Scene scene = new Scene(root);
  115. stage.setScene(scene);
  116. stage.setTitle("Regex Test Harness");
  117. stage.show();
  118.  
  119. } // end start()
  120.  
  121.  
  122.  
  123.  
  124. public void findAndReplace() {
  125.  
  126. //getting all text input
  127.  
  128.  
  129.  
  130. //creating a pattern, case sensitive
  131.  
  132.  
  133.  
  134. //creating a matcher
  135.  
  136.  
  137. String regex = titleInput.getText();
  138. String inputtext = contentInput.getText();
  139.  
  140. Pattern pattern = Pattern.compile(regex);
  141. Matcher matcher = pattern.matcher(inputtext);
  142.  
  143. String done = matcher.group();
  144.  
  145.  
  146. output.setText(done);
  147.  
  148.  
  149. }
  150.  
  151.  
  152.  
  153.  
  154.  
  155. public static void main(String[] args) {
  156. launch(args);
  157. }
  158.  
  159. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:21: error: class RegexTest is public, should be declared in a file named RegexTest.java
public class RegexTest extends Application {
       ^
Main.java:4: error: package javafx.application does not exist
import javafx.application.Application;
                         ^
Main.java:5: error: package javafx.application does not exist
import javafx.application.Platform;
                         ^
Main.java:6: error: package javafx.stage does not exist
import javafx.stage.Stage;
                   ^
Main.java:7: error: package javafx.scene does not exist
import javafx.scene.Scene;
                   ^
Main.java:8: error: package javafx.scene.layout does not exist
import javafx.scene.layout.BorderPane;
                          ^
Main.java:9: error: package javafx.scene.layout does not exist
import javafx.scene.layout.GridPane;
                          ^
Main.java:10: error: package javafx.scene.layout does not exist
import javafx.scene.layout.HBox;
                          ^
Main.java:11: error: package javafx.scene.control does not exist
import javafx.scene.control.TextArea;
                           ^
Main.java:12: error: package javafx.scene.control does not exist
import javafx.scene.control.TextField;
                           ^
Main.java:13: error: package javafx.scene.control does not exist
import javafx.scene.control.Button;
                           ^
Main.java:14: error: package javafx.scene.control does not exist
import javafx.scene.control.Label;
                           ^
Main.java:15: error: package javafx.scene.text does not exist
import javafx.scene.text.Font;
                        ^
Main.java:16: error: package javafx.scene.text does not exist
import javafx.scene.text.FontWeight;
                        ^
Main.java:17: error: package javafx.geometry does not exist
import javafx.geometry.Insets;
                      ^
Main.java:18: error: package javafx.geometry does not exist
import javafx.geometry.Pos;
                      ^
Main.java:21: error: cannot find symbol
public class RegexTest extends Application {
                               ^
  symbol: class Application
Main.java:29: error: cannot find symbol
	private TextField regexInput;
	        ^
  symbol:   class TextField
  location: class RegexTest
Main.java:30: error: cannot find symbol
	private TextField titleInput;
	        ^
  symbol:   class TextField
  location: class RegexTest
Main.java:31: error: cannot find symbol
    private TextArea contentInput;
            ^
  symbol:   class TextArea
  location: class RegexTest
Main.java:32: error: cannot find symbol
    private TextArea output;
            ^
  symbol:   class TextArea
  location: class RegexTest
Main.java:37: error: cannot find symbol
    public void start(Stage stage) {
                      ^
  symbol:   class Stage
  location: class RegexTest
Main.java:49: error: cannot find symbol
        regexInput = new TextField(regex);
                         ^
  symbol:   class TextField
  location: class RegexTest
Main.java:50: error: cannot find symbol
        regexInput.setFont( Font.font(null, FontWeight.BOLD, 20) );
                                            ^
  symbol:   variable FontWeight
  location: class RegexTest
Main.java:50: error: cannot find symbol
        regexInput.setFont( Font.font(null, FontWeight.BOLD, 20) );
                            ^
  symbol:   variable Font
  location: class RegexTest
Main.java:55: error: cannot find symbol
        titleInput = new TextField(title);
                         ^
  symbol:   class TextField
  location: class RegexTest
Main.java:56: error: cannot find symbol
        titleInput.setFont( Font.font(null, FontWeight.BOLD, 20) );
                                            ^
  symbol:   variable FontWeight
  location: class RegexTest
Main.java:56: error: cannot find symbol
        titleInput.setFont( Font.font(null, FontWeight.BOLD, 20) );
                            ^
  symbol:   variable Font
  location: class RegexTest
Main.java:59: error: cannot find symbol
        contentInput = new TextArea();
                           ^
  symbol:   class TextArea
  location: class RegexTest
Main.java:61: error: cannot find symbol
        contentInput.setFont( Font.font(16) );
                              ^
  symbol:   variable Font
  location: class RegexTest
Main.java:71: error: cannot find symbol
        Button quitButton = new Button("Quit");
        ^
  symbol:   class Button
  location: class RegexTest
Main.java:71: error: cannot find symbol
        Button quitButton = new Button("Quit");
                                ^
  symbol:   class Button
  location: class RegexTest
Main.java:73: error: cannot find symbol
            Platform.exit();
            ^
  symbol:   variable Platform
  location: class RegexTest
Main.java:76: error: cannot find symbol
        Button runButton = new Button("Run Regex");
        ^
  symbol:   class Button
  location: class RegexTest
Main.java:76: error: cannot find symbol
        Button runButton = new Button("Run Regex");
                               ^
  symbol:   class Button
  location: class RegexTest
Main.java:83: error: cannot find symbol
        HBox buttonBar = new HBox( 20, runButton, quitButton);
        ^
  symbol:   class HBox
  location: class RegexTest
Main.java:83: error: cannot find symbol
        HBox buttonBar = new HBox( 20, runButton, quitButton);
                             ^
  symbol:   class HBox
  location: class RegexTest
Main.java:84: error: cannot find symbol
        buttonBar.setAlignment(Pos.CENTER);
                               ^
  symbol:   variable Pos
  location: class RegexTest
Main.java:87: error: cannot find symbol
        GridPane root = new GridPane();
        ^
  symbol:   class GridPane
  location: class RegexTest
Main.java:87: error: cannot find symbol
        GridPane root = new GridPane();
                            ^
  symbol:   class GridPane
  location: class RegexTest
Main.java:108: error: cannot find symbol
        BorderPane.setMargin(regexInput, new Insets(2,2,0,2));
                                             ^
  symbol:   class Insets
  location: class RegexTest
Main.java:108: error: cannot find symbol
        BorderPane.setMargin(regexInput, new Insets(2,2,0,2));
        ^
  symbol:   variable BorderPane
  location: class RegexTest
Main.java:109: error: cannot find symbol
        BorderPane.setMargin(contentInput, new Insets(2));  // Set margins around components
                                               ^
  symbol:   class Insets
  location: class RegexTest
Main.java:109: error: cannot find symbol
        BorderPane.setMargin(contentInput, new Insets(2));  // Set margins around components
        ^
  symbol:   variable BorderPane
  location: class RegexTest
Main.java:110: error: cannot find symbol
        BorderPane.setMargin(titleInput, new Insets(2,2,0,2));
                                             ^
  symbol:   class Insets
  location: class RegexTest
Main.java:110: error: cannot find symbol
        BorderPane.setMargin(titleInput, new Insets(2,2,0,2));
        ^
  symbol:   variable BorderPane
  location: class RegexTest
Main.java:114: error: cannot find symbol
        Scene scene = new Scene(root);
        ^
  symbol:   class Scene
  location: class RegexTest
Main.java:114: error: cannot find symbol
        Scene scene = new Scene(root);
                          ^
  symbol:   class Scene
  location: class RegexTest
Main.java:156: error: cannot find symbol
        launch(args);
        ^
  symbol:   method launch(String[])
  location: class RegexTest
49 errors
stdout
Standard output is empty