Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposed resolution to issue # 83 (Invalid File type) #110

Closed
wants to merge 13 commits into from
29 changes: 17 additions & 12 deletions imagelab/ImageLab.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,18 +283,23 @@ public void actionPerformed(final ActionEvent ev) {
public static ActionListener makeOpenListener() {
return new ActionListener() {
public void actionPerformed(final ActionEvent e) {
ImgProvider improvider; // Hold the image
FileDialog fd;
fd = new FileDialog(frame, "Pick an image", FileDialog.LOAD);
fd.setVisible(true);
String theFile = fd.getFile();
String theDir = fd.getDirectory();
//System.out.println("The file's name is " + theDir + theFile);
improvider = new ImgProvider(theDir + theFile);
improvider.setLab(theLab);
improvider.showImage(theDir + theFile);
images.add(improvider);
impro = improvider; //current image provider is set
boolean found = false;
while(!found) {
ImgProvider improvider; // Hold the image
FileDialog fd;
fd = new FileDialog(frame, "Pick an image", FileDialog.LOAD);
fd.setVisible(true);
String theFile = fd.getFile();
String theDir = fd.getDirectory();
if(theFile.contains("jpg")||theFile.contains("gif")){
//System.out.println("The file's name is " + theDir + theFile);
improvider = new ImgProvider(theDir + theFile);
improvider.setLab(theLab);
improvider.showImage(theDir + theFile);
images.add(improvider);
impro = improvider; //current image provider is set
found = true;} //break the loop
}
} //actionPerformed
};
} // makeOpenListener
Expand Down
10 changes: 7 additions & 3 deletions imagelab/ImgProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,13 @@ public ImgProvider() {
* @param name The name of the file containing the image
*/
public ImgProvider(final String name) {
imgName = name;
isLoaded = false;
id = ++count;
if(name.contains(".jpg")||name.contains(".gif")){
imgName = name;
isLoaded = false;
id = ++count;}
else{
imgName = "VOID";
}
}

/**
Expand Down