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

Similar documents
SIMPLE APPLET PROGRAM

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 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 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 Applet & its life Cycle. By Iqtidar Ali

Object Oriented Programming Concepts-15CS45

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

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

OBJECT ORIENTED PROGRAMMING. Course 8 Loredana STANCIU Room B613

9. APPLETS AND APPLICATIONS

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

Introduction to Java Applets 12

CSC System Development with Java Introduction to Java Applets Budditha Hettige

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

Java Applet Basics. Life cycle of an applet:

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

G51PRG: Introduction to Programming Second semester Applets and graphics

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

Chapter 7 Applets. Answers

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

UNIT -1 JAVA APPLETS

Programmierpraktikum

MYcsvtu Notes. Java Programming Lab Manual

PESIT Bangalore South Campus

SNS COLLEGE OF ENGINEERING, Coimbatore

CSD Univ. of Crete Fall Java Applets

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

Java TM Applets. Rex Jaeschke

PROGRAMMING LANGUAGE 2

Introduction to the Java T M Language

Chapter 3 - Introduction to Java Applets

Java Applets / Flash

CT 229 Arrays in Java

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


CS2 Advanced Programming in Java note 8

Lecture Static Methods and Variables. Static Methods

Applets as front-ends to server-side programming

Prashanth Kumar K(Head-Dept of Computers)

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

(Refer Slide Time: 02:01)

Chapter 12 Advanced GUIs and Graphics

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

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

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

Programming: You will have 6 files all need to be located in the dir. named PA4:

Methods (Deitel chapter 6)

Methods (Deitel chapter 6)

Question 1. Show the steps that are involved in sorting the string SORTME using the quicksort algorithm given below.

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

Introduction to Computer Science I

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

NITI NITI I PRIORITET

Chapter 5 - Methods Prentice Hall, Inc. All rights reserved.

OOP Assignment V. For example, the scrolling text (moving banner) problem without a thread looks like:

Advance Programming. BCA Fifth Semester. Purbanchal University. sarojpandey.com.np Page 1 of 101

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

OBJECT ORIENTED PROGRAMMING TYm. Allotted : 3 Hours Full Marks: 70


Advanced Internet Programming CSY3020

