Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

GUI Programming Project: Creating a Web Browser using Java and SWT - Prof. Frank Mccown, Study notes of Computer Science

A programming project where students are required to create a web browser using java and swt. The browser should allow users to surf the web, go forward and back through browsing history, bookmark popular urls, and hold up to six tabs. The application window includes a toolbar with navigation buttons, a textbox for entering urls, and a horizontal tab control for browser tabs.

Typology: Study notes

Pre 2010

Uploaded on 08/19/2009

koofers-user-qpb
koofers-user-qpb 🇺🇸

10 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
GUI Programming
Program #3 – Web Browser
Due Sun, Dec 9 at midnight
100 Points
Overview
You are to create a web browser using Java and SWT. The browser will allow the user to “surf” the Web just like other
popular browsers like Internet Explorer and Firefox. The user can go forward or back through the browse history, and
popular URLs can be bookmarked. The application window can hold up to six tabs, each with its own browser and browse
history. A screenshot of what your browser may look like is shown below.
Requirements
The following specifications must be met in order to receive all 100 points:
1. The application should have a single window with:
a. A custom icon in the title bar
b. A toolbar containing various navigation buttons as shown above
c. A textbox for entering URLs
d. A portion of the screen that animates when pages are being downloaded
e. A horizontal tab control where browser tabs are located
f. A status bar at the bottom of the window that displays the currently selected browser’s status and progress bar
showing how much of a web page has been downloaded.
The progress bar should only be visible when a page is downloading. The window should be resizable.
2. All buttons in the toolbar should be represented graphically. You can design your own graphics or “steal” them from
another browser.
3. The program should have a single tab open to the home page when the application is first started. The home page can
be set to any location the programmer want s (optionally, a button on the browser’s toolbar could allow the user to
change the home page to the currently viewed page). A button on the browser’s toolbar should allow new tabs to be
created, up to a maximum of 6 tabs. When a tab is created, it should become the active tab, and the home page should
pf3
pf4
pf5

Partial preview of the text

Download GUI Programming Project: Creating a Web Browser using Java and SWT - Prof. Frank Mccown and more Study notes Computer Science in PDF only on Docsity!

GUI Programming

Program #3 – Web Browser

Due Sun, Dec 9 at midnight

100 Points

Overview

You are to create a web browser using Java and SWT. The browser will allow the user to “surf” the Web just like other

popular browsers like Internet Explorer and Firefox. The user can go forward or back through the browse history, and

popular URLs can be bookmarked. The application window can hold up to six tabs, each with its own browser and browse

history. A screenshot of what your browser may look like is shown below.

Requirements

The following specifications must be met in order to receive all 100 points:

1. The application should have a single window with:

a. A custom icon in the title bar

b. A toolbar containing various navigation buttons as shown above

c. A textbox for entering URLs

d. A portion of the screen that animates when pages are being downloaded

e. A horizontal tab control where browser tabs are located

f. A status bar at the bottom of the window that displays the currently selected browser’s status and progress bar

showing how much of a web page has been downloaded.

The progress bar should only be visible when a page is downloading. The window should be resizable.

2. All buttons in the toolbar should be represented graphically. You can design your own graphics or “steal” them from

another browser.

3. The program should have a single tab open to the home page when the application is first started. The home page can

be set to any location the programmer wants (optionally, a button on the browser’s toolbar could allow the user to

change the home page to the currently viewed page). A button on the browser’s toolbar should allow new tabs to be

created, up to a maximum of 6 tabs. When a tab is created, it should become the active tab, and the home page should

be loaded into it. The tab’s title should reflect the first 40 characters of the title of the tab’s currently loaded web page.

The user can close individual tabs using a close button on the tab.

4. The program should have the following 5 buttons that control navigation of the currently selected browser:

a) Back – to go back one or more pages.

b) Forward – to go forward one or more pages.

c) Stop – to stop downloading the current web page.

d) Refresh – to reload the current web page.

e) Home – to go back to the home page.

5. The Back, Forward, and Stop buttons should be disabled if the actions they implement are not available. For example, if

the user has not yet visited a second web page, there is no reason the Back button should be enabled. And if there is

nothing downloading, the Stop button should not be enabled.

6. The Back and Forward buttons should have an arrow on the side that, if clicked, shows the pages (by title) the user can

go back to or forward to in a popup menu. If the user selects an item from the menu, the browser should navigate to the

selected page. The Back and Forward buttons’ popup menus should also change based on which browser tab is selected,

so only the current browser’s history is accessible.

7. The user should be able to add new bookmarks using a button from the toolbar, and s/he should be able to access any of

the previously bookmarked pages from a popup menu that appears when clicking on a button in the toolbar. The

bookmarks are to be labeled according to the title of the page it refers to. A method for renaming, deleting, and re-

ordering bookmarks is not necessary. All bookmarked pages should be stored to the file bookmarks.txt in the same

directory as the local images so they are available when the application is restarted.

8. Your program must use the BrowserEx class (discussed later) which extends the org.eclipse.swt.browser.Browser

implementation.

Grading

Your application should implement all the requirements given. You may want to mimic my Extreme Browser, IE, or Firefox.

5 bonus points are available for changing the text box for entering URLs into a combo box that maintains the browser history

and shows the favicon (website icon) of the website being viewed. Both IE and Firefox implement this functionality, so you

should mimic their behavior.

All files making up your Eclipse project should be zipped together and submitted to Easel before the due date. I will load your

project into Eclipse and run it from there to test it.

We've all heard that a million monkeys banging on a million typewriters

will eventually reproduce the entire works of Shakespeare.

Now, thanks to the Internet, we know this is not true.

- Robert Wilensky

import java.util.ArrayList; import org.eclipse.swt.browser.Browser; import org.eclipse.swt.browser.ProgressEvent; import org.eclipse.swt.browser.ProgressListener; import org.eclipse.swt.browser.TitleEvent; import org.eclipse.swt.browser.TitleListener; import org.eclipse.swt.widgets.Composite;

public class BrowserEx extends Browser {

// Parallel arrays storing browser history Title and URL private ArrayList historyTitle; private ArrayList historyUrl;

// Set to false to prevent the progress listener from adding the loaded page // to the browser history arrays private boolean visitNewUrl = true ;

// Title of currently loaded web page private String title;

// Index into history arrays indicating which page is currently being viewed int currentLoc = -1;

// Index into history arrays indicating which page is the last valid // page the user can forward to int forwardLoc = -1;

public BrowserEx(Composite parent, int style) { super (parent, style);

historyTitle = new ArrayList(); historyUrl = new ArrayList();

super .addProgressListener( new ProgressListener() { public void changed(ProgressEvent event) { }

public void completed(ProgressEvent event) { // Only add this URL if user didn't use back and forward methods if (visitNewUrl) addLocationToHistory(); else visitNewUrl = true ; } });

// Set tab title to browser's web page title super .addTitleListener( new TitleListener() { public void changed(TitleEvent event) { title = event.title; } }); }

protected void checkSubclass() { // Disable the check that prevents subclassing of SWT components }

public String getTitle() { if (title == null ) return ""; return title; }

public boolean back() { visitNewUrl = false ; // Prevent adding this URL to history currentLoc--; return super .back(); }

public boolean back( int times) { for ( int i = 0; i < times; i++) { if (!back()) return false ;

return true ; }

public boolean forward() { visitNewUrl = false ; // Prevent adding this URL to history currentLoc++; return super .forward(); }

public boolean forward( int times) { for ( int i = 0; i < times; i++) { if (!forward()) return false ; } return true ; }

public String[] getBackList() { // Return a list of items that are in the back area }

public String[] getForwardList() { // Return a list of items that are in the forward area }

private void addLocationToHistory(String title, String url) { currentLoc++;

// See if there are any items in forward if (currentLoc == historyTitle.size()) {

if (currentLoc > 0) { if (historyUrl.get(currentLoc - 1).equalsIgnoreCase(url)) { // Ignore duplicate URLs that are next to each other currentLoc--; return ; } }

// Nothing in forward, so add to end of list historyTitle.add(title); historyUrl.add(url); } else { // There are items in forward, so replace them historyTitle.add(currentLoc, title); historyUrl.add(currentLoc, url); }

forwardLoc = currentLoc;

printHistory(); }

private void addLocationToHistory() { addLocationToHistory(title, super .getUrl()); }

}

Tabbed Browsing

To implement tabbed browsing, you’ll need to create a tab folder (org.eclipse.swt.custom.CTabFolder) to hold each tab:

tabFolder = new CTabFolder(parent, SWT. BORDER );

You will then create a tab (org.eclipse.swt.custom.CTabItem) which will hold each browser:

final CTabItem tabItem = new CTabItem(tabFolder, SWT. CLOSE ); final BrowserEx browser = new BrowserEx(tabFolder, SWT. NONE ); tabItem.setControl(browser);