From 12d8929afcbf422381709f5dd1b46a0a4595503a Mon Sep 17 00:00:00 2001 From: EthanZeigler Date: Fri, 26 May 2017 20:06:16 -0400 Subject: [PATCH] Throw FileNotFoundException instead of NullPointerException when loading image files. Reorder parameters of CollidableImageElement so width is before height. Update to v1.0. No more beta! --- .gitignore | 8 ++++++++ JGameGUI.iml | 15 +++++++++++++++ .../java/com/ethanzeigler/jgamegui/JGameGUI.java | 9 +++++++-- .../jgamegui/element/CollidableImageElement.java | 2 +- 4 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 .gitignore create mode 100644 JGameGUI.iml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e546b69 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +# Created by .ignore support plugin (hsz.mobi) +.DS_Store +.idea/ +src/.DS_Store +src/main/.DS_Store +src/main/java/.DS_Store +src/main/java/com/.DS_Store +JGameGUI.iml diff --git a/JGameGUI.iml b/JGameGUI.iml new file mode 100644 index 0000000..36fb835 --- /dev/null +++ b/JGameGUI.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/ethanzeigler/jgamegui/JGameGUI.java b/src/main/java/com/ethanzeigler/jgamegui/JGameGUI.java index a559479..c7008cf 100644 --- a/src/main/java/com/ethanzeigler/jgamegui/JGameGUI.java +++ b/src/main/java/com/ethanzeigler/jgamegui/JGameGUI.java @@ -15,6 +15,8 @@ import java.awt.*; import java.awt.event.*; import java.awt.image.BufferedImage; +import java.io.FileNotFoundException; +import java.net.URL; /** * A Java Swing game API designed and created by Ethan Zeigler, class of '16. @@ -385,9 +387,12 @@ public void mousePressed(MouseEvent e) { * @return the ImageIcon if found */ public static ImageIcon loadImageFromFile(String filePath) { - if (filePath == null) - return null; + if (filePath == null) throw new NullPointerException("Input cannot be null"); + URL url = JGameGUI.class.getResource("/" + filePath); + if (url == null) throw new RuntimeException( + new FileNotFoundException("File \"/" + filePath + "\" does not exist. " + + "Check and make sure that the desired file is at this location after compiling.")); return new ImageIcon(JGameGUI.class.getResource("/" + filePath)); } diff --git a/src/main/java/com/ethanzeigler/jgamegui/element/CollidableImageElement.java b/src/main/java/com/ethanzeigler/jgamegui/element/CollidableImageElement.java index d3c598c..2f5b4d3 100644 --- a/src/main/java/com/ethanzeigler/jgamegui/element/CollidableImageElement.java +++ b/src/main/java/com/ethanzeigler/jgamegui/element/CollidableImageElement.java @@ -39,7 +39,7 @@ public CollidableImageElement(String resPath, double xOrig, double yOrig, double * @param height the collision area's height * @param priority the drawing priority. The higher the priority, the later it is drawn, and over others with lower priorities */ - public CollidableImageElement(ImageIcon icon, double xOrig, double yOrig, double height, double width, int priority) { + public CollidableImageElement(ImageIcon icon, double xOrig, double yOrig, double width, double height, int priority) { super(icon, xOrig, yOrig, priority); this.width = width; this.height = height;