Skip to content
Snippets Groups Projects
Commit e4188660 authored by Terence-ChanLY's avatar Terence-ChanLY
Browse files

Added Open File function

parent f1ab15ef
No related branches found
No related tags found
No related merge requests found
Pipeline #84070 passed
package net.codebot.application package net.codebot.application
import javafx.application.Application import javafx.application.Application
import javafx.event.EventHandler
import javafx.scene.Scene import javafx.scene.Scene
import javafx.scene.control.* import javafx.scene.control.*
import javafx.scene.layout.BorderPane import javafx.scene.layout.BorderPane
...@@ -8,7 +9,11 @@ import javafx.scene.layout.HBox ...@@ -8,7 +9,11 @@ import javafx.scene.layout.HBox
import javafx.scene.layout.VBox import javafx.scene.layout.VBox
import javafx.scene.text.Font import javafx.scene.text.Font
import javafx.scene.text.Text import javafx.scene.text.Text
import javafx.stage.FileChooser
import javafx.stage.Stage import javafx.stage.Stage
import java.io.File
import java.io.FileNotFoundException
import java.util.*
class Main : Application() { class Main : Application() {
override fun start(stage: Stage) { override fun start(stage: Stage) {
...@@ -131,6 +136,26 @@ class Main : Application() { ...@@ -131,6 +136,26 @@ class Main : Application() {
topContainer.getChildren().add(mainMenu); topContainer.getChildren().add(mainMenu);
topContainer.getChildren().add(toolbar); topContainer.getChildren().add(toolbar);
//OpenFile function
openFile.onAction = EventHandler {
val filechooser = FileChooser();
val file = File("C:\\Users");
filechooser.setTitle("Open my file");
filechooser.setInitialDirectory(file);
val selectedFile = filechooser.showOpenDialog(stage);
try {
val scanner = Scanner(selectedFile);
text.clear()
while (scanner.hasNextLine()) {
text.appendText(scanner.nextLine() + "\n");
}
} catch (e: FileNotFoundException) {
e.printStackTrace();
}
}
border.top = topContainer border.top = topContainer
border.center = center border.center = center
border.bottom = status border.bottom = status
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment