I am writing program that moves digits from TextField to TextArea for sorting or shuffling or reversing them. All entered digits have to be save in ArrayList.
At first I create javafx stage with buttons labels and etc. Then I added listeners for buttons and for moving text from TextField to TextArea. I run succefully my program couple times before I assign to store digits in ArrayList. Then I got exception message
Exception in Application constructor
Exception in thread "main" java.lang.NoSuchMethodException: StoreNumbers.main([Ljava.lang.String;)
at java.lang.Class.getMethod(Class.java:1778)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:119)
I have search on web and on stackoverflow but didn't find something that help me to understand what I am doing wrong. Below my code. Thank you for help in advance for any advices.
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import java.util.*;
public class StoreNumbers extends Application {
private TextField textField = new TextField();
private TextArea textArea = new TextArea();
StoreNumberPane snPane = new StoreNumberPane();
List<String> arrayList = new ArrayList<>();
public void start(Stage primaryStage) {
Button btSort = new Button("Sort");
Button btShuffle = new Button("Shuffle");
Button btReverse = new Button("Reverse");
HBox hBox = new HBox(10);
hBox.getChildren().addAll(btSort, btShuffle, btReverse);
hBox.setAlignment(Pos.CENTER);
btSort.setOnAction(e -> snPane.sort());
btShuffle.setOnAction(e -> snPane.shuffle());
btReverse.setOnAction(e -> snPane.reverse());
Label label = new Label("Enter a number: ");
textField.setPromptText("Enter integer");
FlowPane flowPane = new FlowPane();
flowPane.getChildren().addAll(label, textField);
ScrollPane scrollPane = new ScrollPane(textArea);
BorderPane pane = new BorderPane();
pane.setCenter(textArea);
pane.setBottom(hBox);
pane.setTop(flowPane);
pane.setOnKeyPressed(e -> {
if (e.getCode() == KeyCode.ENTER) {
obtainData();
textField.clear();
}
});
Scene scene = new Scene(pane, 400, 400);
primaryStage.setTitle("Exercise20_20");
primaryStage.setScene(scene);
primaryStage.show();
snPane.requestFocus();
}
public void displayArray(){
}
private void obtainData(){
String userInput = textField.getText();
if(userInput != null)
arrayList.add(userInput);
textArea.setText(String.format("%s", arrayList));
}
}
class StoreNumberPane extends Pane{
StoreNumbers storeNumbers = new StoreNumbers();
public void sort(){
Collections.sort(storeNumbers.arrayList);
}
public void shuffle(){
Collections.shuffle(storeNumbers.arrayList);
}
public void reverse(){
Collections.reverse(storeNumbers.arrayList);
}
}