Chapter 131 Applets and HTML Chapter 13. 2 Objectives learn how to write applets learn to write a simple HTML document learn how to embed an applet in.

Slides:



Advertisements
Similar presentations
Learn about Java applets. Know the differences between Java applets and applications. Designing and using Java applets Running Java applets. Security.
Advertisements

Dept. of Computer Science - SSBN Java Applets Vishnuvardhan.M.
Html: getting started HTML is hyper text markup language. It is what web browsers look at on the Internet. HTML documents should be created in a simple.
Unit 3 Day 4 FOCS – Web Design. No Journal Entry.
Creating and Editing a Web Page Using Inline Styles
Slides prepared by Rose Williams, Binghamton University Mouse Events + Chapter 17: Applets.
CIS101 Introduction to Computing Week 05. Agenda Your questions Exam next week - Excel Introduction to the Internet & HTML Online HTML Resources Using.
Slides prepared by Rose Williams, Binghamton University Chapter 18 Applets.
1 Applets Chapter 1 To understand:  why applets are used to extend the capabilities of Web pages  how an applet is executed and know about the restrictions.
CIS101 Introduction to Computing Week 05. Agenda Your questions CIS101 Survey Introduction to the Internet & HTML Online HTML Resources Using the HTML.
Chapter 12Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Announcements/Reminders l Happy Tax Day! l Project 8 due on Thursday.
Chapter 14 Applets. 2 Knowledge Goals Understand the differing roles of applications and applets Understand how a browser operates Understand the role.
Slides prepared by Rose Williams, Binghamton University Chapter 18 Applets.
1 CA201 Word Application Creating Document for the Web Week # 9 By Tariq Ibn Aziz Dammam Community college.
Java Applets. Lecture Objectives Learn about Java applets. Know the differences between Java applets and applications. Designing and using Java applets.
Introduction to HTML 2006 CIS101. What is the Internet? Global network of computers that are connected and communicate via a series of Protocols Protocols.
Introduction to HTML 2004 CIS101. What is the Internet? Global network of computers that are connected and communicate via a series of Protocols Protocols.
Chapter 131 Applets and HTML Chapter Reminders Project 8 due Dec 10:30 pm Project 6 regrades due by midnight tonight –Submit all files (including.
28-Jun-15 Applets. 2 An applet is a program that is typically embedded in a Web page and can be run from a browser You need special HTML in the Web page.
HTML Companion. Lecture Objectives Learn about HTML. Know basic HTML tags.
Chapter 20 Applets Slides prepared by Rose Williams, Binghamton University Copyright © 2008 Pearson Addison-Wesley. All rights reserved.
Applets, HTML and GUI’s Recitation – 04/11/2008 CS 180 Department of Computer Science, Purdue University.
CIS101 Introduction to Computing Week 06. Agenda Your questions Excel Exam during second hour Our status after the snow day Introduction to the Internet.
The Internet & The World Wide Web Notes
Chapter 16 The World Wide Web Chapter Goals ( ) Compare and contrast the Internet and the World Wide Web Describe general Web processing.
Chapter 13Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 13 l HTML l Applets Applets and HTML.
CPS120: Introduction to Computer Science The World Wide Web Nell Dale John Lewis.
Windows Internet Explorer 9 Chapter 1 Introduction to Internet Explorer.
WEB DESIGN USING DREAMWEAVER. The World Wide Web –A Web site is a group of related files organized around a common topic –A Web page is a single file.
Applets Chapter 17.  Java’s big splash onto the scene came in the mid 90’s. The people at Sun Microsystems had managed to work java programs into Web.
Using a Template to Create a Resume and Sharing a Finished Document
Tutorial 1: Browser Basics.
Introduction to HTML. What is a HTML File?  HTML stands for Hyper Text Markup Language  An HTML file is a text file containing small markup tags  The.
 2008 Pearson Education, Inc. All rights reserved Introduction to XHTML.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
Chapter 17: Applets, Images, and Sound. Objectives Learn about applets Write an HTML document to host an applet Use the init() method Work with JApplet.
HTML Hyper Text Markup Language. What is an HTML File?  HTML stands for Hyper Text Markup Language  An HTML file is a text file containing small markup.
Chapter 8 Introduction to HTML and Applets Fundamentals of Java.
1 Week 1 l HTML l Applets Applets and HTML. 2 Overview l Applets: Java programs designed to run from a document on the Internet l HTML: Hypertext Markup.
Chapter 13. Applets and HTML HTML Applets Computer Programming with JAVA.
Windows Internet Explorer 7 Chapter 1 Introduction to Windows Internet Explorer.
Chapter 13Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 13 l HTML l Applets Applets and HTML.
Lec.10 + (Chapter 8 & 9) GUI Java Applet Jiang (Jen) ZHENG July 6 th, 2005.
4 Chapter Four Introduction to HTML. 4 Chapter Objectives Learn basic HTML commands Discover how to display graphic image objects in Web pages Create.
Ali Alshowaish. What is HTML? HTML stands for Hyper Text Markup Language Specifically created to make World Wide Web pages Web authoring software language.
Chapter 12Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Announcements/Reminders l Next week: »No Lectures »No Labs »Recitation.
HTML BTEC National in Computing Section5. Create Information “HTML: defining HTML, discussing HTML uses and demonstrating HTML basics, HTML structure…..
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.
Introduction to Computers 12/6/ BEGINNING HTML DESIGNING YOUR OWN WWW PAGES.
Applets, Images, and Audio Chapter 14 CSCI CSCI 1302 – Applets, Images, and Audio2 Outline Introduction The Applet Class –The init Method –The start.
Applets Java code is compiled into byte code instead of machine language –Languages like C, C++, Pascal and others are compiled into machine language so.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 2 – Welcome Application Introduction to Graphical.
Creating and Editing a Web Page
Chapter 27 Getting “Web-ified” (Web Applications) Clearly Visual Basic: Programming with Visual Basic nd Edition.
1 2/16/05CS120 The Information Era Chapter 4 Basic Web Page Construction TOPICS: Intro to HTML and Basic Web Page Design.
Creating and Editing a Web Page Using Inline Styles
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
Creating Web Pages with Links, Images, and Embedded Style Sheets
1 Applets Programming. Introduction Java programs are divided into two main categories, applets and applications. An application is an ordinary Java program.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 17 : Applets King Fahd University of Petroleum & Minerals College of Computer Science.
Chapter 14 Applets. Applets: Introduction Java programs are divided into two main categories, applets and applications An application is an ordinary Java.
Creating Web pages using HTML: Here, you will learn how to set up facilities on the internet by creating Web pages and mounting them on the World Wide.
Chapter 8 Introduction to HTML and Applets
Java Applets.
Chapter 27 WWW and HTTP.
Applets and HTML Chapter 13.
Chapter 13 Applets and HTML HTML Applets.
Chapter 16 The World Wide Web.
Presentation transcript:

Chapter 131 Applets and HTML Chapter 13

2 Objectives learn how to write applets learn to write a simple HTML document learn how to embed an applet in an HTML document

Chapter 133 Outline Applets HTML Applets in HTML

Chapter 134 Introduction Applets are simply Java programs designed to run from a document (page) on the World Wide Web. HyperText Markup Language (HTML) is the language used to create Web documents.

Chapter 135 Applets: Outline Introduction to Applets Applet Basics Running an Applet Adding Icons to an Applet

Chapter 136 Introduction to Applets An applet is a “small application” or a “little Java program.” Applets are Java programs that are typically displayed on a Website and viewed over the Internet. An applet can also be run as a stand-alone program on a computer which is not connected to the Internet.

Chapter 137 Applet Basics An applet is a derived class of class JApplet which is a class in the Swing library. When writing an applet, it is a good idea to include all of the following: import javax.swing.*; import java.awt.*; import java.awt.event.*;

Chapter 138 Applet Basics, cont.

Chapter 139 Applet Basics, cont. A JApplet is a Container, which permits you to add components to it in the same way you can add components to a JFrame. But, applets do not use the setVisible method or the setTitle method, nor do they need any size instructions. Applets are displayed automatically, and do not need to have a main method.

Chapter 1310 Applet Basics, cont. Applets typically do not use constructors. Instead they use method init which serves the same purpose. Setting colors, adding components, etc. is done in method init. Method init has no parameters and is not overloaded. Applets do not need to be closed using listeners.

Chapter 1311 Applet Basics, cont. class HelloApplet

Chapter 1312 Applet Basics, cont.

Chapter 1313 Running an Applet Applets are compiled the same way other Java classes are compiled. However, the normal way to run an applet is as part of a Web document. –The applet then is viewed using a Web browser. An applet can also be viewed using an applet viewer which is a program designed to run an applet as a stand-alone program.

Chapter 1314 Programming Example: An Adder Applet class AdderApplet

Chapter 1315 Programming Example: An Adder Applet, cont.

Chapter 1316 Converting a Swing Application to an Applet Derive the class from JApplet rather than from JFrame. Remove method main. Replace the constructor(s) with a method named init.

Chapter 1317 Converting a Swing Application to an Applet Delete any invocation of addWindowListener. Delete any invocation of setTitle. Delete any invocation of setSize.

Chapter 1318 Adding Icons to an Applet An icon typically is a small picture. By placing the icon in a JLabel, the icon is displayed. A JLabel can consist of text, an icon, or both. A JButton or JMenuItem can also have an icon.

Chapter 1319 Adding Icons to an Applet, cont. class DukeApplet

Chapter 1320 Adding Icons to an Applet, cont.

Chapter 1321 Adding Icons to an Applet, cont. ImageIcon is a class in the Swing library. syntax ImageIcon Name_of_ImageIcon = new ImgeIcon(Picture_File_Name); –Picture_File_Name is a string giving either a relative or absolute path name to the picture file.

Chapter 1322 HTML: Outline Introduction to HTML HTML Basics Inserting Hyperlinks Displaying a Picture

Chapter 1323 Introduction to HTML Documents to be read on the Web or using a Web browser typically are expressed in a language called HTML. HTML stands for HyperText Markup Language. Hypertext contains links (or hyperlinks) which permit you to go to other documents.

Chapter 1324 Introduction to HTML, cont. These documents are called pages. HTML is not a general-purpose programming language like Java. Instead, it is a collection of simple (markup) commands that can produce something that can be viewed using a Web browser.

Chapter 1325 Introduction to HTML, cont. The commands allow you to include pictures and hyperlinks. The commands also allow you to specify headings, subheadings, paragraph beginnings, etc. In short, HTML is mostly a language for formatting a manuscript so that it can be viewed on the Web.

Chapter 1326 HTML Basics Most HTML commands are of the form Some text example My Home Page

Chapter 1327 HTML Basics, cont. Anything between and is centered on the page when it is displayed. Some commands do not need a closing command. For example begins a new line and begins a new paragraph. The browser inserts breaks where necessary to fit the text appropriately on the screen.

Chapter 1328 HTML Basics, cont. HTML is not case sensitive.,,, are all the same… An HTML file is a regular text file that you create and edit with a text editor. HTML files should end with.html or.htm Commands such as and form a “container” (in this case a table container).

Chapter 1329 HTML Basics, cont.

Chapter 1330 HTML Basics, cont. The entire document is enclosed between and. The head of the document is enclosed between and. –The head contains information used by a browser, but typically not displayed. –It might consist only of a title enclosed between and, used to name the document.

Chapter 1331 HTML Basics, cont. Two parts of the document are displayed on the screen. –The body is enclosed between and and is the real content of the document. –The address is optional. It is enclosed between and. It includes the address of the document’s owner and the last date the document was modified.

Chapter 1332 HTML Basics, cont.

Chapter 1333 HTML Basics, cont.

Chapter 1334 Inserting Hyperlinks The key active element in an HTML document is a link that the person viewing the document can click to view another HTML document. syntax Displayed_Text_to_Click

Chapter 1335 Inserting Hyperlinks, cont. example Walter Savitch The Path_to_Document can be either a full path name or a relative path name to a HTML file or a URL to any place on the Web.

Chapter 1336 URLs A URL is a kind of path name for the World Wide Web. URL stands for Uniform Resource Locator. URLs are absolute path names to documents anywhere in the world. Relative path names can be used for documents on your own computer.

Chapter 1337 Displaying the Most Current Version of a Document While you are developing an HTML page, you can display the most recent version of the page by clicking the button labeled Reload (or perhaps Refresh). Otherwise, for efficiency, the browser may access an earlier copy of the page.

Chapter 1338 Displaying a Picture A picture can be inserted into an HTML document using example The picture can be in any directory, but the path name, either full or relative, leading to the picture must be provided.

Chapter 1339 Applets in HTML: Outline Placing an Applet in an HTML Document (optional) The Older Applet Class Applets and Security

Chapter 1340 Placing an Applet in an HTML Document To display the adder window created by class AdderApplet, place the following command in an HTML document: (Actually “.class” is optional. code=“AdderApplet” works just as well)

Chapter 1341 Placing an Applet in an HTML Document, cont. This command assumes that the HTML file and the file AdderApplet.class are in the same directory. –Otherwise, a relative or absolute path name to AdderApplet.class is needed.

Chapter 1342 Placing an Applet in an HTML Document, cont.

Chapter 1343 Placing an Applet in an HTML Document, cont.

Chapter 1344 Using an Old Web Browser A Web browser must be set up to run applets. Web browsers do not use the same Java interpreter used to run Java applications. Older Web browsers (yours or someone else’s who may want to view your HTML document) may not be able to run applets from an HTML document.

Chapter 1345 Using an Old Web Browser, cont. Furthermore, Java updates for browsers typically lag core Java language updates. Using the older Applet class sometimes can remedy the problem. These problems do not exist if you are running applets from the applet viewer using a recent version of Java.

Chapter 1346 The Older Applet Class To use the older Applet class instead of the JApplet class –remove the J s from JApplet, JButton, JLabel, etc. (that is, use Applet, Button, Label ) –use the following import statements import java.awt.*; import java.awt.event.*; import java.applet.*;

Chapter 1347 The Older Applet Class, cont. –you do not need import javax.swing.*; –add components to the applet to itself rather than using a content pane (whatever was done to the content pane of a JApplet should be done directly to the Applet ).

Chapter 1348 The Older Applet Class, cont. –example: substitute add(friendlyLabel); for getContentPane().add(friendlyLabel); Furthermore, class Applet cannot accommodate icons easily.

Chapter 1349 Applets and Security Your applet is a program that may be run on someone else’s computer. Worse, someone else’s applet might be run on your computer! Furthermore, you don’t know that an HTML page contains an applet until you load it into your browser, and then it is too late to reject the applet; it is already stored on your computer.

Chapter 1350 Applets and Security, cont. Someone else’s program running on your computer creates serious security concerns. –Will it leave a virus? –Will it alter your files or read confidential information? –Will it corrupt your operating system? Applets cannot do any of these things (at least not easily).

Chapter 1351 Applets and Security, cont. Applets cannot run your programs, nor can they read from or write to files on your computer (unless the applet originated on your computer).

Chapter 1352 Summary You have learned how to write applets. You have learned to write a simple HTML document. You have learned how to embed an applet in an HTML document.