• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Form in NetBeans

Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd like create a easy form with a window displayed a web page(NetBeans or Eclipse). I am beginner. Could you help me please?
Posts: 75857
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Simple web browsers: We had to make one of those back in the Autumn for our MSc course. I don't think it is a beginner's task, but I have copied the sheet to go with the lab work (I am sure Dr Norval won't mind).

Advanced Java Programming
Lab work sheet 5

(This is expected to take 2 weeks to complete)
Aim: Design and build a simple web browser.

Your Web Browser should have
1.a text field to input a URL
2.a back button to display web pages previously visited
3.a forward button to allow the browser to move forward through list of visited URLs
4.a display area for html pages ( JEditorPane)

User Interface

The design of the User interface is up to you. Suggestions are
-Buttons and labelled text field, in a JPanel, placed in the overall panel using BorderLayout. NORTH.
-JEditorPane, possibly in a JScrollPane, which is then placed with BorderLayout.CENTER.
-You could use the JToolBar component for the two buttons and textfield instead.
-�Forward� and �Back� buttons could have images (Icons class) rather than text for the familiar > and < symbols. See JButton constructor in java.swing.JButton

JEditorPane information (javax.swing package)

-JEditorPane will display HTML pages using the method setPage(URL myurl).(If the HTML page has embedded frames the content may change). setPage throws an IOException, which should be caught.

-The editor pane should be un- editable so that hyperinks within the page can be visited. e.g. pane.setEditable(false);

-The editor pane is a source of Hyperlink events, and a HyperlinkListener interface object can respond to the events with a method hyperlinkUpdate ( HyperlinkEvent )
JEditorPane Hyperlink events ( Hyperlink events in javax.swing.event )

-The hyperlink listener responds to events such as mouse moving over the hyperlink, or clicking the hyperlink. The Hyperlink event should be checked to see if it is a mouse click (EventType.ACTIVATED) .
-From the HyperlinkEvent, the URL can be found, using event.getURL()
-This URL can then be used to visit a new page, update the textfield, and be added to the pages visited .
-An example of this is given below where pane is a JEditorPane object

pane.addHyperlinkListener(new HyperlinkListener()
public void hyperlinkUpdate(HyperlinkEvent e)
if( e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
URL url = e.getURL();
// call your method to go to the URL,

URL information ( java. net package)

A URL can be formed from a string,
URL myurl = new URL (� http://www.tees.ac.uk�);

A MalformedURLException needs to be caught or thrown.
The string representing a URL object can be found with the toString() method e.g.
String homeurl = myurl.toString();

History of pages visited. (ArrayList in java.util)

Use an ArrayList, holding URL classes. Each time a new page is visited, add the URL to the list. Keep track of the current position in the ArrayList (e.g.int currentplace, initially 0), incrementing this for each new page visited. The forward and back buttons can then have actions to get the next or previous UR. [ An Iterator is not useful here as an iterator only moves in one direction through a Collection]

Program design

It is tempting to launch straight in, testing JEditorPane method to show HTML pages.
You are strongly recommended to spend time designing the application, using 2-3 classes with small methods. Use UML diagrams to identify what methods go where and which data fields are needed in which classes.

I was told off for trying to display the website of a University 20 miles from here in my exercise.


Good luck, but don't attempt it if you think it is beyond you.
Campbell Ritchie
Posts: 75857
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have had another look at Horstmann's book, which I quote several times daily.
Horstmann C, Cornell G, Core Java 2 7/e vol II-advanced features, Upper Saddle River NJ: Prentice-Hall (Sun Microsystems Press) 2004.
On page 410 there is a description of editor panes etc, and how they can be used to show HTML.
There will be an example which ought to be possible to download from Horstmann'd website.
See whether you can understand it.
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic