Copyright © 1998-2009 Curt Hill Applets A different type of program.

Slides:



Advertisements
Similar presentations
Computers: Tools for an Information Age Writing Your Own Web Page: Using HTML and Web Authoring Tools.
Advertisements

Internet Services and Web Authoring (CSET 226) Lecture # 5 HyperText Markup Language (HTML) 1.
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.
OMT II Mam Saima Gul. * Static web page * a web page with contents that remain fixed and unchanged once it has been created by the author Web server Client.
The Web Warrior Guide to Web Design Technologies
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.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
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.
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.
23-Jun-15 HTML. 2 Web pages are HTML HTML stands for HyperText Markup Language Web pages are plain text files, written in HTML Browsers display web pages.
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.
Object Oriented Programming (OOP) LAB # 5 TA. Maram & TA. Mubaraka TA. Kholood & TA. Aamal.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L05 (Chapter 16) Applets.
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.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Applets Java API.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 16: Java Applets & AWT Fundamentals of Web Programming.
Chapter 12 Applets and Advanced Graphics  The Applet Class  The HTML Tag F Passing Parameters to Applets F Conversions Between Applications and Applets.
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.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
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.
2 Copyright © 2004, Oracle. All rights reserved. Running a Forms Developer Application.
Chapter 8 Introduction to HTML and Applets Fundamentals of Java.
Chapter 12 Applets and Advanced GUI  The Applet Class  The HTML Tag F Passing Parameters to Applets F Conversions Between Applications and Applets F.
Chapter 13. Applets and HTML HTML Applets Computer Programming with JAVA.
Copyright © Curt Hill First Window Builder Program Easy GUIs in Eclipse.
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.
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,
HTML Basics BCIS 3680 Enterprise Programming. Web Client/Server Architecture 2  Your browser (the client) requests a Web page from a remote computer.
Lec.10 + (Chapter 8 & 9) GUI Java Applet Jiang (Jen) ZHENG July 6 th, 2005.
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.
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.
Chapter 6 Applets and HTML  Overview  HTML tags for Applets  Applet Life Cycle  Applet Class  JAR files.
HTML Form Widgets. Review: HTML Forms HTML forms are used to create web pages that accept user input Forms allow the user to communicate information back.
Chapter 10: Applets and Advanced Graphics The Applet Class The Applet Class The HTML Tag The HTML Tag Passing Parameters to Applets Passing Parameters.
L. Anne Spencer (c) 2001 Basic Web Design Document, text, & layout formatting tags & attributes.
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.
Applets, Images, and Audio Chapter 14 CSCI CSCI 1302 – Applets, Images, and Audio2 Outline Introduction The Applet Class –The init Method –The start.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
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.
Writing Your Own Web Page: Using HTML and FrontPage Chapter 10.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 - Introduction to Java Applets Will not cover Section 3.7 Thinking About Objects: Identifying.
2 Copyright © 2004, Oracle. All rights reserved. Running a Forms Developer Application.
1 Applets Programming. Introduction Java programs are divided into two main categories, applets and applications. An application is an ordinary Java program.
© Ms. Masihi.  A Web page contains text and images that convey specific information to viewers.  To create a new web page, open Dreamweaver and select.
HTML Simple Introduction
Running a Forms Developer Application
Distributed Computing, M. L. Liu
Distributed Computing, M. L. Liu
UNIT-5.
Java Applets.
Teaching slides Chapter 6.
11.1 Applets & graphics.
JAVA APPLET PREPARED BY Mr. Jahanzaib Ahmed
Presentation transcript:

Copyright © Curt Hill Applets A different type of program

Copyright © Curt Hill What is an Applet? A small Java program run within something else Usually a web browser –Macro language for Corel Office Suite This is a very restrictive programming environment It can display window components and do graphics –Flow is default layout manager

Copyright © Curt Hill Why write an applet? Need a web page with more than static text and graphics Need: –Animation other than animated gifs or video/movie –Calculations or programming not in HTML –Front end data entry for server Simple things often done with a script, more complicated with applet

Copyright © Curt Hill Applet Restrictions The browser is in control Cannot create or access files from client machine –Starting in 1.3 there is local workspace that can be accessed –This is not a pipe into the whole file system Cannot run programs on client machine Can only connect to the server machine –Some harmless things may go elsewhere Cannot execute native methods –Native is machine language

Copyright © Curt Hill Applet is a Panel and Container It has methods that can do the work It has properties that can be referenced from all its methods It has events –Methods that are called asynchronously –Called by browser –The event model has already been integrated into the applet

Copyright © Curt Hill Events Something that happens at unpredictable times Event handler is executed when the event occurs Typical events that may need handling: –The applet becomes visible and needs to be drawn –A button is pushed –An error occurs

Copyright © Curt Hill Applet methods There are more than 20 standard applet methods Most of these are inherited from ancestors Five are event handlers: –Each is automatically called by the browser or containing program –Each has a characteristic signature Overriding these gives the applet desired behaviors These do not need to be added

Copyright © Curt Hill Applet Startup Events public void init() –Called once after applet is first loaded –Use for one time initializations –Use this instead of a constructor to initialize instance variables public void start() –Called whenever the applet becomes visible –Not when page becomes visible –May be used to start animations

