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.

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.
1 Chapter 17 Applets and Multimedia. 2 Motivations F When browsing the Web – you frequently see the graphical user interface –animation developed using.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 18 Applets and Multimedia.
Slides prepared by Rose Williams, Binghamton University Mouse Events + Chapter 17: Applets.
Applets. The Applet Class public class MyApplet extends java.applet.Applet {... /** The no-arg constructor is called by the browser when the Web page.
Review of Java Applets Vijayan Sugumaran Decision and Information Sciences Oakland University.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 16 Applets.
1 Applets. 2 Motivations When browsing the Web, you frequently see the graphical user interface and animation developed using Java. These programs are.
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.
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.
Java Applets. Lecture Objectives Learn about Java applets. Know the differences between Java applets and applications. Designing and using Java applets.
Applet class The Applet class provides the essential framework that enables applets to be run by a web browser Applet do not have main method Applet depend.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 14 Applets, Images,
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.
Applets. What is an Applet?  According to Sun “An applet is a small program that is intended not to be run on its own, but rather to be embedded inside.
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.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L05 (Chapter 16) Applets.
Applets, HTML and GUI’s Recitation – 04/11/2008 CS 180 Department of Computer Science, Purdue University.
Java Programming, 2E Introductory Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
Applets  The Applet Class  The HTML Tag F Passing Parameters to Applets.
Chapter 9: Applets Jim Burns Fall Outline Learn about applets Learn about applets Write an HTML doc to host an applet Write an HTML doc to host.
Chapter 12 Applets and Advanced Graphics  The Applet Class  The HTML Tag F Passing Parameters to Applets F Conversions Between Applications and Applets.
Chapter 13Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 13 l HTML l Applets Applets and HTML.
16-1 The World Wide Web The Web An infrastructure of distributed information combined with software that uses networks as a vehicle to exchange that information.
JAVA APPLETS By: Ms. Humaira Siddiqui. Java and the Internet Java is considered to be a language well suited to be used in the internet. In contrast with.
JAPPLET.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
1 INF160 IS Development Environments AUBG, COS dept Lecture 04 Title: Computer Applications (Extract from Syllabus)
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.
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 12 Applets and Advanced GUI  The Applet Class  The HTML Tag F Passing Parameters to Applets F Conversions Between Applications and Applets F.
Chapter 13. Applets and HTML HTML Applets Computer Programming with JAVA.
Chapter 13Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 13 l HTML l Applets Applets and HTML.
Chapter 10: Applets and Advanced Graphics The Applet Class The Applet Class The HTML Tag The HTML Tag Passing Parameters to Applets Passing Parameters.
Lec.10 + (Chapter 8 & 9) GUI Java Applet Jiang (Jen) ZHENG July 6 th, 2005.
Pravin Yannawar, DOCS, NMU Jalgaon Basic Java : Applets 2 Objectives of This Session Identify the need for Applets Distinguish between Applets and Applications.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 16 Applets and Multimedia.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved GUI: Applets and Multimedia.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Applets and Multimedia.
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
Applets Yong Choi School of Business CSU, Bakersfield.
Java Programming Applets. Topics Write an HTML document to host an applet Understand simple applets Use Labels with simple AWT applets Write a simple.
Chapter 14 Applets and Advanced GUI  The Applet Class  The HTML Tag F Passing Parameters to Applets F Conversions Between Applications and Applets F.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
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.
1 WWW. 2 World Wide Web Major application protocol used on the Internet Simple interface Two concepts –Point –Click.
1 Applets. 2 Design of Applets 3 Sun wrote Java to be executable within a hosting application browser The applications are applets. An applet is downloaded.
Chapter 131 Applets and HTML Chapter Objectives learn how to write applets learn to write a simple HTML document learn how to embed an applet in.
Applets, Images, and Audio Chapter 14 CSCI CSCI 1302 – Applets, Images, and Audio2 Outline Introduction The Applet Class –The init Method –The start.
Creating a Java Application and Applet
1 Applets. 2 What is an applet? Applet: a Java program that can be inserted into a web page and run by loading that page in a browser brings web pages.
Introduction to Applets Chapter 21. Applets An applet is a Java application that is intended to be invoked and executed through a Web browser. Click Here.
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.
Chapter 8 Introduction to HTML and Applets
Java Applets.
Distributed Computing, M. L. Liu
UNIT-5.
Java Applets.
Chapter 13 Applets and HTML HTML Applets.
Presentation transcript:

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 pages, and the results were dazzling. The infusion of Java into the Web was powerful, efficient, portable, and secure  The trick was to create a part of a program, called an applet, and to display the applet inside a rectangle on the Web page

 Java programs are divided into two main categories, applets and applications  An application is an ordinary Java program  An applet is a kind of Java program that can be run across the Internet

 Applications are invoked from the static main method by the Java interpreter, and applets are run by the Web browser. The Web browser creates an instance of the applet using the applet’s no-arg constructor and controls and executes the applet through the init, start, stop, and destroy methods.  Applets have security restrictions  Web browser creates graphical environment for applets, GUI applications are placed in a frame.

 Applets are not allowed to read from, or write to, the file system of the computer viewing the applets.  Applets are not allowed to run any programs on the browser’s computer.  Applets are not allowed to establish connections between the user’s computer and another computer except with the server where the applets are stored.

 When the applet is loaded, the Web browser creates an instance of the applet by invoking the applet’s no-arg constructor.  The browser uses the init, start, stop, and destroy methods to control the applet.  By default, these methods do nothing.  To perform specific functions, they need to be modified in the user's applet so that the browser can call your code properly

 init() method  Executes when Web page containing a JApplet loaded  Or when running appletviewer command  start() method  Executes after init() method  Executes again every time applet becomes active after it has been inactive

 stop() method  Invoked when user leaves Web page  destroy() method  Called when user closes browser or Applet Viewer  Releases any resources JApplet might have allocated  Every JApplet has the same life cycle outline

 Always extends the JApplet class, which is a subclass of Applet for Swing components.  Override init(), start(), stop(), and destroy() if necessary. By default, these methods are empty.  Add your own methods and data if necessary.

import java.awt.*; import javax.swing.*; public class FirstApplet extends JApplet { public void init ( ) { getContentPane( ).setBackground(Color.ORANGE); setLayout(new BorderLayout( )); JLabel message = new JLabel("An applet a day keeps the doctor away. "); add(message, BorderLayout.CENTER); }

 Some of the items included in a Swing GUI are not included in an applet  Applets do not contain a main or setVisible method  Applets are displayed automatically by a Web page or an applet viewer  Applets do not have titles  Therefore, they do not use the setTitle method  They are normally embedded in an HTML document, and the HTML document can add any desired title

 Applets do not use the setSize method  The HTML document takes care of sizing the applet  Applets do not have a close-window button  Therefore, they do not have a setDefaultCloseOperation method  When the HTML document containing the applet is closed, then the applet is automatically closed

 An icon is a picture  It is typically, but not always, a small picture  An icon can be stored in a file of many different standard formats  Such as. gif,. tiff, or. jpg  The class ImageIcon is used to convert a picture file to a Swing icon  Then it can be added as a component to any Container class, such as JApplet  The class ImageIcon is in the javax.swing package ImageIcon NameOfImageIcon = new ImageIcon("PictureFileName");

 The easiest way to display an icon in an applet is to place it in a JLabel  The following three lines create a label, create an icon, and then add the icon to the label : JLabel aLabel=new JLabel("Welcome to my applet."); ImageIcon waveIcon = new ImageIcon("hand_waving.gif"); aLabel.setIcon(waveIcon);

 Java can also play sound files within the Applet class  play( ) method of the Applet class  Simplest way to retrieve and play a sound  Two forms  Codebase attribute  Indicates the filename of the applet’s main class file  getCodeBase( ) method AudioClip aClip = new AudioClip(getCodeBase(), "audio/event.au");

 An applet class is compiled in the same way as any other Java class  However, an applet is run differently from other Java programs  The normal way to run an applet is to embed it in an HTML document  The applet is then run and viewed through a Web browser

 HTML is used to be able to run an applet from a web site  HTML stands for Hypertext Markup Language  Hypertext is text viewed on a browser that contains clickable entries called links or hyperlinks  When a link or hyperlink is clicked, the document specified by the link is displayed

 When you create an applet  Write applet in Java  Save with. java file extension  Compile applet into bytecode using javac command  Write HTML document  Includes statement to call compiled Java class  Load HTML document into a Web browser  Or run Applet Viewer program

 Run applet from within HTML document  Three object tag attributes  code  Name of compiled applet  width  height

 Due to security restrictions, applets cannot access local files. How can an applet load resource files for image and audio?

 The java.net.URL class can be used to identify files (image, audio, text, etc.) on the Internet.  In general, a URL (Uniform Resource Locator) is a pointer to a “resource” on the World Wide Web on a local machine or a remote host.  A resource can be something as simple as a file or a directory.

 A URL is the name of an HTML document on the Web  URL is an acronym for Uniform Resource Locator  URLs often begin with http  This is the name of the protocol used to transfer and interpret the HTML document  Most browsers will fill in if it is omitted

 Text can be marked as a hyperlink so that if a user clicks that text, the browser goes to another Web page specified by the link TextToClick  The PathToDocument can be a full or relative path name to an HTML file, or a URL to any place on the Web  The TextToClick will be displayed and underlined by the browser

 A picture can also be inserted in an HTML document  The PathToPicture can be a full or relative path name to a file with a digitally encoded picture  Most commonly used picture-encoding formats are accepted, such as.gif,.tiff, and.jpg

Our Java class goals Click here for list of goals