JEditorPane Chapter 18 - Student. (c) 2005 by Elizabeth Sugar Boese JEditorPane creation Declare a JEditorPane component. JEditorPane pane; Check to see.

Slides:



Advertisements
Similar presentations
Exception Handling. Background In a perfect world, users would never enter data in the wrong form, files they choose to open would always exist, and code.
Advertisements

Exception Handling – illustrated by Java mMIC-SFT November 2003 Anders P. Ravn Aalborg University.
CS102--Object Oriented Programming
Chapter 8Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 8 l Basic Exception Handling »the mechanics of exceptions l.
Java Programming Exceptions. Java has a built in mechanism for error handling and trapping errors Usually this means dealing with abnormal events or code.
Slides prepared by Rose Williams, Binghamton University ICS201 Exception Handling University of Hail College of Computer Science and Engineering Department.
1 Lecture 11 Interfaces and Exception Handling from Chapters 9 and 10.
Java Programming, 3e Concepts and Techniques Chapter 4 Decision Making and Repetition with Reusable Objects.
(c) 2006 E.S.Boese All Rights Reserved. Threads and Timers Chapter 19 - Student.
1 L52 Networking (1). 2 OBJECTIVES In this chapter you will learn:  To understand Java networking with URLs, sockets and datagrams.  To implement Java.
 Pearson Education, Inc. All rights reserved. 1 CH24 Networking : OBJECTIVES In this chapter you will learn:  To understand Java networking.
Exceptions CIS 304 Intermediate Java Programming for Business.
Files and Streams CS 21a. 10/02/05 L18: Files Slide 2 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L24 (Chapter 25) Networking.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. COMPSCI 125 Spring 2005 Chapter 8  Errors and Exceptions Throwable class.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 25 Networking.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Exception Error handling. Exception 4 n An unusual occurrence during program execution that requires immediate handling n Errors are the most common type.
15-Jul-15 Basic Protocols. 2 Sockets Sockets, or ports, are a very low level software construct that allows computers to talk to one another When you.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Building a Web Browser CS1316: Representing Structure and Behavior.
Chapter 6: Graphical User Interface (GUI) and Object-Oriented Design (OOD) J ava P rogramming: Program Design Including Data Structures Program Design.
Io package as Java’s basic I/O system continue’d.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Java and C++, The Difference An introduction Unit - 00.
(c) E.S.Boese All Rights Reserved.1 Internet Applications Chapter 15 - Lecture Slides.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
What is an exception? An exception is: – an event that interrupts the normal processing of the program. –an error condition that violates the semantic.
Chapter 11 Exception Handling F Exceptions and Exception Types F Claiming Exceptions F Throwing Exceptions F Catching Exceptions F Rethrowing Exceptions.
June 14, 2001Exception Handling in Java1 Richard S. Huntrods June 14, 2001 University of Calgary.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
(c) 2008 E.S.Boese All Rights Reserved. Threads and Media Chapter 8 - Lecture Slides 1.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Very Brief Introduction to Java I/O with Buffered Reader and Buffered Writer.
Java Programming: Guided Learning with Early Objects
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 11: Handling Errors; File Input/Output.
1 Chapter 28 Networking. 2 Objectives F To comprehend socket-based communication in Java (§28.2). F To understand client/server computing (§28.2). F To.
MSc Workshop - © S. Kamin, U. ReddyLect 3 - GUI -1 Lecture 3 - Graphical User Interfaces r GUI toolkits in Java API r JFrame r GUI components.
CIS Intro to JAVA Lecture Notes Set June-05 GUI Programming – Assignment 5 Notes.
Chapter 12 1 TOPIC 13B l Buttons and Action Listeners Window Interfaces Using Swing Objects.
BIO Java 1 Exception Handling Aborting program not always a good idea – can’t lose messages – E-commerce: must ensure correct handling of private.
Data Structures Using Java1 Chapter 2 Inheritance and Exception Handling.
Chapter 12 Handling Exceptions and Events. Chapter Objectives Learn what an exception is Become aware of the hierarchy of exception classes Learn about.
FT228/3 Web Development Error processing. Introduction READ Chapter 9 of Java Server Pages from O’reilly 2 nd Edition Need to be able to 1) Diagnose and.
Computer Programming with JAVA Chapter 8. Exception Handling Basic Exception Handling the mechanics of exceptions Defining and Using Exceptions some "simple"
Creating Applets. What is an applet? What is an applet? A Java program that runs in a web browser. A Java program that runs in a web browser. An applet.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Java Programming, 2E Introductory Concepts and Techniques Chapter 4 Decision Making and Repetition with Reusable Objects.
Data Structures and Java CS /14/2015 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L6:
Exceptions Chapter 16 This chapter explains: What as exception is Why they are useful Java exception facilities.
Exceptions and Assertions Chapter 15 – CSCI 1302.
CIS Intro to JAVA Lecture Notes Set July-05 GUI Programming –TextField Action Listeners, JEditorPane action listeners, HTML in a JEditorPane,
Chapter 10 Exceptions 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design © 2007 Pearson Addison-Wesley. All rights reserved.
Event Handling (the right way). A Simple Web Page Events - Summary The web page looks like this:
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Exception Handling in C + + Introduction Overview of C++ Exception Handling Designing With Exceptions Exception Handling Philosophies Conclusion.
Lecture10 Exception Handling Jaeki Song. Introduction Categories of errors –Compilation error The rules of language have not been followed –Runtime error.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 28.1 Java Speech API 28.2 Downloading and.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Frame Windows Application program, not applet Construct and show frame JFrame frame = new JFrame(); *** frame.show(); *** Set default close operation..
Exception. Agenda Exception. Handling Exceptions. The finally Clause.
Garbage Collection It Is A Way To Destroy The Unused Objects. To do so, we were using free() function in C language and delete() in C++. But, in java it.
CSE 205 Exam 2 Review By Cheri Thompson and Katherine Kincade.
Generics, Exceptions and Undo Command
Accessing Files in Java
Using Procedures and Exception Handling
Use proper case (ie Caps for the beginnings of words)
HTML in Swing
Presentation transcript:

