import javafx.application.Application; import javafx.application.Platform; import javafx.stage.Stage; import javafx.stage.FileChooser; import javafx.scene.control.TextArea; import javafx.scene.layout.Pane; import javafx.scene.Scene; import javafx.event.EventHandler; import javafx.scene.input.KeyEvent; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import java.util.ArrayList; public class LeetCoder extends Application { ArrayList chunks = new ArrayList<>(); public void start(Stage stage) { lesFil(stage); TextArea area = new TextArea(); area.setEditable(false); area.setPrefSize(600, 400); area.setOnKeyPressed(new EventHandler() { int i = 0; public void handle(KeyEvent e) { if (i >= chunks.size()) i = 0; String nyTekst = area.getText() + " " + chunks.get(i); area.setText(nyTekst); area.setScrollTop(Double.MAX_VALUE); i++; } }); Pane root = new Pane(area); stage.setScene(new Scene(root)); stage.show(); } private void lesFil(Stage stage) { FileChooser fs = new FileChooser(); File fil = fs.showOpenDialog(stage); Scanner sc = null; try { sc = new Scanner(fil); } catch (FileNotFoundException fnfe) { Platform.exit(); } while (sc.hasNextLine()) { String[] biter = sc.nextLine().split(" "); for (String bit : biter) chunks.add(bit); chunks.add("\n"); } } }