Introduction to Java Applets Sangeetha Parthasarathy 05/21/2001.

Slides:



Advertisements
Similar presentations
Client Side Programming Using Java Applet Outcomes: You will be expected to know: – Java Applets and HTML file; –bytecode and platform independent programs;
Advertisements

Java Applets A First Program. Applet Example /* The world’s simplest program, repeated once more in another format in an attempt to turn all of you into.
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.
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.
 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.
1 Introduction to Applets Overview l What is an Applet? l Steps for creating an applet l What is HTML? l Basic HTML tags l Drawing Simple Graphical shapes.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 16 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.
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.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 14 Applets, Images,
Chapter 3 - Introduction to Java Applets Outline 3.1Introduction 3.2Thinking About Objects 3.4A Simple Java Applet: Drawing a String 3.5Two More Simple.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved COS240 Object-Oriented Languages.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Object Oriented Programming (OOP) LAB # 5 TA. Maram & TA. Mubaraka TA. Kholood & TA. Aamal.
Program Design With Methods And Graphics / Chapter 4 1 Abstract Window Toolkit.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L05 (Chapter 16) Applets.
 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.
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.
Computer Science [3] Java Programming II - Laboratory Course Lab 6: Introduction to Java Applets Sample Applets from the Java Simple Java Applet: Drawing.
 2002 Prentice Hall. All rights reserved. 1 Chapter 3 - Introduction to Java Applets Outline 3.1 Introduction 3.2 Sample Applets from the Java 2 Software.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Applets.
JAPPLET.
Java Applets. 2 Introduction to Java Applet Programs  Applications are stand alone programs executed with Java interpreter executed with Java interpreter.
OOP (Java): Simple/ OOP (Java) Objectives – –give some simple examples of Java applications and one applet 2. Simple Java Programs Semester.
1 A Simple Applet. 2 Applets and applications An application is an “ordinary” program Examples: Notepad, MS Word, Firefox, Halo, etc. An applet is a Java.
Chapter 3 Introduction to Java Applets 1 3 There is no main method in a Java Applet. A Java Applet can only run in a browser. An Applet is run.
Applets. What is an applet? Why create applets instead of applications? – Applets are Java programs that can be embedded in an HTML document – In contrast,
1 CSC Computer Education (P) Ltd. DESIGNED BY K PRAKASH,
Java Applets. 2 Introduction to Java Applet Programs Applications are ___________________ programs –executed with Java interpreter Applet is a small program.
2/4: Objects & Java Applets Objects: their nature –attributes & behaviors –inheritance Java Applets –what is an applet vs. an application? –where do applets.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved COS240 O-O Languages AUBG,
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 - Introduction to Java Applets Outline 3.1Introduction 3.2Thinking About Objects 3.3Sample.
Program that runs in appletviewer (test utility for applets) Web browser (IE, Communicator) Executes when HTML (Hypertext Markup Language) document containing.
APPLET. 2 Introduction to Java Applet Programs Applications are stand alone programs ◦ executed with Java interpreter Applet is a small program ◦ can.
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.
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.
Java 3 More Java Then Java. Libraries & Packages Java standard class library is composed of useful classes that help us to achieve our programming goals.
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.
2/4: Objects & Java Applets Objects: their nature –attributes & behaviors –inheritance –information hiding –classes: blueprints for objects Java Applets.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 - Introduction to Java Applets Will not cover Section 3.7 Thinking About Objects: Identifying.
1 Applets Programming. Introduction Java programs are divided into two main categories, applets and applications. An application is an ordinary Java program.
JAVA & J2EE Unit 2 Engineered for Tomorrow Prepared by Santhiya.M & Ganga V C Department OF Computer Science and Engineeering.
9/13: Objects & Java Applets Objects: their nature –attributes & behaviors –inheritance –information hiding –classes: blueprints for objects Java Applets.
Lecture 09 Applets.
Introduction to Java Applets
Java Applet.
Chapter 3 - Introduction to Java Applets
Java Applets.
Chapter 13: Advanced GUIs and Graphics
Distributed Computing, M. L. Liu
Distributed Computing, M. L. Liu
Java I.
UNIT-5.
Java Applets.
Java Applets.
Applet in Java.
Java Programming COMP-417 Applet
Applet 2019/4/23.
11.1 Applets & graphics.
Outline Character Strings Variables and Assignment
JAVA APPLET PREPARED BY Mr. Jahanzaib Ahmed
Advanced GUIs and Graphics
Presentation transcript:

Introduction to Java Applets Sangeetha Parthasarathy 05/21/2001

Object-Oriented Programming OOPS encapsulates data(attributes) and methods(behaviors) into packages called objects. Java programming tends to object –oriented. In java, the unit of programming is the class from which objects are eventually instantiated. Java programmers concentrate on creating user-defined types called classes. The class contains data and set of functions that manipulate the data. The programmer uses built-in types and other classes as building blocks for constructing new user-defined types.

The Java Applet An applet is an java code that can be inserted in a HTML document. The java code runs in a appletviewer – a test utility for applets to execute an applet. The appletviewer executes an applet when a HTML document containing the applet is opened in a browser. The appletviewer loads the HTML file, determines from the file which applet to load and begins the execution of the applet.

A Simple Java Applet import java.awt.*; import java.applet.Applet; public class welcomeApplet extends Applet { public void paint(Graphics g) { g.drawString("Welcome to Java Programming",25,25); }

1. Java contains many predefined pieces called classes or grouped into packages. The classes are included by using the statement import java.awt.Graphics; -Line1 import javax.swing.JApplet; - Line 2 The import statements tell the compiler where to locate the classes require to compile the java applet. Line 2 specifies that class Japplet is located in package javax.swing and class Graphics is located in the package java.awt. 2. Every Java applet is composed of atleast one class definition. You create your own class using pieces of existing class definition. Java uses inheritance to create new classes from existing class definitions.

3. The extends keyword followed by class name indicates the class from which our new class inherits existing pieces. 4. To inherit from existing classes, the programmer does not need to know every detail of the class and use every functions of the class, he uses only necessary functions. 5. The welcomeApplet that is inherited from JApplet uses the paint method of the class. 6. JApplet class consists start, init and paint. These function are automatically called when the applet begins the execution. These function contain nothing in the JApplet class. The programmer overrides this function with actions he wants. 7. The paint has been defined in the JApplet to receive a Graphics object which is in the package java.awt. The Graphics contains a set of function to print information on the screen.

8. The paint function prints the message on the screen. The syntax is g.drawString(“This is a message string”,25,25) – The function requires three parameters string, x- coordinate and y-coordinate. 9. The x-coordinate is equivalent as column and y- coordinate is the row equivalent. 10. The upper left-hand coordinates are 0,0.

Embedding the Applet in HTML Code The applet is inserted with the applet tag. The applet contains the width and height of the browser window where the applet is loaded. The default width and height is 0,0.

Running the appletviewer without.html or.htm does not load the applet in the browser. The applet tag has the code which specifies the class file to loaded. Placing additional characters such as commas between components in the tag may cause the appletviewer or browser to produce an error message. Forgeting an tag prevents the applet from loading into the browser.