Skip to content

Commit

Permalink
Edit file path for fxmlLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
fredtwt committed Feb 14, 2022
1 parent 8130e3c commit ec8bcdd
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 10 deletions.
3 changes: 1 addition & 2 deletions src/main/java/doge/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package doge;

import java.io.File;
import java.io.IOException;

import doge.command.ByeCommand;
Expand All @@ -19,7 +18,7 @@ public class Main extends Application {
public void start(Stage stage) {
try {
FXMLLoader fxmlLoader =
new FXMLLoader(new File("./src/main/resource/view/MainWindow.fxml").toURI().toURL());
new FXMLLoader(MainWindow.class.getResource("/view/MainWindow.fxml"));
AnchorPane ap = fxmlLoader.load();
stage.setScene(new Scene(ap));
stage.setTitle("Doge");
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/doge/view/DialogBox.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package doge.view;

import java.io.File;
import java.io.IOException;
import java.util.Collections;

Expand All @@ -27,7 +26,8 @@ public class DialogBox extends HBox {

private DialogBox(String text, Image img) {
try {
FXMLLoader fxmlLoader = new FXMLLoader(new File("./src/main/resource/view/DialogBox.fxml").toURI().toURL());
FXMLLoader fxmlLoader =
new FXMLLoader(MainWindow.class.getResource("/view/DialogBox.fxml"));
fxmlLoader.setController(this);
fxmlLoader.setRoot(this);
fxmlLoader.load();
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/doge/view/DogeDialogBox.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package doge.view;

import java.io.File;
import java.io.IOException;

import javafx.fxml.FXML;
Expand All @@ -23,7 +22,7 @@ public class DogeDialogBox extends HBox {
private DogeDialogBox(String text, Image img) {
try {
FXMLLoader fxmlLoader =
new FXMLLoader(new File("./src/main/resource/view/DogeDialogBox.fxml").toURI().toURL());
new FXMLLoader(MainWindow.class.getResource("/view/DogeDialogBox.fxml"));
fxmlLoader.setController(this);
fxmlLoader.setRoot(this);
fxmlLoader.load();
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/doge/view/MainWindow.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package doge.view;

import java.io.File;

import doge.Doge;
import doge.Parser;
import doge.command.ByeCommand;
Expand Down Expand Up @@ -30,8 +28,8 @@ public class MainWindow extends AnchorPane {
private Button sendButton;

private Doge doge;
private Image userImg = new Image(new File("./src/main/resource/images/user.png").toURI().toString());
private Image dogeImg = new Image(new File("./src/main/resource/images/doge.jpg").toURI().toString());
private Image userImg = new Image(this.getClass().getResourceAsStream("/images/user.png"));
private Image dogeImg = new Image(this.getClass().getResourceAsStream("/images/doge.jpg"));

@FXML
public void initialize() {
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit ec8bcdd

Please sign in to comment.