Internet Software Development Applets Paul J Krause.

Slides:



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

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 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.
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.
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.
A Simple Applet --- Digital Clock import java.awt.*; import java.util.Calendar; public class DigitalColok extends java.applet.Applet implements Runnable.
Enahnced Digital Clock Applet Setting applet parameters in the web page. The applet tag in HTML:
1 Recitation 11. Applet Applets. An applet is a Java program that is started by a browser (e.g. netscape or internet explorer) when an html file has a.
Applets, Graphical User Interfaces, and Threads / Chapter 9 1 Applets, Graphical User Interfaces, and Threads.
Applet class The Applet class provides the essential framework that enables applets to be run by a web browser Applet do not have main method Applet depend.
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,
APPLETS CSC 171 FALL 2004 LECTURE 6. APPLETS Graphical Java programs Run inside web browser Platform-neutral Easy deployment--loads when needed Secure.
Unit 071 Review of Applets Learning Outcomes oDistinguish between Java Applications and Java Applets. oWrite applet programs that can load images and play.
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.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L05 (Chapter 16) Applets.
CSTP WS00CS423 (cotter)1 Java Applets Objective: Learn how to develop Java programs that interact with users through a Web browser.
Applets  The Applet Class  The HTML Tag F Passing Parameters to Applets.
©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.
Component-Based Software Engineering Internet Applications Paul Krause.
Applets CS 3331 Sections 3.3 & 4.7 of [Jia03].
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.
Applets.
JAPPLET.
Object Oriented Programming Lecture 4: Refactoring, An Applet Example, Idiom - Animation applets, Introduction to the Laboratorial exercise www2.hh.se/staff/jebe/oop2005/
Applets & Graphics. Applets programs that run inside a browser Java platform-independence makes applets possible security restrictions: –cannot read or.
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.
Object Oriented Programming Lecture 5: Refactoring by Inheritance and Delegation - A simple Design Pattern for animation applets, A Generic Function Plotter.
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,
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.
Program that runs in appletviewer (test utility for applets) Web browser (IE, Communicator) Executes when HTML (Hypertext Markup Language) document containing.
Lec 16 Adding Mouse and KeyEvent handlers to an Applet Class.
APPLET. 2 Introduction to Java Applet Programs Applications are stand alone programs ◦ executed with Java interpreter Applet is a small program ◦ can.
Introduction to Java 113 th February 2004Sifei HE © 2004 Introduction to Java for CS381, EE4.Web By Sifei HE Department of Computing.
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. Internet/WWW How does it work? Internet/WWW.
Your name CSCI/CMPE 3326 Object-Oriented Programming in Java Dongchul Kim Department of Computer Science University of Texas – Pan American 1.Applet.
1 Contents Introduction Applet Vs Application Security Restrictions on Applet A simple example “Hello World!” applet Compiling & Running Applet HTML document.
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.
Applets Java code is compiled into byte code instead of machine language –Languages like C, C++, Pascal and others are compiled into machine language so.
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.
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.
Creating an Object that can draw itself The paint method can ‘draw’ because it is passed a graphics environment as a parameter. If a class method is passed.
Java Applets. Introduction to Java and Java Applets Java applications Run in stand-alone mode No additional software required (such as a Web browser)
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.
Topic: Applets Course : JAVA PROGRAMMING Paper Code: ETCS-307
User Interface Programming In Java
Applets In Java Visit for more Learning Resources 1.
Java Applets.
Distributed Computing, M. L. Liu
Distributed Computing, M. L. Liu
UNIT-5.
Java Applets.
Java Applets.
Introduction to Applet, Application and JDK
Java applets 1/3/2019.
Java Programming COMP-417 Applet
Handout-14 Applets and Graphics
Enabling Application Delivery Via the Web
A Brief History January 1996: first official release JDK 1.0
APPLET PROGRAMMING.
Presentation transcript:

Internet Software Development Applets Paul J Krause

Contents  Applet Basics  Passing parameters to applets  Simple graphics operations  Animating applets

Hello.java // Filename: Hello.java public class Hello { public static void main(String args) { public static void main(String args) { System.out.println(“Hello fom Venus”); System.out.println(“Hello fom Venus”); }}

Applets  Java applications are executed from the command line  Applets are small applications that can be embedded in html pages  They can then be downloaded via the world wide web and invoked in a browser

Template for an Applet  Subclass one of the Java foundation classes: java.applet.Applet; java.applet.Applet; javax.swing.JApplet; javax.swing.JApplet;  It’s behaviour is invoked in a “paint” method, not a “main” method

// File: MyApplet.java import java.awt.*; import java.applet.Applet; public class MyApplet extends Applet { public void paint(Graphics g) { public void paint(Graphics g) { // Do something interesting }}

Viewing Area of Applet y x(0,0) height width These dimensions are set in the HTML file

Contract for the paint method  Dimensions of the region on the Web page assigned to the applet are set within an tag in an HTML file  The paint( ) method defines the appearance of the applet within this rectangular region  The paint( ) method is invoked when the applet is initially loaded in the browser (or applet viewer)