Copyright © Curt Hill Applet Paint Method public void paint(Graphics g) –Called by update to redraw the screen –A Graphics object, which holds the panel –All displays on the panel are through this graphics item –Only need to override if you are using Graphics drawing items Most GUI items (components) repaint themselves –Paint must call super.paint() for this

Copyright © Curt Hill Animations and Paint Paint typically only needs to cause the redraw of non components Paint is itself called by update public void update(Graphics g) –update clears the screen and paints –Using the normal update causes flicker in the screen because of the clear –Thus update is overridden not to clear every time

Copyright © Curt Hill Applet Finish Methods public void stop() –Called whenever the applet scrolls out of sight –Should halt whatever start begins public void destroy() –Called once when applet is being removed by browser –Use to release resources –There have been problems in the past on browsers not calling it

Copyright © Curt Hill Starting and Stopping start is called when applet becomes visible stop is called when it is not There may be many pairs of start- stop calls in a run start and stop should be inverses of each other –What one does the other reverses

Notes Since the browser is in control there is no need for an exit button or a dialog box Any GUI components may be used Event handlers for buttons are still acceptable Copyright © Curt Hill

HTML Hyper Text Markup Language A text based formatting language Consists of text and tags Text is written mostly without regard to margins –The browser may dynamically change margins XML is the successor –It may emulate HTML

Copyright © Curt Hill HTML Tags A tag is enclosed in A keyword identifies the function Some parameters may be part of the tag Paired tags start with and end with Tag names are not sensitive to case Some tags do not need a ending tag

Copyright © Curt Hill Structure of HTML file Starts with and ends with The file is composed of two pieces within this: –Head - to –Body - to Different tags can be in each –These will be considered now, but many more exist than than will be shown

Copyright © Curt Hill HTML Head Tags Page Title –The title that most browsers show Various META tags that indicate author etc. HTML files produced by other programs (eg. Word) will produce many other tags in this area –These are usually tags which give a variety of auxiliary information like subject, program name, template, etc

Copyright © Curt Hill HTML Body Tags The body is what shows in the browser window The Body tag can set the default colors, backgrounds etc Between and occurs all the content of the page as well

Copyright © Curt Hill Paired Formatting tags to to bold to italics to underline to monospaced typewriter font to determines font sizes and styles through creates a header

Copyright © Curt Hill Unpaired tags Some HTML generators will pair these as well, but it is not necessary new paragraph a new line produces a horizontal line

Copyright © Curt Hill Java applet tags Default message code identifies the class file size of panel is determined by height and width Multiple params can be entered The default message is shown if the browser cannot handle Java

Copyright © Curt Hill Applet Methods getCodeBase() returns the URL getAppletInfo() returns a string of information about applet getImage(URL) gets an image from server getParameter and getParameterInfo describe parameters

Copyright © Curt Hill Executing the applet Two possibilities –AppletViewer A minimal browser Ignores all the other HTML –Java Capable Web Browser Usually harder to reload the applet

Communication is Good! Parameters are the means that the HTML can communicate with the applet Two sides to this: –How the HTML passes the data –How Java catches the data Copyright © Curt Hill

Recall the Java applet tags Default message code identifies the class file size of panel is determined by height and width Params can be entered The default message is shown if the browser cannot handle Java Copyright © Curt Hill

Required Parameters The height and width are special parameters They must be given in order that the browser knows the size of the applet to display However, they may be accessed from Java, just like any parameters Copyright © Curt Hill

Optional Parameters The HTML for a parameter is a tag, which is enclosed within the applet tag Parameters tags have three pieces: –The PARAM tag label –The name of the parameter –The value of the parameter –These are separated by blanks in the PARAM tag Copyright © Curt Hill

The name is how the parameter will be identified in Java –Must be unique for this applet –Not case sensitive The value is always a string –Must be enclosed in quotes if it contains special characters Copyright © Curt Hill

Receiving the parameter The function getParameter must be used It returns a String and takes a String The String it takes is the name of the parameter The String it returns is the value of that parameter If the parameter is not present, then returned value is null Copyright © Curt Hill

Obtaining parameters String s; s = getParameter(“width”); if (s != null) width = Integer.parseInt(s); s = getParameter(“Name”); if(s!=null) name = s; Copyright © Curt Hill

Eclipse Use javax.swing.Japplet as the ancestor It will not give you much so you add the components that are needed in the init method It will recognize that you have an applet and not an application –It will use applet viewer One screen shot follows Copyright © Curt Hill

AppletShell The web page contains Has the following methods: –init and destroy –start and stop –paint –Delete the ones not used Copyright © Curt Hill

Windows Builder Besides the ability to create and populate an application, we also can generate applets Mostly the same as applications, but no about/exit buttons are needed Copyright © Curt Hill

Eclipse AppletViewer is the default way to view an applet The default sizes may changed They are generally 200 by 200 Copyright © Curt Hill

Run Configuration Copyright © Curt Hill

Main Tab Copyright © Curt Hill

Parameters Tab Copyright © Curt Hill