Java Applets. 2 Introduction to Java Applet Programs  Applications are stand alone programs executed with Java interpreter executed with Java interpreter.

Slides:



Advertisements
Similar presentations
Lecture 2 Internet Computing Using Java Theophano Mitsa UMASS-Dartmouth.
Advertisements

Introduction To Java Objectives For Today â Introduction To Java â The Java Platform & The (JVM) Java Virtual Machine â Core Java (API) Application Programming.
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;
Java Applets A lab course by Dr. Junaid Ahmed Zubairi SUNY Fredonia.
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.
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.
Chapter 14 Applets. 2 Knowledge Goals Understand the differing roles of applications and applets Understand how a browser operates Understand the role.
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,
Problem Solving and Software Engineering Chapter 1.
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.
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.
Object Oriented Programming (OOP) LAB # 5 TA. Maram & TA. Mubaraka TA. Kholood & TA. Aamal.
PHY281Introduction to JavaSlide 1 Introduction to Java In this section we will learn how how to use Java and write our first Java Applet:  The Java Development.
 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.
Introduction to Java Programming CS 21a: Introduction to Computing I Department of Information Systems and Computer Science Ateneo de Manila University.
Introduction to Java Programming CS 21a: Introduction to Computing I First Semester,
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.
Java Programming, 3e Concepts and Techniques Chapter 2 - Part 2 Creating a Java Application and Applet.
16-1 The World Wide Web The Web An infrastructure of distributed information combined with software that uses networks as a vehicle to exchange that information.
CPS120: Introduction to Computer Science The World Wide Web Nell Dale John Lewis.
Java Lecture 16: Dolores Zage. WWW n Was a method for distributing passive information n added forms and image maps n interaction was only a new way to.
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 and Frames CS 21a: Introduction to Computing I First Semester,
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
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.
HTML. Principle of Programming  Interface with PC 2 English Japanese Chinese Machine Code Compiler / Interpreter C++ Perl Assembler Machine Code.
Chapter 8 Introduction to HTML and Applets Fundamentals of Java.
Chapter 13. Applets and HTML HTML Applets Computer Programming with JAVA.
POS 406 Java Technology And Beginning Java Code
1 Programming Fundamentals AITI-GP. 2 Introduction to Programming.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Introduction to Applets Course Lecture Slides 29 th July 2010.
The Joy of Programming (also known as) Introduction to Object-Oriented Programming.
CS 3131 Introduction to Programming in Java Rich Maclin Computer Science Department.
Chapter 13Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 13 l HTML l Applets Applets and HTML.
Introduction to Java Applets Sangeetha Parthasarathy 05/21/2001.
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,
Introduction to Java Programming. Introduction Course Objectives Organization of the Book.
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.
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.
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.
CSE S. Tanimoto Java Introduction 1 Java A Programming Language for Web-based Computing with Graphics.
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
Applets Yong Choi School of Business CSU, Bakersfield.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Introduction to Programming. The Programming Process Create/Edit Program Compile Program Execute Program Compile Errors?Run-Time Errors? Source Program.
Creating a Java Application and Applet
Applets. 9/04/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L12: Applets Slide 2 Applets Usually.
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.
Applications Active Web Documents Active Web Documents.
Lecture 09 Applets.
Introduction to Java Applets
UNIT-5.
Java Applets.
Handout-14 Applets and Graphics
G6DICP - Lecture 27 Java Applets.
Presentation transcript:

Java Applets

2 Introduction to Java Applet Programs  Applications are stand alone programs executed with Java interpreter executed with Java interpreter  Applet is a small program can be placed on a web page can be placed on a web page will be executed by the web browser will be executed by the web browser give web pages “dynamic content” give web pages “dynamic content”

3 Java Applets  Built using one of general definitions of applets Applet class Applet class JAapplet class JAapplet class  Java applets are usually graphical Draw graphics in a defined screen area Draw graphics in a defined screen area Enable user interaction with GUI elements Enable user interaction with GUI elements

4 Java Applet Classes  Abstract Windowing Toolkit AWT Earlier versions of Java Earlier versions of Java Applet class is one of the AWT components Applet class is one of the AWT components  Java Foundation Classes JFC Extension to Java in 1997 Extension to Java in 1997 Has a collection of Swing components for enhanced GUIs Has a collection of Swing components for enhanced GUIs Swing component classes begin with J Swing component classes begin with J

5 Java Applets  Applets are Java programs that can be embedded in HTML documents To run an applet you must create a.html file which references the applet To run an applet you must create a.html file which references the applet Ready to Program also will run an applet Ready to Program also will run an applet  When browser loads Web page containing applet Applet downloads into Web browser Applet downloads into Web browser begins execution begins execution  Can be tested using appletviewer program

