Contents 8-1. Copyright (c) N. Afshartous

Similar documents
Framework. Set of cooperating classes/interfaces. Example: Swing package is framework for problem domain of GUI programming

Unit 1- Java Applets. Applet Programming. Local Applet and Remote Applet ** Applet and Application

Module 5 The Applet Class, Swings. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Module 5 Applets About Applets Hierarchy of Applet Life Cycle of an Applet

UNIT-2: CLASSES, INHERITANCE, EXCEPTIONS, APPLETS. To define a class, use the class keyword and the name of the class:

Applets as front-ends to server-side programming

UNIT -1 JAVA APPLETS

Introduction to Java Applets 12

Road Map. Introduction to Java Applets Review applets that ship with JDK Make our own simple applets

9. APPLETS AND APPLICATIONS

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 9: Writing Java Applets. Introduction

SIMPLE APPLET PROGRAM

PROGRAMMING LANGUAGE 2

An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a

Java Applets / Flash

Java History. Java History (cont'd)

Object Oriented Programming Concepts-15CS45

OBJECT ORIENTED PROGRAMMING. Course 8 Loredana STANCIU Room B613

SNS COLLEGE OF ENGINEERING, Coimbatore

Java Applet & its life Cycle. By Iqtidar Ali

MULTIMEDIA PROGRAMMING IN JAVA. Prof.Asoc. Alda Kika Department of Informatics Faculty of Natural Sciences University of Tirana

Java Applets. Last Time. Java Applets. Java Applets. First Java Applet. Java Applets. v We created our first Java application

CSC System Development with Java Introduction to Java Applets Budditha Hettige

Chapter 7 Applets. Answers

Module 5 The Applet Class, Swings. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Module 5 The Applet Class, Swings. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

An applet is called from within an HTML script with the APPLET tag, such as: <applet code="test.class" width=200 height=300></applet>

(Refer Slide Time: 02:01)

Lecture Static Methods and Variables. Static Methods

Java Applet Basics. Life cycle of an applet:

CS 209 Programming in Java #12 JAR Files: Creation and Use

CSD Univ. of Crete Fall Java Applets

Overview. Applets. A Java GUI inside your browser! Important methods Drawing images Playing audio Getting input parameters Double buffering

Outline. Introduction to Java. What Is Java? History. Java 2 Platform. Java 2 Platform Standard Edition. Introduction Java 2 Platform

CS2 Advanced Programming in Java note 8

CORBA Java. Java. Java. . Java CORBA. Java CORBA (RMI) CORBA ORB. . CORBA. CORBA Java

Chapter 3 - Introduction to Java Applets

CS335 Graphics and Multimedia

Prashanth Kumar K(Head-Dept of Computers)


Today. cisc3120-fall2012-parsons-lectiv.2 2

Lecture Static Methods and Variables. Static Methods

Page 1 of 7. public class EmployeeAryAppletEx extends JApplet

SELF-STUDY. Glossary

CT 229 Arrays in Java

G51PRG: Introduction to Programming Second semester Applets and graphics

Outline. Announcements. Feedback. CS1007: Object Oriented Design and Programming in Java. Java beans Applets

Java TM Applets. Rex Jaeschke

CS1004: Intro to CS in Java, Spring 2005

1. What is Jav a? simple

Summary. 962 Chapter 23 Applets and Java Web Start

Comp Intermediate Programming EXAM #2 April 02, 2003 Rice University - Instructors: Cox & Nguyen

Introduction to Java

S.E (Computer ) (Second Semester) EXAMINATION, Time : Two Hours Maximum Marks : 50

From C++ to Java. Duke CPS

Introduction to the Java T M Language

Advanced Internet Programming CSY3020

Chapter 13. Applets and HTML. HTML Applets. Chapter 13 Java: an Introduction to Computer Science & Programming - Walter Savitch 1

A socket is a software endpoint that establishes bidirectional communication between a server program and one or more client programs.

Dynamic code downloading using Java TM (Using the java.rmi.server.codebase Property)

Programming In Java Prof. Debasis Samanta Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

ASSIGNMENT NO 14. Objectives: To learn and demonstrated use of applet and swing components

Graphics Applets. By Mr. Dave Clausen

JAVA. Object Oriented Programming with. M.T. Somashekara D.S.Guru K.S. Manjunatha

PESIT Bangalore South Campus

The init() Method. Browser Calling Applet Methods

Chapter 12 Advanced GUIs and Graphics

EE219 Object Oriented Programming I (2005/2006) SEMESTER 1 SOLUTIONS

Shared Collection of Java Course Materials: New Topics Covered. Agenda

G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY

Java Programming Unit 6. Inner Classes. Intro to Apples. Installing Apache Tomcat Server.

Java 1.8 Programming

Author: Arvind Bansal Chapman Hall / CRC Press ISBN:

CSC 551: Web Programming. Fall 2001

TWO-DIMENSIONAL FIGURES

The Servlet Life Cycle

Framework. Set of cooperating classes/interfaces. Example: Swing package is framework for problem domain of GUI programming

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

Ji Gong. Freedom vs. FUD. Julien Gouesse Sven Gothel Xerxes Ranby

GUI, Events and Applets from Applications, Part III

Lecture 1: Overview of Java

Web Development & Design Foundations with HTML5, 8 th Edition Instructor Materials Chapter 11 Test Bank

Syllabus & Curriculum for Certificate Course in Java. CALL: , for Queries

Using the API: Introductory Graphics Java Programming 1 Lesson 8

Methods (Deitel chapter 6)

Methods (Deitel chapter 6)

CSC 1214: Object-Oriented Programming

Java Applets, etc. Instructor: Dmitri A. Gusev. Fall Lecture 25, December 5, CS 502: Computers and Communications Technology

Programmierpraktikum

Graphics Applets. By Mr. Dave Clausen

CS 3331 Advanced Object-Oriented Programming Exam 1

B2.52-R3: INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING THROUGH JAVA

Goals. Java - An Introduction. Java is Compiled and Interpreted. Architecture Neutral & Portable. Compiled Languages. Introduction to Java

Chapter 14: Applets and More

EE219 - Semester /2009 Solutions Page 1 of 10

Understanding How Java Programs Work

Higher National Diploma in Information Technology First Year, Second Semester Examination 2015

Graphics -- To be discussed

Programming graphics

DIFFERENCE BETWEEN APPLET AND APPLICATION

Transcription:

Contents 1. Classes and Objects 2. Inheritance 3. Interfaces 4. Exceptions and Error Handling 5. Intro to Concurrency 6. Concurrency in Java 7. Graphics and Animation 8. Applets 8-1

Chapter 8: Applets After this chapter you will be able to: - Create applets - Read data embedded in HTML into applets 8-2

Creating An Applet Create a subclass of class Applet import java.applet.applet; import java.awt.graphics; public class HelloApplet extends Applet { public void paint (Graphics g) { g.drawstring("this is an Applet", 10, 10); } } and a HTML file containing an applet tag <applet code=helloapplet width=200 height=200> </applet> 8-3

Running An Applet TM Open the HTML file using a Java enabled web browser or the JDK s appletviewer The.class file will be executed when the HTML file loads 8-4

Applet Tag Attributes Required attributes: code: specifies the bytecode (.class) file width: specifies the width of the applet s output area on the web page height: specifies the height of the applet s output area on the web page <applet code=helloapplet width=200 height=200> </applet> 8-5

Applet Tag Attributes 8-6 Optional attributes: align: specifies the alignment of the applet s area on the web page vspace: specifies the spacing (in pixels) above and below the applet s area hspace: specifies the spacing (in pixels) on either side of the applet s area codebase: specifies the directory location of the.class file relative to the directory of the HTML file name: specifies a name that can be used for inter-applet communication

Applet Methods Can override the following methods: init is automatically called once public void init (); start is automatically called after init, and then whenever a user returns to the applet s web page after moving off public void start (); 8-7

Applet Methods stop is called automatically when a user moves off the applet s web page public void stop (); destroy is called automatically when the user exits the browser public void destroy (); paint is called automatically for drawing/redrawing public void paint (Graphics g); 8-8

Passing Data To Applets Can embed data in applet tag with one or more param tags: <applet code=helloapplet width=200 height=200> <param name=message1 value= hello there > <param name=message2 value= bonjour > <param name=message3 value= ni how > </applet> the applet can retrive the value part by calling getparameter to lookup by passing the name part public String getparameter (String name); 8-9

Example init reads in the messages import java.applet.*; import java.awt.*; public class GreetingApplet extends Applet { String [] messages; 8-10 } public void init () { int count = 0; // count the # of messages while (getparameter("message" + (count+1))!= null) count++; messages = new String[count]; // allocate array for (int i = 0; i < count; i++) messages[i] = getparameter("message" + (i + 1)); }...

Output Messages paint outputs the messages import java.applet.*; import java.awt.*; public class GreetingApplet extends Applet { String [] messages; } public void init () {...} public void paint (Graphics g) { for (int i = 0; i < messages.length; i++) g.drawstring(messages[i], 10, 10*(i+1)); } 8-11

AppletContext An applet can interact with the browser environment via an object which supports the AppletContext interface An applet can get it s context object by calling Applet.getAppletContext public AppletContext getappletcontext(); 8-12

Interface AppletContext An applet can call the methods below after getting it s context public interface java.applet.appletcontext { public Applet getapplet(string name); public Enumeration getapplets(); public AudioClip getaudioclip(url url); public Image getimage(url url); public void showdocument(url url); public void showdocument(url url, String target); public void showstatus(string status); } 8-13

AppletContext Methods getapplet retrieves an applet object using the name attribute of the Applet HTML tag. Can have multiple applets on the same web page. public Applet getapplet(string name); getapplets Returns an Enumeration containing all the applets on the current web page public Enumeration getapplets(); 8-14

Interface Enumeration An object supporting the Enumeration interface supports iteration through a list public interface java.util.enumeration { public boolean hasmoreelements(); public Object nextelement(); } Processing all the applets AppletContext ac = getappletcontext(); Enumeration e = ac.getapplets(); while (e.hasmoreelements()) { Applet a = (Applet) e.nextelement(); // process applet } 8-15

Playing Sound AppletContext.getAudioClip returns an AudioClip object using specified url public AudioClip getaudioclip(url url); Interface AudioClip public interface java.applet.audioclip { public void loop(); // play clip continuously public void play(); // play clip once public void stop(); // stop playing } 8-16

AppletContext Methods getimage returns an Image object corresponding to the specified url public Image getimage(url url); showdocument requests the browser to display a new web page using the specified url public void showdocument(url url); target can be specified in multi-frame applets public void showdocument(url url, String target); 8-17

Displaying Messages showstatus displays a message in the status area at the bottom of the browser window public void showstatus(string status); 8-18

Security Issues Java provides several levels of security safe language: no pointers (as in C/C++) makes it harder to write viruses bytecode verification: the virtual machine verifies bytecode before execution custom security (initial release JDK 1.1) Using class SecurityManager can implement a custom security policy to grant/deny requests for resources package java.security supports digital signatures encryption 8-19

Conclusions/Predictions Security is an important area for Java applications Look for package java.security to evolve over time with new features Java will become the language of choice for developing secure applications 8-20

It s Graduation Time Congratulations!! 8-21