Skip to content

Commit

Permalink
Throw FileNotFoundException instead of NullPointerException when load…
Browse files Browse the repository at this point in the history
…ing image files. Reorder parameters of CollidableImageElement so width is before height.

Update to v1.0. No more beta!
  • Loading branch information
EthanZeigler committed May 27, 2017
1 parent ffedb39 commit 12d8929
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions JGameGUI.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:3.8.1" level="project" />
</component>
</module>
9 changes: 7 additions & 2 deletions src/main/java/com/ethanzeigler/jgamegui/JGameGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 12d8929

Please sign in to comment.