I did fix your shit.
This commit is contained in:
GEI22857 2022-05-19 15:23:15 +02:00 committed by GitHub
parent bfe88db9c4
commit fd37c39e11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 30 deletions

View File

@ -1,9 +1,6 @@
package application; package application;
import java.io.File;
import javafx.application.Application; import javafx.application.Application;
import javafx.stage.FileChooser;
import javafx.stage.Stage; import javafx.stage.Stage;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.Alert; import javafx.scene.control.Alert;
@ -17,17 +14,10 @@ public class Main extends Application {
try { try {
RootBorderPane root = new RootBorderPane(); RootBorderPane root = new RootBorderPane();
Scene scene = new Scene(root,400,400); Scene scene = new Scene(root,400,400);
primaryStage.setAlwaysOnTop(true); // primaryStage.setAlwaysOnTop(true);
primaryStage.setTitle("Rechner"); primaryStage.setTitle("Rechner");
primaryStage.setScene(scene); primaryStage.setScene(scene);
primaryStage.show(); primaryStage.show();
FileChooser fileChooser = new FileChooser();
Button btImport = new Button("Select File");
btImport.setOnAction(e -> {
File selectedFile = fileChooser.showOpenDialog(primaryStage);
});
} catch(Exception e) { } catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -4,13 +4,11 @@ import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.util.Scanner; import java.util.Scanner;
import javafx.scene.Scene;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane; import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane; import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.stage.FileChooser; import javafx.stage.FileChooser;
public class RootBorderPane extends BorderPane { public class RootBorderPane extends BorderPane {
@ -28,7 +26,7 @@ public class RootBorderPane extends BorderPane {
private void initComponents() { private void initComponents() {
title = new Label("Do stuff"); title = new Label("Do stuff");
tfInput = new TextField(); tfInput = new TextField();
btInput = new Button("Abesnden"); btInput = new Button("Absenden");
btImport = new Button("Importieren"); btImport = new Button("Importieren");
gpInput = new GridPane(); gpInput = new GridPane();
@ -49,35 +47,29 @@ public class RootBorderPane extends BorderPane {
} }
public void importCSV() { public void importCSV() {
String extension = ""; String fileName = "";
String filePath = "";
FileChooser fileChooser = new FileChooser(); FileChooser fileChooser = new FileChooser();
File selectedFile = fileChooser.showOpenDialog(null); File selectedFile = fileChooser.showOpenDialog(null);
File readfile = selectedFile;
File Readfile = selectedFile; if (readfile.exists()) {
if (Readfile.exists()) { fileName = readfile.getName();
String FileName = Readfile.getName(); filePath = readfile.getAbsolutePath();
String FilePath = Readfile.getAbsolutePath();
int index = FileName.lastIndexOf('.');
if (index > 0) {
extension = FileName.substring(index + 1);
}
System.out.println(extension);
} else { } else {
System.out.println("The file does not exist."); System.out.println("The file does not exist.");
} }
if(extension == "txt") { if(fileName.endsWith(".csv")) {
try { try {
File file = selectedFile; File file = selectedFile;
Scanner myReader = new Scanner(file); Scanner myReader = new Scanner(file);
String data = "";
while (myReader.hasNextLine()) { while (myReader.hasNextLine()) {
String data = myReader.nextLine(); data += myReader.nextLine();
System.out.println(data);
} }
System.out.println(data);
myReader.close(); myReader.close();
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
System.out.println("An error occurred."); System.out.println("An error occurred.");