Skip to content

pb111 recitation #19

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 3 commits 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>
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# lab_browser
A simple GUI example: a web browser

People
Parit Burintrathikul pb111
Zdravko Paskalev zp12
8 changes: 8 additions & 0 deletions src/BrowserException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

public class BrowserException extends Exception {

public BrowserException(String string) {
super(string);
}

}
3 changes: 2 additions & 1 deletion src/BrowserModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ public BrowserModel () {

/**
* Returns the first page in next history, null if next history is empty.
* @throws BrowserException
*/
public URL next () {
public URL next () throws BrowserException {
if (hasNext()) {
myCurrentIndex++;
return myHistory.get(myCurrentIndex);
Expand Down
18 changes: 18 additions & 0 deletions src/BrowserView.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public class BrowserView {
private Button myBackButton;
private Button myNextButton;
private Button myHomeButton;
private Button myFavoriteButton;
private Button myGetFavButton;
// favorites
private ComboBox<String> myFavorites;
// get strings from resource file
Expand All @@ -73,6 +75,7 @@ public class BrowserView {
*/
public BrowserView (BrowserModel model, String language) {
myModel = model;
myFavorites = new ComboBox<String>();
// use resources for labels
myResources = ResourceBundle.getBundle(DEFAULT_RESOURCE_PACKAGE + language);
BorderPane root = new BorderPane();
Expand Down Expand Up @@ -210,13 +213,28 @@ public void handle (ActionEvent event) {
result.getChildren().add(myNextButton);
myHomeButton = makeButton("HomeCommand", event -> home());
result.getChildren().add(myHomeButton);
myFavoriteButton = makeButton("AddFavoriteCommand", event ->addFavorite());
result.getChildren().add(myFavoriteButton);
// myGetFavButton = makeButton("FavoriteFirstItem", event -> showFavorite());
// result.getChildren().add(myGetFavButton);

result.getChildren().add(myFavorites);
myFavorites.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle (ActionEvent event) {
String a= myFavorites.getValue;
String url = myModel.getFavorite(a).toString();
showPage(url);
}
});
// if user presses button or enter in text field, load/show the URL
EventHandler<ActionEvent> showHandler = new ShowPage();
result.getChildren().add(makeButton("GoCommand", showHandler));
myURLDisplay = makeInputField(40, showHandler);
result.getChildren().add(myURLDisplay);
return result;
}


// make buttons for setting favorites/home URLs
private Node makePreferencesPanel () {
Expand Down