Skip to content

Commit

Permalink
refactor(build): Fix Resources issue in .jar
Browse files Browse the repository at this point in the history
  • Loading branch information
itsamirhn committed Jun 8, 2024
1 parent 3d0e232 commit 5a5f964
Show file tree
Hide file tree
Showing 17 changed files with 8 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/main/java/com/amirhn/GUI/ChessController.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import com.amirhn.Pieces.Piece;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Objects;
import javax.sound.sampled.*;
import javax.swing.*;

Expand Down Expand Up @@ -76,9 +78,10 @@ private void playMoveSound(Move move) {
} else {
soundPath = Constants.MoveSoundPath;
}
URL soundURL = getClass().getResource(soundPath);
AudioInputStream audioInputStream = null;
try {
audioInputStream = AudioSystem.getAudioInputStream(new File(soundPath).getAbsoluteFile());
audioInputStream = AudioSystem.getAudioInputStream(Objects.requireNonNull(soundURL));
} catch (UnsupportedAudioFileException | IOException e) {
e.printStackTrace();
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/amirhn/GUI/Components/PieceImageIcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@

import com.amirhn.GUI.Constants;
import javax.swing.*;
import java.util.Objects;

/** The type Piece image icon. */
public class PieceImageIcon extends ImageIcon {
private static final String DefaultPath = Constants.PieceImageDirectory;

/**
* Instantiates a new Piece image icon.
*
* @param color the color
* @param typeLetter the type letter
*/
public PieceImageIcon(String color, char typeLetter) {
super(DefaultPath + "/" + color.toLowerCase().charAt(0) + typeLetter + ".png");
super(Objects.requireNonNull(PieceImageIcon.class.getResource(Constants.PieceImageDirectory + "/" + color.toLowerCase().charAt(0) + typeLetter + ".png")));
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/amirhn/GUI/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public class Constants {
public static final String GameTitle = "Chess";

/** The constant PieceImageDirectory. */
public static final String PieceImageDirectory = "png";
public static final String PieceImageDirectory = "/png";

/** The constant SoundDirectory. */
public static final String SoundDirectory = "sound";
public static final String SoundDirectory = "/sound";

/** The constant MoveSoundPath. */
public static final String MoveSoundPath = Constants.SoundDirectory + "/" + "move.wav";
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.

0 comments on commit 5a5f964

Please sign in to comment.