6 Contrast Application with Applet ApplicationApplet Object class extended Class not declared public Has a main() static keyword used Uses System.exit(1) JApplet class extended class declared to be public init() instead of main() init() not declared with static keyword

7 Applet Declaration  Syntax (note difference from application declaration) public class ClassName extends JAapplet application ClassName is an object that will be a subclass of JApplet

8 Body of an Applet  Note there is no main() method in an applet JApplet class provides other methods instead of a main method JApplet class provides other methods instead of a main method  First method executed is the init() method

9 Applets  Applet Program that runs in Program that runs in appletviewer (test utility for applets)appletviewer (test utility for applets) Web browser (IE, Communicator)Web browser (IE, Communicator) Executes when HTML (Hypertext Markup Language) document containing applet is opened Executes when HTML (Hypertext Markup Language) document containing applet is opened Applications run in command windows Applications run in command windows  Notes Focus on fundamental programming concepts first Focus on fundamental programming concepts first Explanations will come laterExplanations will come later

10 Applets and Web Pages – HTML  Applets embedded in a web page Executed when web page loaded by browser Executed when web page loaded by browser  Web pages structured with HTML codes H yper T ext M ark-up L anguage H yper T ext M ark-up L anguage  Syntax...  Syntax... Turns format on Turns the format off

11 Applets and Web Pages – HTML  Embedding Java applets Insert applet tags Insert applet tags  Call the specific applet by its file name Where nnn and mmm are specific pixel sizes

12 Applets and Web Pages – HTML  Create the web page code using a text editor  Save it with an.html suffix  Open this file with appletviewer or with a web browser that supports Java  Java Plug-in must be installed (part of J2SDK from Sun)

13 Applets and Web Pages – HTML  Client Web browser anywhere can access this web page from its host server  Embedded Java applet runs on client browser (of any type platform)  This means a client anywhere on any type of platform can run a piece of software developed on any other type of platform Platform Independence

14 Thinking About Objects  Java an object-oriented language However, Java has constructs from structured programming However, Java has constructs from structured programming  Object orientation Natural way to think about world and writing computer programs Natural way to think about world and writing computer programs Object-oriented programming models the real worldObject-oriented programming models the real world Attributes - properties of objects Attributes - properties of objects Size, shape, color, weight, etc.Size, shape, color, weight, etc. Behaviors - actions that objects can perform Behaviors - actions that objects can perform A ball rolls, bounces, inflates and deflatesA ball rolls, bounces, inflates and deflates

15 Thinking About Objects  Object orientation (continued) Inheritance Inheritance New classes of objects absorb characteristics of existing classesNew classes of objects absorb characteristics of existing classes Information hiding Information hiding Objects usually do not know how other objects are implementedObjects usually do not know how other objects are implemented We can drive cars without knowing how every part works internallyWe can drive cars without knowing how every part works internally

16 Thinking About Objects Class - unit of Java programming  Java focuses on nouns (classes) C focuses on verbs and is action oriented C focuses on verbs and is action oriented  Contain methods Implement behaviors Implement behaviors  Contain data Implement attributes Implement attributes  Classes are reusable Standardized, interchangeable parts Standardized, interchangeable parts

17 A Simple Java Applet: Drawing a String  Figure 3.6 – a welcome message applet Figure 3.6 Figure 3.6  The.html code to run the applet in a browser  The program output shown in the Applet Viewer

18 Running the Applet  Compile Use Ready to Program Use Ready to Program If no errors, bytecodes stored in If no errors, bytecodes stored in WelcomeApplet.class  We must create an HTML file Loads the applet into appletviewer or a browser Loads the applet into appletviewer or a browser Ends in.htm or.html Ends in.htm or.html  To execute an applet Create an HTML file indicating which applet the browser (or appletviewer ) should load and execute Create an HTML file indicating which applet the browser (or appletviewer ) should load and execute

19 Running the Applet - Alternatively  Run from within Ready to Program  Prompt for applet window size appears  Applet window runs

20 import allows us to use predefined classes (allowing us to use applets and graphics, in this case). extends allows us to inherit the capabilities of class JApplet. Method paint is guaranteed to be called in all applets. Its first line must be defined as above.

21 Running An Applet import java.applet.Applet; import java.awt.Graphics; public class HelloApplet extends Applet { public void paint (Graphics g) { g.drawString ("Hello. Welcome to",25,25); g.drawString ("Java Programming",25,40); }} import java.applet.Applet; import java.awt.Graphics; public class HelloApplet extends Applet { public void paint (Graphics g) { g.drawString ("Hello. Welcome to",25,25); g.drawString ("Java Programming",25,40); }} Enter this text into your Ready to Program editor Compile the Java code Enter this text into your Ready to Program editor Compile the Java code

22 Running An Applet  Now create an. html file to run the applet  Save it as HelloApplet.html HelloApplet.html  Make sure you save it in the same directory as the. java file