<< 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

Preface

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.

Figures

  • 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.

Listings

  • 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

if three forces F1.f2 .f3 act at a point on a Cartesian plane in the daigram .....so if the question says write down the x and y components ..... I really don't understand
Syamthanda Reply
hey , can you please explain oxidation reaction & redox ?
Boitumelo Reply
hey , can you please explain oxidation reaction and redox ?
Boitumelo
for grade 12 or grade 11?
Sibulele
the value of V1 and V2
Tumelo Reply
advantages of electrons in a circuit
Rethabile Reply
we're do you find electromagnetism past papers
Ntombifuthi
what a normal force
Tholulwazi Reply
it is the force or component of the force that the surface exert on an object incontact with it and which acts perpendicular to the surface
Sihle
what is physics?
Petrus Reply
what is the half reaction of Potassium and chlorine
Anna Reply
how to calculate coefficient of static friction
Lisa Reply
how to calculate static friction
Lisa
How to calculate a current
Tumelo
how to calculate the magnitude of horizontal component of the applied force
Mogano
How to calculate force
Monambi
a structure of a thermocouple used to measure inner temperature
Anna Reply
a fixed gas of a mass is held at standard pressure temperature of 15 degrees Celsius .Calculate the temperature of the gas in Celsius if the pressure is changed to 2×10 to the power 4
Amahle Reply
How is energy being used in bonding?
Raymond Reply
what is acceleration
Syamthanda Reply
a rate of change in velocity of an object whith respect to time
Khuthadzo
how can we find the moment of torque of a circular object
Kidist
Acceleration is a rate of change in velocity.
Justice
t =r×f
Khuthadzo
how to calculate tension by substitution
Precious Reply
hi
Shongi
hi
Leago
use fnet method. how many obects are being calculated ?
Khuthadzo
khuthadzo hii
Hulisani
how to calculate acceleration and tension force
Lungile Reply
you use Fnet equals ma , newtoms second law formula
Masego
please help me with vectors in two dimensions
Mulaudzi Reply
how to calculate normal force
Mulaudzi
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




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?

Ask