Java Applet.

Slides:



Advertisements
Similar presentations
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.
Advertisements

LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class.
Java Applet & JavaScript SNU OOPSLA Lab. October 2005.
Client Side Programming Using Java Applet Outcomes: You will be expected to know: – Java Applets and HTML file; –bytecode and platform independent programs;
Applets The objectives of this chapter are: To describe applets and their purpose To discuss embedding applets in HTML pages.
Programming and Problem Solving With Java Copyright 1999, James M. Slack Applets What is an Applet? Applet Parameters Graphics in Applets Other Applet.
got ? Research Project – April 1998 Hang Xia, Mark Wang, Richard S. Chang Updated: R Norman, August 1999.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Lecture 24 Applets. Introduction to Applets Applets should NOT have main method but rather init, stop, paint etc They should be run through javac compiler.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 - Introduction to Java Applets Outline 3.1 Introduction 3.2 Sample Applets from the Java 2.
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.
Applets, Graphical User Interfaces, and Threads / Chapter 9 1 Applets, Graphical User Interfaces, and Threads.
Java Applets. Road Map Introduction to Java Applets Review applets that ship with JDK Make our own simple applets –Introduce inheritance –Introduce the.
Applets. An applet is a Panel that allows interaction with a Java program A applet is typically embedded in a Web page and can be run from a browser You.
26-Jun-15 Applets. 2 An applet is a Panel that allows interaction with a Java program A applet is typically embedded in a Web page and can be run from.
A Simple Applet. Applets and applications An applet is a Java program that runs on a web page –Applets can be run from: Internet Explorer Netscape Navigator.
EE2E1. JAVA Programming Lecture 10 Applets. Contents Introduction Introduction Web-servers and clients Web-servers and clients A simple example “Hello.
Program Design With Methods And Graphics / Chapter 4 1 Abstract Window Toolkit.
The tag The complete syntax of the tag is as follows( code, width and height are required and others optional)
Java Programming, 2E Introductory Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Java Applets What is an Applet? How do you create.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
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.
COP 4331 – OOD&P Lecture 6. Review Midterm Review Complete sample application –See SwingColorTest.java.
Java Applets. An applet is a Panel that allows interaction with a Java program. A applet is typically embedded in a Web page and can be run from a browser.
Applets Applet is java program that can be embedded into HTML pages. Java applets runs on the java enabled web browsers such as mozilla and internet explorer.
Introduction to Java Applets Sangeetha Parthasarathy 05/21/2001.
1 CSC Computer Education (P) Ltd. DESIGNED BY K PRAKASH,
Lec.10 + (Chapter 8 & 9) GUI Java Applet Jiang (Jen) ZHENG July 6 th, 2005.
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.
Pravin Yannawar, DOCS, NMU Jalgaon Basic Java : Applets 2 Objectives of This Session Identify the need for Applets Distinguish between Applets and Applications.
Program that runs in appletviewer (test utility for applets) Web browser (IE, Communicator) Executes when HTML (Hypertext Markup Language) document containing.
Java applets. Outline What is Java? Java Applications Java Applets Java Applets Securities Summary.
APPLET. 2 Introduction to Java Applet Programs Applications are stand alone programs ◦ executed with Java interpreter Applet is a small program ◦ can.
Java Applet. Introductions Applet is java program that can be embedded into HTML pages Java applets runs on the java enables web browsers such as mozila.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
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 A Simple Applet. 2 Applets and applications An applet is a Java program that runs on a web page Applets can be run within any modern browser To run.
CSI 3125, Preliminaries, page 1 Applet. CSI 3125, Preliminaries, page 2 Graphics Methods public abstract void drawString(String str, int x, int y): is.
Creating a Java Application and Applet
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.
1 Java Applet Basics Chapter Eight. 2 Applets vs. Applications l Applications: Stand alone Java programs run by interpreter l Applets WWW browser embedded.
1 Applets Programming. Introduction Java programs are divided into two main categories, applets and applications. An application is an ordinary Java program.
Applet: An applet is a java program that is transmitted over the network from the server to client & executed within clients browser. Applets are used.
Applications Active Web Documents Active Web Documents.
Lecture 09 Applets.
Object Oriented Programming
JAVA Applets Pavan D.M..
JAVA Applets Pavan D.M..
Applets In Java Visit for more Learning Resources 1.
Java Applets.
Distributed Computing, M. L. Liu
Distributed Computing, M. L. Liu
Applets.
UNIT-5.
Java Applets.
Introduction to Applet, Application and JDK
Java applets 1/3/2019.
APPLETS.
Applet in Java.
Java Programming COMP-417 Applet
11.1 Applets & graphics.
Handout-14 Applets and Graphics
JAVA APPLET PREPARED BY Mr. Jahanzaib Ahmed
Enabling Application Delivery Via the Web
G6DICP - Lecture 27 Java Applets.
APPLET PROGRAMMING.
Presentation transcript:

Java Applet

Introductions Applet is java program that can be embedded into HTML pages Java applets runs on the java enables web browsers such as mozila and internet explorer. Applet is designed to run remotely on the client browser, so there are some restrictions on it. Applet can't access system resources on the local computer. Applets are used to make the web site more dynamic and entertaining.

Advantages of Applet * Applets are cross platform and can run on Windows, Mac OS and Linux platform * Applets can work all the version of Java Plugin * Applets runs in a sandbox, so the user does not need to trust the code, so it can work without security approval * Applets are supported by most web browsers * Applets are cached in most web browsers, so will be quick to load when returning to a web page * User can also have full access to the machine if user allows

Disadvantages of Java Applet * Java plug-in is required to run applet * Java applet requires JVM so first time it takes significant startup time * If applet is not already cached in the machine, it will be downloaded from internet and will take time * Its difficult to desing and build good user interface in applets compared to HTML technology

The Applet class To create an applet, you must import the Applet class This class is in the java.applet package The Applet class contains code that works with a browser to create a display window Capitalization matters! applet and Applet are different names

Importing the Applet class Here is the directive that you need: import java.applet.Applet; import is a keyword java.applet is the name of the package A dot ( . ) separates the package from the class Applet is the name of the class There is a semicolon ( ; ) at the end

Applet versus Application Applets are small programs while applications are larger programs. Applets don't have the main method while in an application execution starts with the main method. Applets can run in our browser's window or in an appletviewer. To run the applet in an appletviewer will be an advantage for debugging. Applets are designed for the client site programming purpose while the applications don't have such type of criteria.

The Life cycle of An Applet init(): This method is called to initialized an applet start(): This method is called after the initialization of the applet. stop(): This method can be called multiple times in the life cycle of an Applet. destroy(): This method is called only once in the life cycle of the applet when applet is destroyed.

The Life cycle of An Applet import java.awt.*; import java.applet.*; class Myclass extends Applet{ public void init(){} Publicvoidstart(){} public void stop() {} public void destroy() {} public void paint(Graphics g) {}

Applet Tag [<] APPLET [CODEBASE = codebaseURL] CODE = appletFile [ALT = alternateText] [NAME = appletInstanceName] WIDTH = pixels HEIGHT = pixels [ALIGN = alignment] [VSPACE = pixels] [HSPACE = pixels] > [< PARAM NAME = appletParameter1 VALUE = value >] [< PARAM NAME = appletParameter2 VALUE = value >] . . [alternateHTML] [</]APPLET[>]

Creating First Applet Example import java.applet.*; import java.awt.*; public class FirstApplet extends Applet{ public void paint(Graphics g){ g.drawString("Welcome in Java Applet.",40,20); }

HTML code <HTML> <HEAD> </HEAD> <BODY> <APPLET ALIGN="CENTER" CODE="FirstApplet.class" WIDTH="800" HEIGHT="500"></APPLET> </BODY> </HTML>

Drawing Shapes Example in java Graphics.drawLine() : to draw the line in the applet. drawLine(int X_from_coordinate, int Y_from_coordinate, int X_to_coordinate, int Y_to_coordinate); Graphics.drawString() : draws the given string as the parameter drawString(String string, int X_coordinate, int Y_coordinate); Graphics.drawOval() : draws the circle g.drawOval(int X_coordinate, int Y_coordinate, int Wdth, int height); Graphics.drawRect() : draws the rectangle. Here is the syntax of the drawRect() method : g.drawRect(int X_coordinate, int Y_coordinate, int Wdth, int height)

Drawing Shapes Example using color in java Graphics.setColor() : sets the color for the object by specified color. setColor(Color.color_name); Graphics.fillOval() : to fill the color inside the oval by specified color g.fillColor(Color.color_name); Graphics.fillRect() :to fill the color inside the rectangle by specified color g.fillRect(int X_coordinate, int Y_coordinate, int Wdth, int height)

Passing Parameter in Java Applet The param tag(<parma name="" value=""></param>) is used to pass the parameters to an applet To access values String strParameter = this.getParameter("Message");

Event Listeners Example To handle the events generated by these buttons you add action listeners e.g. object_name.addActionListener(this);. When the action event occurs, that object's actionPerformed method is invoked. actionPerformed(ActionEvent e)

Display image paint(Graphics g) has used MediaTracker is a utility class that tracks the status of a number of media objects img - image name type of Image. x - lower X - Coordinate type of int. y - lower Y - Coordinate type of int. x1 - upper X - Coordinate type of int. y1 - upper Y - Coordinate type of int.