HelloFromVenus.java import java.awt.*; import java.applet.Applet; public class HelloFromVenus extends Applet { public void paint(Graphics g) { Dimension d = getSize( ); // Gets the size of the rectangle allocated to an // instance of this applet }}

painting the background import java.awt.*; import java.applet.Applet; public class HelloFromVenus extends Applet { public void paint(Graphics g) { Dimension d = getSize( ); g.setColor(Color.black); g.fillRect(0, 0, d.width, d.height); }}

painting the text public void paint(Graphics g) { Dimension d = getSize( ); g.setColor(Color.black); g.fillRect(0, 0, d.width, d.height); // set font style and size:- g.setFont(new Font(“Sans-serif”, Font.BOLD, 24); // change colour on paint brush:- g.setColor(255, 215, 0); // note different way! g.drawString(“Hello from Venus!”, 40, 25); }

finally add the image public void paint(Graphics g) { Dimension d = getSize( ); g.setColor(Color.black); g.fillRect(0, 0, d.width, d.height); g.setFont(new Font(“Sans-serif”, Font.BOLD, 24); g.setColor(255, 215, 0); g.drawString(“Hello from Venus!”, 40, 25); g.drawImage(getImage(getCodeBase( ), “Venus.gif”, 20, 60, this); }

Embedding Applets in HTML < applet code = bytecode-filename width = pixels height = pixels > </applet>

<HTML><HEAD> HelloFromVenus Applet </HEAD> <CENTER> Here is the Hello From Venus Applet Here is the Hello From Venus Applet </CENTER> Venus photo courtesy of NASA. </BODY>

Parameter passing  To make applets reusable in different contexts, we need to be able to pass parameters from the html files  Can do this by using: tag in html, and tag in html, and getParameter(String) method in the applet getParameter(String) method in the applet

in the html file < applet code = bytecode-filename width = pixels height = pixels > …</applet>

in the applet String input = getParameter(String);

Example  In the html file:  In the applet textV = getParameter(“text”); textV = getParameter(“text”);

Initialisation of an applet  Initialisation of an applet is not done in the Constructor method, but in an init( ) method  Why?  An applet context interprets the tag in an html file  The applet context first constructs an instance of the applet, then interprets the remaining parameters in the tag  The init( ) method is invoked after the information in the tag has been processed

import java.awt.*; import java.applet.*; public class Font02 extends Applet { String tmpSt, textV; String tmpSt, textV; int sizeV; int sizeV; public void init( ) { public void init( ) { textV = getParameter("text"); tmpSt = getParameter("size"); sizeV = Integer.parseInt(tmpSt) } public void paint(Graphics gg) { public void paint(Graphics gg) { … } }

<html><head> Font Rotation and Translation Font Rotation and Translation </head> Font Rotation and Translation Font Rotation and Translation </body></html>

shifting graphical objects  To translate a graphical object, use: translate(xpos, ypos); translate(xpos, ypos);  To rotate a graphical object, use: rotate(angle_in_radians); rotate(angle_in_radians);

public void paint(Graphics gg) { public void paint(Graphics gg) { int ii; Graphics2D g = (Graphics2D) gg; g.setFont( new Font("Arial", Font.BOLD, sizeV) ); g.setColor(Color.blue) g.translate(200, 200); for(ii = 1; ii <= 16; ii++) { g.rotate(Math.PI/8.0); g.rotate(Math.PI/8.0); g.drawString( textV, 20, 0); g.drawString( textV, 20, 0);}

public void paint(Graphics gg) { public void paint(Graphics gg) { int ii; Graphics2D g = (Graphics2D) gg; g.setFont( new Font("Arial", Font.BOLD, sizeV) ); g.translate(200, 200); for(ii = 1; ii <= 16; ii++) { g.rotate(Math.PI/8.0); g.rotate(Math.PI/8.0); g.setColor( new Color( (int) (Math.random( )*256), g.setColor( new Color( (int) (Math.random( )*256), (int) (Math.random( )*256), (int) (Math.random( )*256), (int) (Math.random( )*256) )); (int) (Math.random( )*256) )); g.drawString( textV, 20, 0); g.drawString( textV, 20, 0);}

Animated applets  Create a thread for an instance of the applet  paint( ) the applet into the applet context  Each time the relevant graphical properties of the applet are changed, repaint( ) the applet

Applet Lifecycle  init() is invoked when the applet is loaded  start() is invoked when the page containing the applet has been entered  stop() is invoked when the page is left  destroy() is invoked when the page is discarded

Font03.java import java.awt.*; import java.applet.*; public class Font03 extends Applet implements Runnable { protected Thread paintThread = null; protected Thread paintThread = null; protected String tmpSt, textV; protected String tmpSt, textV; protected int sizeV; protected int sizeV; protected double rotation=0.0; protected double rotation=0.0; public void init( ) { // as before public void init( ) { // as before}}

starting and stopping public void start( ) { if (paintThread == null) { paintThread = new Thread(this); paintThread = new Thread(this); paintThread.start( ); paintThread.start( );}} public void stop( ) { paintThread = null; }

running the applet public void run( ) { while (Thread.currentThread( ) == paintThread) { repaint( ); repaint( ); try { try { Thread.currentThread( ).sleep(100); rotation += Math.PI/8.0; } catch(InterruptedException e) { } catch(InterruptedException e) { }}}

public void paint(Graphics gg) { public void paint(Graphics gg) { int ii; Graphics2D g = (Graphics2D) gg; g.setFont( new Font("Arial", Font.BOLD, sizeV) ); g.translate(200, 200); g.rotate(rotation); g.setColor( new Color( (int) (Math.random( )*256), (int) (Math.random( )*256), (int) (Math.random( )*256), (int) (Math.random( )*256) )); (int) (Math.random( )*256) )); g.drawString( textV, 20, 0); }