Applets Life Cycle Drawing and Event Handling Methods for UI Components Applet Capabilities Example.

Slides:



Advertisements
Similar presentations
1 Applets Programming Enabling Application Delivery Via the Web.
Advertisements

Introduction to Java 2 Programming Lecture 10 Applets.
Made with love, by Zachary Langley Applets The Graphics Presentation.
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.
Programming and Problem Solving With Java Copyright 1999, James M. Slack Applets What is an Applet? Applet Parameters Graphics in Applets Other Applet.
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.
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.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 16 Applets.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
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.
CS3157 Java UI Recitation. Material Covered: Overview of AWT components, Event Handling, creating applets, and sample UI. Not covered in recitation: Drawing,
Applets, Graphical User Interfaces, and Threads / Chapter 9 1 Applets, Graphical User Interfaces, and Threads.
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.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 14 Applets, Images,
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.
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.
J2EE Applets Servlet - Applet communication Presented by Bartosz Sakowicz.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L05 (Chapter 16) Applets.
Io package as Java’s basic I/O system continue’d.
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.
Chapter 9: Applets Jim Burns Fall Outline Learn about applets Learn about applets Write an HTML doc to host an applet Write an HTML doc to host.
Applets Java API.
Applets, AWTS CompSci 230 Software Construction.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 16: Java Applets & AWT Fundamentals of Web Programming.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
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.
Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 9 Source File Anatomy.
JAPPLET.
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.
Chapter 10: Applets and Advanced Graphics The Applet Class The Applet Class The HTML Tag The HTML Tag Passing Parameters to Applets Passing Parameters.
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.
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.
CSC 205 – Java Programming II Applet. Types of Java Programs Applets Applications Console applications Graphics applications Applications are stand-alone.
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 Programming Applets. Topics Write an HTML document to host an applet Understand simple applets Use Labels with simple AWT applets Write a simple.
Chapter 10: Applets and Advanced Graphics The Applet Class The Applet Class The HTML Tag The HTML Tag Passing Parameters to Applets Passing Parameters.
Chapter 14 Applets and Advanced GUI  The Applet Class  The HTML Tag F Passing Parameters to Applets F Conversions Between Applications and Applets F.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
Field Trip #23 Hangman By Keith Lynn. JApplet A JApplet is a top-level container An applet is a small Java program that is executed by another program.
Introduction to Java Chapter 9 - Graphical User Interfaces and Applets1 Chapter 9 Graphical User Interfaces and Applets.
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 Applets. 2 Design of Applets 3 Sun wrote Java to be executable within a hosting application browser The applications are applets. An applet is downloaded.
Applets, Images, and Audio Chapter 14 CSCI CSCI 1302 – Applets, Images, and Audio2 Outline Introduction The Applet Class –The init Method –The start.
Chapter 12: Accessing the Web URL (Uniform Resource Locator) class Applet methods –for audio clips –for images –context interface.
Copyright © Curt Hill Applets A different type of program.
Creating a Java Application and Applet
1 Applets. 2 What is an applet? Applet: a Java program that can be inserted into a web page and run by loading that page in a browser brings web pages.
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.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 10.
1 Java and AWT CPS 470 Spring 1998 Laura Campbell.
1 Applets Programming. Introduction Java programs are divided into two main categories, applets and applications. An application is an ordinary Java program.
CS202 Java Object Oriented Programming GUI Programming – Applets Chengyu Sun California State University, Los Angeles.
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.
Applets.
Lecture 09 Applets.
Ellen Walker Hiram College
30 Java Applets.
Distributed Computing, M. L. Liu
Distributed Computing, M. L. Liu
UNIT-5.
Introduction to Computing Using Java
Java applets 1/3/2019.
Applet Fundamentals Applet are small applications that are accessed on an Internet server, transported over the Internet, automatically installed and run.
11.1 Applets & graphics.
APPLET PROGRAMMING.
Presentation transcript:

Applets Life Cycle Drawing and Event Handling Methods for UI Components Applet Capabilities Example

Life Cycle Loading the applet –instance of applet subclass is created –applet initializes itself [ init ()] (like constructor) –applet starts running [ start ()] (execution, except user input) Leave and Come Back –stopping [ stop ()] –restarting [ start ()] –iconification [minimize]

Reloading the Applet Quitting the Browser –stop () –final cleanup [ destroy ()] init, start, stop, destroy methods

Drawing and Event Handling paint (): Basic display method. update (): method used with paint () to improve performance Objects notified of registered events (listen for them) Register event by implementing appropriate interface ( mouseListener )

Buttons (java.awt.Button) Checkboxes (java.awt.Checkbox) Single-line text fields (java.awt.TextField) Larger text display and editing areas (java.awt.TextArea) Labels (java.awt.Label) Lists (java.awt.List) Pop-up lists of choices (java.awt.Choice) Sliders and scrollbars (java.awt.Scrollbar) Drawing areas (java.awt.Canvas) Menus (java.awt.Menu, java.awt.MenuItem, java.awt.CheckboxMenuItem) Containers (java.awt.Panel, java.awt.Window and its subclasses) Pre-Made AWT UI Components