Java History. Java History (cont'd)

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

Java - Applets. public class Buttons extends Applet implements ActionListener

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

CS1004: Intro to CS in Java, Spring 2005

Lecture Static Methods and Variables. Static Methods

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Information Science and Engineering

MODULE 8p - Applets - Trials B

CS 3331 Advanced Object-Oriented Programming Exam 1

Understanding How Java Programs Work

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

Java Certification Mock Exam

IT101. Graphical User Interface

Graphics Applets. By Mr. Dave Clausen

Chapter 14: Applets and More

8/23/2014. Chapter Topics. Introduction to Applets. Introduction to Applets. Introduction to Applets. Applet Limitations. Chapter 14: Applets and More

CSC 1214: Object-Oriented Programming

Chapter 14: Applets and More

Using the API: Introductory Graphics Java Programming 1 Lesson 8

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

Java - Applets. C&G criteria: 1.2.2, 1.2.3, 1.2.4, 1.3.4, 1.2.4, 1.3.4, 1.3.5, 2.2.5, 2.4.5, 5.1.2, 5.2.1,

Graphics Applets. By Mr. Dave Clausen

G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY

Hosur road, 1km before Electronic City, Bengaluru Date : 4/10/17 Max Marks : 50. Subject & Code : JAVA and J2EE (10CS753) Section : A,B,C

Chapter 2 Using Objects. Types. Number Literals. A type defines a set of values and the operations that can be carried out on the values Examples:

Java - Dates and Threads

Core JAVA Training Syllabus FEE: RS. 8000/-

Interfaces. Interfaces. Implementing Interfaces. Interfaces : : : :

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

The init() Method. Browser Calling Applet Methods

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

CSC 551: Web Programming. Fall 2001

User interfaces and Swing

Definition: A thread is a single sequential flow of control within a program.

Page 1 of 7. public class EmployeeAryAppletEx extends JApplet

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 OOP THROUGH JAVA (Common to CT, CM and IF)

CSC 551: Web Programming. Fall 2001

S.E. Sem. III [CMPN] Object Oriented Programming Methodology

Transcription:

About Applets Module 5 Applets An applet is a little application. Prior to the World Wide Web, the built-in writing and drawing programs that came with Windows were sometimes called "applets." On the Web, using Java, the object-oriented programming language, an applet is a small program that can be sent along with a Web page to a user. Java applets can perform interactive animations, immediate calculations, or other simple tasks without having to send a user request back to the server. Hierarchy of Applet Life Cycle of an Applet The life cycle of an Applet is as given below 1. init( ): This is the first method to be called. The variables required to run Applet are initialized inside this method. This method will be called only once during the runtime of the Applet. 2. start( ): This method is called after init( ). This method will be called every time Applet is restarted. Example, if user leaves web browser and comes back later, start( ) method will be loaded again.

3. paint( ): This method is called each time applet s output must be redrawn. Example, if user minimizes web browser and maximize it later. 4. stop( ): This method is called when web browser leaves the web page that contains the applet. When stop( ) is called, the applet is not terminated, its still running. It s like suspending the applet for a while. 5. destroy( ): This method is only called when the browser shuts down normally. Because applets are meant to live on an HTML page, you should not normally leave resources behind after a user leaves the page that contains the applet. An Applet Skeleton import java.awt.*; import java.applet.*; public class AppExample extends Applet{ public void init(){ // Do Initialization public void start(){ //Start or Resume Execution public void stop(){ //Suspends Execution public void destroy(){ //perform shutdown activities public void paint(graphics g){ //redisplay contents of window

Example 1: Sample Applet Application import javax.swing.japplet; import java.awt.graphics; public class MyApplet extends JApplet { public void paint(graphics g) { g.drawstring("my First Applet Program", 50, 25); Example 2: import java.applet.applet; import java.awt.*; public class MyApplet1 extends Applet { String msg; public void init(){ setbackground(color.blue); setforeground(color.white); msg = "INSIDE INIT() ---"; public void start(){ msg += "Inside Start() ---"; public void paint(graphics g){ msg += "INSIDE PAINT() ---"; g.drawstring(msg, 30, 80);

showstatus("displaying Status Window"); repaint( ) This method is used to redraw the output window. When this method is called, it in turn calls update( ) method of Component class that in turn calls the paint( ) method of the program to redraw the output window. There are four versions of repaint( ) method, they are 1. void repaint( ) // Repaints the entire window 2. void repaint(int left, int top, int width, int height) where, left & top coordinates from the upper left top corner width & height region to be repainted 3. void repaint(long maxdelay) 4. void repaint(long maxdelay, int left, int top, int width, int height) where, maxdelay time in milliseconds should be elapsed before calling update( ) method. Below program demonstrates the working of repaint method /* AppletRepaint.java */ import java.awt.*; import java.applet.*; public class AppletRepaint extends Applet implements Runnable { String msg = " A Running Banner "; Thread t = null;

int state; boolean stopflag; public void init() { setbackground(color.blue); setforeground(color.white); public void start(){ t = new Thread(this); stopflag = false; t.start(); public void run(){ char ch; for(;;){ try{ repaint(); Thread.sleep(5000); ch = msg.charat(0); msg = msg.substring(1, msg.length()); msg += ch; if(stopflag) break; catch(interruptedexception e){ public void stop(){ stopflag = true; t = null; public void paint(graphics g){ g.drawstring(msg, 50, 30);

Status Window It is used to display information at status bar. Prototype: showstatus( Message to be displayed ); The HTML Applet Tag <APPLET The below applet tag is used by Appletviewer and HTML to execute applets. Appletviewer executes the applets in new window, whereas HTML allows multiple applets to run in same window. Syntax: [CODEBASE = codebaseurl] CODE = appletfile [ALT = alternatetext] [NAME = appletinstancename] WIDTH = pixels HEIGHT = pixels [ALIGN = alignment] [VSPACE = pixels][hspace = pixels] >

[PARAM NAME = AttributeName VALUE = AttributeValue] [PARAM NAME = AttributeName VALUE = AttributeValue]. </APPLET> The attributes in square brackets are optional. CODEBASE: It is the path of the directory that will be searched for the applets executable class file i.e. specified by the CODE tag. CODE: It is the name of the applet compiled file to be run in browser. ALT: Alternate text is displayed when browser can t run applets. NAME: Name given to applet. Naming applet helps in identifying and communicating with other applets in same page. WIDTH and HEIGHT: Specifies the size of applets display area. ALIGN: Specifies the alignment of the applet. VSPACE and HSPACE: VSPACE specifies the space above and below the applet. HSPACE specifies the space left and right of the applet. Both, space are in pixels. PARAM NAME and VALUE: This tag allows passing parameter to applets in HTML page. The applets access this parameters using getparameter( ) method. getdocumentbase( ) and getcodebase( ) Displays the path of directory that holds the path of the HTML file that has started the applet (getdocumentbase). Displays the path of the applets class file from where the applet is loaded (getcodebase). Below Program demonstrates DocumentBase and CodeBase. import java.awt.*; import java.applet.applet; import java.net.*; public class getcodedoc extends Applet { public void paint(graphics g){ String msg; URL url = getcodebase(); msg = "Code Base:" + url.tostring(); g.drawstring(msg, 10, 40);

Output: url = getdocumentbase(); msg = "Document Base:" + url.tostring(); g.drawstring(msg, 10, 60);