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

summarize halerambos & holbon
David Reply
the Three stages of Auguste Comte
Clementina Reply
what are agents of socialization
Antonio Reply
sociology of education
Nuhu Reply
definition of sociology of education
Nuhu
what is culture
Abdulrahim Reply
shared beliefs, values, and practices
AI-Robot
What are the two type of scientific method
ogunniran Reply
I'm willing to join you
Aceng Reply
what are the scientific method of sociology
Man
what is socialization
ogunniran Reply
the process wherein people come to understand societal norms and expectations, to accept society's beliefs, and to be aware of societal values
AI-Robot
scientific method in doing research
ogunniran
defimition of sickness in afica
Anita
Cosmology
ogunniran
Hmmm
ogunniran
list and explain the terms that found in society
REMMY Reply
list and explain the terms that found in society
Mukhtar
what are the agents of socialization
Antonio
Family Peer group Institution
Abdulwajud
I mean the definition
Antonio
ways of perceived deviance indifferent society
Naomi Reply
reasons of joining groups
SAM
to bring development to the nation at large
Hyellafiya
entails of consultative and consensus building from others
Gadama
World first Sociologist?
Abu
What is evolutionary model
Muhammad Reply
Evolution models refer to mathematical and computational representations of the processes involved in biological evolution. These models aim to simulate and understand how species change over time through mechanisms such as natural selection, genetic drift, and mutation. Evolutionary models can be u
faruk
what are the modern trends in religious behaviours
Selekeye Reply
what are social norms
Daniel Reply
shared standards of acceptable behavior by the group or appropriate behavior in a particular institution or those behaviors that are acceptable in a society
Lucius
that is how i understood it
Lucius
examples of societal norms
Diamond
Discuss the characteristics of the research located within positivist and the interpretivist paradigm
Tariro Reply
what is Industrialisation
Selekeye Reply
industrialization
Angelo
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