Introduction to Java 2 Programming Lecture 10 Applets.

Slides:



Advertisements
Similar presentations
1 Applets Programming Enabling Application Delivery Via the Web.
Advertisements

Learn about Java applets. Know the differences between Java applets and applications. Designing and using Java applets Running Java applets. Security.
20 Maart 2006ISS - Internet Applications Part 21 Internet Applications part 2 René de Vries Based on slides by M.L. Liu and Marko van Eekelen.
Dept. of Computer Science - SSBN Java Applets Vishnuvardhan.M.
Java Applets:. How Applets differ from application?: They do not use main method but init(), start() and paint() methods of the applet class They can.
Applet Security Gunjan Vohra. What is Applet Security? One of the most important features of Java is its security model. It allows untrusted code, such.
Client Side Programming Using Java Applet Outcomes: You will be expected to know: – Java Applets and HTML file; –bytecode and platform independent programs;
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
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.
18-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.
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.
Java Applets. Lecture Objectives Learn about Java applets. Know the differences between Java applets and applications. Designing and using Java applets.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 14 Applets, Images,
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.
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.
EE2E1. JAVA Programming Lecture 10 Applets. Contents Introduction Introduction Web-servers and clients Web-servers and clients A simple example “Hello.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L05 (Chapter 16) Applets.
COMPUTER TERMS PART 1. COOKIE A cookie is a small amount of data generated by a website and saved by your web browser. Its purpose is to remember information.
Applets  The Applet Class  The HTML Tag F Passing Parameters to Applets.
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.
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.
JAPPLET.
Applets Life Cycle Drawing and Event Handling Methods for UI Components Applet Capabilities Example.
Introduction to Applets CS 3505 Client Side Scripting with applets.
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.
Java Applets. 2 Introduction to Java Applet Programs  Applications are stand alone programs executed with Java interpreter executed with Java interpreter.
Chapter 8 Introduction to HTML and Applets Fundamentals of Java.
24.1Introduction Java Powerful, object-oriented language Fun to use for beginners, appropriate for experience programmers Language of choice for Internet.
Java Applets. 2 Introduction to Java Applet Programs Applications are ___________________ programs –executed with Java interpreter Applet is a small program.
Java Applets 1. What is an applet? An applet is a small Java program that is typically embedded in a Web page and can be run using the applet viewer or.
CSC 205 – Java Programming II Applet. Types of Java Programs Applets Applications Console applications Graphics applications Applications are stand-alone.
Pravin Yannawar, DOCS, NMU Jalgaon Basic Java : Applets 2 Objectives of This Session Identify the need for Applets Distinguish between Applets and Applications.
CS 7: Introduction to Computer Programming Java and the Internet Sections ,2.1.
Java the UML Way version Only to be used in connection with the book "Java the UML Way", by Else Lervik and.
Chapter 16: Networking F Client/Server Communications F Serving Multiple Clients F Applet Clients F Viewing HTML Pages F Retrieving Files from Web Servers.
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.
Chapter 4 Applets Cop Why Applets? WWW makes huge information available to anyone with web browser. Web server send web pages and images to your.
1 Applets are small applications that are accessed on an Internet server, transported over the internet, automatically installed and run as a part of web.
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.
Applets, Images, and Audio Chapter 14 CSCI CSCI 1302 – Applets, Images, and Audio2 Outline Introduction The Applet Class –The init Method –The start.
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.
CSI 3125, Preliminaries, page 1 Applet. CSI 3125, Preliminaries, page 2 Applet An applet is a Java program that runs in a Web browser. An applet can be.
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.
CHAPTER Agenda Applets Servelets Browsers HelloWorld.
HTML Overview Part 8 – Java Applets 1. Applets 2  A Java applet is a small application embedded in your HTML document which runs in the browser window.
1 Java Applet Basics Chapter Eight. 2 Applets vs. Applications l Applications: Stand alone Java programs run by interpreter l Applets WWW browser embedded.
Client-Server applications Introduction to Java Applets Client-server architectures Why do Applets exist? What can an Applet do?
1 Applets Programming. Introduction Java programs are divided into two main categories, applets and applications. An application is an ordinary Java program.
CS202 Java Object Oriented Programming GUI Programming – Applets Chengyu Sun California State University, Los Angeles.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 17 : Applets King Fahd University of Petroleum & Minerals College of Computer Science.
Applications Active Web Documents Active Web Documents.
Java Applets.
30 Java Applets.
Distributed Computing, M. L. Liu
Distributed Computing, M. L. Liu
UNIT-5.
Introduction to Computing Using Java
Java Applets.
Introduction to Applet, Application and JDK
Java applets 1/3/2019.
Applet in Java.
Java Programming COMP-417 Applet
Applet Fundamentals Applet are small applications that are accessed on an Internet server, transported over the Internet, automatically installed and run.
11.1 Applets & graphics.
JAVA APPLET PREPARED BY Mr. Jahanzaib Ahmed
Enabling Application Delivery Via the Web
Presentation transcript:

Introduction to Java 2 Programming Lecture 10 Applets

Overview Introduction to Applets –The Rules for Applets –The Applet Lifecycle Writing Applets –Creating applets –Deploying applets Examples: Interacting with the browser –Parameters –Displaying status messages –Showing documents

Introduction to Applets Applets are applications that are deployed over the Internet –Designed to run inside a browser –Are embedded in HTML pages –Core part of Java Not are popular as they were (or forecasted to be) –Patchy browser support –Can be slow to download –Macromedia Flash, etc. offer similar functionality

Introduction to Applets But do provides a number of benefits… Easy to deploy (web components) No need for installation or upgrades Provide more sophisticated functionality than a web page/form Allow for proprietary client-server protocols Re-use code from traditional applications Very secure

The Rules for Applets An applet cannot (usually) do the following: Cannot load libraries or define native methods Cannot read or write files on the client Cannot make network connections except to the server it came from Cannot start any program on the client Cannot read certain system properties Cannot pretend to be a local application –Applet windows look different

The Rules for Applets Ensures that an applet cannot damage the client –Otherwise opens potential for viruses, security breaches, trojan horses, etc –Applets are considered to be untrusted code Rules are enforced by a Security Manager –Installed by the JVM in the browser The rules are known as a security policy Alternate policies can be used on request –But only if the user decides to trust the code

The Applet Lifecycle Applets are loaded, started and managed by the browser Browser is a container that provides services to the applet –Similar to Robots in the Robocode arena Browser drives the applet through life-cycle methods –The methods mark milestones in the applet life –Instruct it to carry out some basic operations –Form a contract between the browser and the applet (Aside: this is a common pattern used in many Java frameworks in various forms)

The Applet Lifecycle Four basic lifecycle methods –Defaults provided by java.applet.Applet init() – Initialises the applet when (re-)loaded –Perform initialisation here rather than constructor –Guarantees complete environment is available (e.g. parameters) start() – Starts the applet running, after loading or user revisits page stop() – Stops the applet running, when user leaves page or quits destroy() – Perform final clean-up before its unloaded

The Applet Lifecycle

Writing Applets Writing applet involves creating a sub-class of –java.applet.Applet, or –javax.swing.JApplet (recommended) Remember, JApplet is a top-level Swing container –can add usual Swing components Applet base class provides a number of useful methods Applets also have a context object, that provides other functionality –E.g. driving the browser, communicating with other applets

Writing Applets

Useful Methods getParameter() – get a parameter set in the web page showStatus() – show a message in the status bar getImage() – load an image getAudioClip(), play() – play a sound file getAppletContext() – get context object getAppletContext().showDocument() – instruct the browser to show another webpage

Writing Applets Tip for development/debugging: –Use the appletviewer tool for viewing and testing applets –Easier to control than in a browser –Avoids problems with caching of applets Example…A Basic Applet

Deploying Applets Applets are embedded into web pages with the tag –Instructs the browser to display an applet in that location of the web page The applet tag can be used to set several properties about the applet –the class to load and run as an applet –height and width –Location of class files (codebase)

Deploying Applets <applet name=MyApplet code=AppletSubclass.class width=anInt height=anInt codebase= <param name=parameter1Name value=aValue/> <param name=parameter2Name value=anotherValue/> Your browser is not Java enabled!

Deploying Applets The Basic Applet <applet code="intro2java.applet.BasicApplet.class" width="100" height="100">

Writing Applets Beware of CLASSPATH! –Applets classes are loaded from the same directory as the HTML page –Unless an alternate directory is set with the codebase attribute

Examples The Hello World Applet Interacting with the browser 1.Getting parameters 2.Showing a status message 3.Showing other web pages 4.The Calculator as an applet