JEditorPane Chapter 18 - Student

(c) 2005 by Elizabeth Sugar Boese JEditorPane creation Declare a JEditorPane component. JEditorPane pane; Check to see if it is null (first time we run the applet). If it is null, we instantiate it: if( pane == null ) pane = new JEditorPane( );

(c) 2005 by Elizabeth Sugar Boese JEditorPane Set the web page in to the JEditorPane. NOTE: The URL MUST begin with pane.setPage( url ); try...catch blocks are Java's way of handling __________ which are thrown We need to put our code within a try…catch block in case there is a problem accessing the web page. try { pane.setPage( url ); } catch( IOException ioe ) { pane.setText( "Error accessing web page: " + url ); } If there is an error accessing the page we want, we’ll print the error message inside the JEditorPane

(c) 2005 by Elizabeth Sugar Boese JEditorPane – setupURL method Create a method setupURL to make it easier for us to __________ the page being displayed: public void setupURL( String url ) { if( pane == null ) pane = new JEditorPane( ); try { pane.setPage( url ); } catch( IOException ioe ) { pane.setText( "Error accessing web page: " + url ); }

(c) 2005 by Elizabeth Sugar Boese JEditorPane Store the JEditorPane inside a JScrollPane, to ensure users can access the _____________ being displayed JScrollPane scrollPane = new JScrollPane(pane);

(c) 2005 by Elizabeth Sugar Boese JEditorPane Handle clicks on links inside the web page that is displayed. To do this, there are four things we need to do (similar to other events we've worked with). 1. These events are inside the javax.swing.event package import javax.swing.event.*; 2. Specify that we are listening for these type of events – implements HyperlinkListener 3. Specify that we want to listen for HyperLinkEvents on our JEditorPane component: pane.addHyperlinkListener( this ); 4. Implement the required method for implementing the HyperlinkListener, public void hyperlinkUpdate( HyperlinkEvent event ) { if( event.getEventType() == HyperlinkEvent.EventType.ACTIVATED ) { setupURL( String.valueOf( event.getURL( )) ); }

(c) 2005 by Elizabeth Sugar Boese Simple example see JEditorPaneEx.java

(c) 2005 by Elizabeth Sugar Boese Example with buttons see JEditorPaneExBtn.java

(c) 2005 by Elizabeth Sugar Boese Summary JEditorPane