Adding UI Components add: adds the component to the applet remove: removes the component setLayout: sets the applet’s layout manager which controls the position and size of the applet components

Working with Applets Cannot load libraries or define native methods Cannot read or write files on local host Cannot make network connections Cannot start a program on local host Cannot read system properties on local host Implemented with SecurityManager which throws SecurityExceptions

Applets Can... Display html If local, restrictions off make network connections back to host they came from Don’t have to stop when you leave

<APPLET CODE = AppletSubclass.class WIDTH=anInt HEIGHT=anInt>

Finding and Loading Data Files

Applet.getCodeBase() returns URL of directory from which applet classes load Applet.getDocumentBase() returns URL of directory from which applet’s html came Image image=getImage(getCodeBase(),"imgDir/a.gif");

Showing Status Applet.showStatus(String s); showStatus("MyApplet: Loading image file " + file);

Displaying Documents AppletContext class allows applet to interact with context (i.e. browser) in which it runs. Display in browser (won’t work with appletviewer) public void showDocument(java.net.URL url) public void showDocument(java.net.URL url, String targetWindow)

"_blank" Display the document in a new, nameless window. "windowName" Display the document in a window named windowName. This window is created if necessary. "_self" Display the document in the window and frame that contain the applet. "_parent" Display the document in the applet's window but in the parent frame of the applet's frame. If the applet frame has no parent frame, this acts the same as "_self". "_top" Display the document in the applet's window but in the top-level frame. If the applet's frame is the top-level frame, this acts the same as "_self".

...//In an Applet subclass: urlWindow = new URLWindow(getAppletContext());... class URLWindow extends Frame {... public URLWindow(AppletContext appletContext) {... this.appletContext = appletContext;... }... public boolean action(Event event, Object o) {... String urlString = /* user-entered string */; URL url = null; try { url = new URL(urlString); } catch (MalformedURLException e) {...//Inform the user and return... } if (url != null) { if (/* user doesn't want to specify the window */) { appletContext.showDocument(url); } else { appletContext.showDocument(url, /* user-specified window */); }...

Sending Messages to Other Applets Same host, same directory, same page Find by name on same page Two ways to name applet

1) By specifying a NAME attribute within the applet's tag. For example: <APPLET CODEBASE=example/ CODE=Sender.class WIDTH=450 HEIGHT=200 NAME="buddy">... 2) By specifying a NAME parameter with a tag. For example: <APPLET CODEBASE=example/ CODE=Receiver.class WIDTH=450 HEIGHT=35>...

Applet receiver = null; String receiverName = nameField.getText(); //Get name to search for. receiver = getAppletContext().getApplet(receiverName); if (receiver != null) { //Use the instanceof operator to make sure the applet //we found is a Receiver object. if (!(receiver instanceof Receiver)) { status.appendText("Found applet named " + receiverName + ", " + "but it's not a Receiver object.\n"); } else { status.appendText("Found applet named " + receiverName + ".\n" + " Sending message to it.\n"); //Cast the receiver to be a Receiver object //(instead of just an Applet object) so that the //compiler will let us call a Receiver method. ((Receiver)receiver).processRequestFrom(myName); } }...

Playing Sound AudioClip onceClip, loopClip; onceClip = applet.getAudioClip(getCodeBase(), "bark.au"); loopClip = applet.getAudioClip(getCodeBase(), "train.au"); onceClip.play(); //Play it once. loopClip.loop(); //Start the sound loop. loopClip.stop(); //Stop the sound loop.

Using the Applet Tag Like command line arguments for applets Customize applet operation User Configures Names Provide Default Values Parameter values are all strings Let applet interpret string

<APPLET CODE=AppletButton.class CODEBASE=example WIDTH=350 HEIGHT=60> <PARAM NAME=buttonText VALUE="Click here to see a BorderLayout in action">

int requestedWidth = 0;... String windowWidthString = getParameter("WINDOWWIDTH"); if (windowWidthString != null) { try { requestedWidth = Integer.parseInt(windowWidthString); } catch (NumberFormatException e) { //Use default width. }

String windowClass; String buttonText; String windowTitle; int requestedWidth = 0; int requestedHeight = 0;... public void init() { windowClass = getParameter("WINDOWCLASS"); if (windowClass == null) { windowClass = "TestWindow"; } buttonText = getParameter("BUTTONTEXT"); if (buttonText == null) { buttonText = "Click here to bring up a " + windowClass; } windowTitle = getParameter("WINDOWTITLE"); if (windowTitle == null) { windowTitle = windowClass; } String windowWidthString = getParameter("WINDOWWIDTH"); if (windowWidthString != null) { try { requestedWidth = Integer.parseInt(windowWidthString); } catch (NumberFormatException e) { //Use default width. }...

Combining Applet Files If applet has more than one file, combine into zip archive jar tool and JAR format from java jar cvf file.zip com/mycompany/myproject/*.class *.gif (Solaris) jar cvf file.zip com\mycompany\myproject\*.class *.gif (Windows 95/NT)

<APPLET CODE="AppletSubclass.class" ARCHIVE="file1, file2" WIDTH=anInt HEIGHT=anInt>