Skip to content

lab for today: made edits to files #28

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# lab_browser
A simple GUI example: a web browser

by David Zhou (dz54) and Kevin Wang (kw197)
6 changes: 6 additions & 0 deletions src/BrowserException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

public class BrowserException extends RuntimeException {
public BrowserException(String s){
super(s);
}
}
13 changes: 9 additions & 4 deletions src/BrowserModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;


/**
Expand All @@ -18,6 +19,8 @@ public class BrowserModel {
// state
private URL myHome;
private URL myCurrentURL;
private static final String errorResources = "resources/error";
private ResourceBundle myErrorResource;
private int myCurrentIndex;
private List<URL> myHistory;
private Map<String, URL> myFavorites;
Expand All @@ -32,6 +35,7 @@ public BrowserModel () {
myCurrentIndex = -1;
myHistory = new ArrayList<>();
myFavorites = new HashMap<>();
myErrorResource = ResourceBundle.getBundle(errorResources);
}

/**
Expand All @@ -42,7 +46,8 @@ public URL next () {
myCurrentIndex++;
return myHistory.get(myCurrentIndex);
}
return null;
throw new BrowserException(myErrorResource.getString("next"));

}

/**
Expand All @@ -53,7 +58,7 @@ public URL back () {
myCurrentIndex--;
return myHistory.get(myCurrentIndex);
}
return null;
throw new BrowserException(myErrorResource.getString("back"));
}

/**
Expand Down Expand Up @@ -119,7 +124,7 @@ public URL getFavorite (String name) {
if (name != null && !name.equals("") && myFavorites.containsKey(name)) {
return myFavorites.get(name);
}
return null;
throw new BrowserException(myErrorResource.getString("getFavorite"));
}

// deal with a potentially incomplete URL
Expand All @@ -137,7 +142,7 @@ private URL completeURL (String possible) {
// e.g., let user leave off initial protocol
return new URL(PROTOCOL_PREFIX + possible);
} catch (MalformedURLException eee) {
return null;
throw new BrowserException(myErrorResource.getString("completeURL"));
}
}
}
Expand Down
Loading