Bloat entfernt

This commit is contained in:
GEI22857 2022-05-19 16:01:22 +02:00 committed by GitHub
parent fd37c39e11
commit 934c1a113a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,7 +12,7 @@ import javafx.scene.layout.GridPane;
import javafx.stage.FileChooser; import javafx.stage.FileChooser;
public class RootBorderPane extends BorderPane { public class RootBorderPane extends BorderPane {
private Label title; private Label title, data;
private TextField tfInput; private TextField tfInput;
private Button btInput, btImport; private Button btInput, btImport;
private GridPane gpInput; private GridPane gpInput;
@ -29,6 +29,7 @@ public class RootBorderPane extends BorderPane {
btInput = new Button("Absenden"); btInput = new Button("Absenden");
btImport = new Button("Importieren"); btImport = new Button("Importieren");
gpInput = new GridPane(); gpInput = new GridPane();
data = new Label();
tfInput.setPromptText("test"); tfInput.setPromptText("test");
} }
@ -37,6 +38,7 @@ public class RootBorderPane extends BorderPane {
gpInput.add(btInput, 0, 0); gpInput.add(btInput, 0, 0);
gpInput.add(tfInput, 1, 0); gpInput.add(tfInput, 1, 0);
gpInput.add(btImport, 2, 0); gpInput.add(btImport, 2, 0);
gpInput.add(data, 1, 1);
setTop(title); setTop(title);
setCenter(gpInput); setCenter(gpInput);
@ -46,38 +48,25 @@ public class RootBorderPane extends BorderPane {
btImport.setOnAction(event -> importCSV()); btImport.setOnAction(event -> importCSV());
} }
public void importCSV() { private void importCSV() {
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; if(selectedFile.getName().endsWith(".csv")) {
if (readfile.exists()) {
fileName = readfile.getName();
filePath = readfile.getAbsolutePath();
} else {
System.out.println("The file does not exist.");
}
if(fileName.endsWith(".csv")) {
try { try {
File file = selectedFile; Scanner myReader = new Scanner(selectedFile);
Scanner myReader = new Scanner(file);
String data = ""; tfInput.setText(selectedFile.getAbsolutePath());
while (myReader.hasNextLine()) { while (myReader.hasNextLine()) {
data += myReader.nextLine(); data.setText(myReader.nextLine());
} }
System.out.println(data);
myReader.close(); myReader.close();
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
System.out.println("An error occurred."); System.out.println("File not Found");
e.printStackTrace(); e.printStackTrace();
} }
} else { } else {
System.out.println("The file is not a csv file."); Main.showAlert("The file is not a csv file.");
} }
} }
} }