<< Chapter < Page Chapter >> Page >
The purpose of this module is to show students how to use Java Swing to render a web page in a JFrame object.

Table of contents


This module is one in a collection of modules designed for teaching INEW 2338 Advanced Java (Web) at Austin Community College in Austin, TX. More specifically, it is one in asub-collection of modules designed for teaching network programming in that course. The purpose of this module is to show students how to use Java Swingto render a web page in a JFrame object.

Viewing tip

I recommend that you open another copy of this module in a separate browser window and use the following links to easily find and view the Figuresand Listings while you are reading about them.


  • Figure 1 . JFrame output from the program named Java4655c.
  • Figure 2 . Command line output from the program named Java4655c.
  • Figure 3 . JFrame output from the program named Java4655b.
  • Figure 4 . JFrame output from the program named Java4655a.


  • Listing 1 . Beginning of the program named Java4655c.
  • Listing 2 . The method named runner.
  • Listing 3 . Beginning of the class named Java4655cHtmlHandler.
  • Listing 4 . Open the URL object in a JEditorPane object.
  • Listing 5 . Register a hyperlink listener.
  • Listing 6 . Display the JEditorPane.
  • Listing 7 . The hyperlinkUpdate method.
  • Listing 8 . The constructor for the Java4655bHtmlHandler class.
  • Listing 9 . The HyperlinkEvent handler for Java4655b.
  • Listing 10 . Scrolling code in Java4655a.
  • Listing 11 . The program named Java4655c.
  • Listing 12 . The program named Java4655b.
  • Listing 13 . The program named Java4655a.

Discussion and sample code

In an earlier module, you learned how to connect to a website and cause a raw text version of a file to be downloaded and displayed. However, the display of raw HTMLtext isn't very useful, which is why rendering web browsers were invented.

In this module, you will learn how to connect to a website and cause an HTML file to be downloaded and rendered in a JFrame object. We will develop a program that makes it possible to follow hyperlinks much as you wouldexpect with a commercial web browser.

A skeleton program - Java4655c

I will begin this explanation with a skeleton program that illustrates four important aspects of rendering a webpage in a Swing JFrame object :

  • Getting a URL object that is connected to a webpage.
  • Opening the URL object in a JEditorPane object.
  • Displaying the JEditorPane in a rendered format.
  • Handling hyperlink events on the JEditorPane .

(Note that there are alternatives to the first two items in the above list, which we will see later.)

To keep the code simple, two important aspects of webpage rendering will be omitted from this program:

  • Scrolling large web pages.
  • Following hyperlinks.

These capabilities will be added to other programs later in this module.

Beginning of the program named Java4655c

Questions & Answers

Introduction about quantum dots in nanotechnology
Praveena Reply
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
how to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
characteristics of micro business
for teaching engĺish at school how nano technology help us
Do somebody tell me a best nano engineering book for beginners?
s. Reply
there is no specific books for beginners but there is book called principle of nanotechnology
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
what is the actual application of fullerenes nowadays?
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
what is the Synthesis, properties,and applications of carbon nano chemistry
Abhijith Reply
Mostly, they use nano carbon for electronics and for materials to be strengthened.
is Bucky paper clear?
carbon nanotubes has various application in fuel cells membrane, current research on cancer drug,and in electronics MEMS and NEMS etc
so some one know about replacing silicon atom with phosphorous in semiconductors device?
s. Reply
Yeah, it is a pain to say the least. You basically have to heat the substarte up to around 1000 degrees celcius then pass phosphene gas over top of it, which is explosive and toxic by the way, under very low pressure.
Do you know which machine is used to that process?
how to fabricate graphene ink ?
for screen printed electrodes ?
What is lattice structure?
s. Reply
of graphene you mean?
or in general
in general
Graphene has a hexagonal structure
On having this app for quite a bit time, Haven't realised there's a chat room in it.
what is biological synthesis of nanoparticles
Sanket Reply
what's the easiest and fastest way to the synthesize AgNP?
Damian Reply
types of nano material
abeetha Reply
I start with an easy one. carbon nanotubes woven into a long filament like a string
many many of nanotubes
what is the k.e before it land
what is the function of carbon nanotubes?
I'm interested in nanotube
what is nanomaterials​ and their applications of sensors.
Ramkumar Reply
what is nano technology
Sravani Reply
what is system testing?
Got questions? Join the online conversation and get instant answers!
QuizOver.com Reply

Get the best Algebra and trigonometry course in your pocket!

Source:  OpenStax, Object-oriented programming (oop) with java. OpenStax CNX. Jun 29, 2016 Download for free at https://legacy.cnx.org/content/col11441/1.201
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?