CSC 205 – Java Programming II Applet. Types of Java Programs Applets Applications Console applications Graphics applications Applications are stand-alone.

Slides:



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

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.
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 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;
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,
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.
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.
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.
Threads A thread is a program unit that is executed independently of other parts of the program A thread is a program unit that is executed independently.
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.
Developing User Interfaces (DUI) Chris North cs3724: HCI.
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.
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.
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.
JAPPLET.
Applets Life Cycle Drawing and Event Handling Methods for UI Components Applet Capabilities Example.
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.
POS 406 Java Technology And Beginning Java Code
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Introduction to Applets Course Lecture Slides 29 th July 2010.
CS 3131 Introduction to Programming in Java Rich Maclin Computer Science Department.
Java Applets. Topics What is an applet? To convert GUI applications to Applets Hello World applet example!! Applets life cycle examples Invoking applets.
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,
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.
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 applets. Outline What is Java? Java Applications Java Applets Java Applets Securities Summary.
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.
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.
1 Applications & Applets Standalone applications & Java applets Peter Mozelius DSV/UCSC.
Applets, Images, and Audio Chapter 14 CSCI CSCI 1302 – Applets, Images, and Audio2 Outline Introduction The Applet Class –The init Method –The start.
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.
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.
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.
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.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
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.
Applications Active Web Documents Active Web Documents.
Applets.
30 Java Applets.
Distributed Computing, M. L. Liu
Distributed Computing, M. L. Liu
UNIT-5.
Introduction to Computing Using Java
Java Applets.
Java applets 1/3/2019.
Applet in Java.
Java Programming COMP-417 Applet
11.1 Applets & graphics.
JAVA APPLET PREPARED BY Mr. Jahanzaib Ahmed
G6DICP - Lecture 27 Java Applets.
APPLET PROGRAMMING.
Presentation transcript:

CSC 205 – Java Programming II Applet

Types of Java Programs Applets Applications Console applications Graphics applications Applications are stand-alone programs An application must have a main method

What Is Applet An applet is a program that adheres to a set of conventions run within a Java-compatible Web browser downloaded from a Web server An applet must extend the Applet class

Download From Web Server

Advantages & Disadvantages Advantages –Can be accessed where Internet is available –When GUIs need to be upgraded, just change them at one location: on the Web server Disadvantages –Time to download may be long –Security could be an issue

Security Policies Browsers impose the following restrictions on any applet that is loaded over the network: An applet cannot load libraries or define native methods. It cannot ordinarily read or write files, or start any program on the host that's executing it. It cannot make network connections except to the host that it came from. It cannot read certain system properties. Windows that an applet brings up look different than windows that an application brings up.

Inheritance Hierarchy java.applet Class Applet java.lang.Object | +--java.awt.Component | +--java.awt.Container | +--java.awt.Panel | +--java.applet.Applet

A Typical Applet import java.applet.Applet; import java.awt.Graphics; public class Simple extends Applet { //methods to be overridden public void init() {…} public void start() {…} public void stop() {…} public void destroy() {…} void addItem(String newWord) { …; repaint(); } public void paint(Graphics g) {…} //inherited from the Container class }

Life Cycle of an Applet Loading the Applet –An instance of the applet's controlling class (an Applet subclass) is created –The applet initializes itself –The applet starts running Leaving and Returning to the Applet's Page –The applet stops running when leaving the page –the applet can start itself again when returning

Methods for Milestones An applet can override the following methods init To initialize the applet each time it's loaded (or reloaded). start To start the applet's execution, such as when the applet's loaded or when the user revisits a page that contains the applet. stop To stop the applet's execution, such as when the user leaves the applet's page or quits the browser. destroy To perform a final cleanup in preparation for unloading

Methods for Drawing An applet can override the following two display methods (of the Container class) : paint The basic display method. Many applets implement the paint method to draw the applet's representation within a browser page. update A method you can use along with paint to improve drawing performance

Animation To update applet changes invoke the repaint method (inherited from the Component class) periodically The paint method will be invoked when the applet is repainted

Event Handling Applets inherit a group of event-handling methods from the Component class To react to an event, an applet must override either the appropriate event-specific method, or the handleEvent method (from the Component class)

Event Handling – Example Adding the following code to the Simple applet makes it respond to mouse clicks. import java.awt.Event;... public boolean mouseDown(Event event, int x, int y) { addItem("click!... "); return true; }

Deprecation Unfortunately, many of the samples available online or in textbooks use deprecated methods You will be warned when you compile code with deprecated methods Use the –deprecation option to see detailed info javac –deprecation Simple.java Replace deprecated methods with newer methods as recommended by latest version of Java API

Deprecation

Using UI Components Because the Applet class inherits from the AWT Container class, it's easy to add components to applets and to use layout managers to control the components' onscreen positions. add Adds the specified Component remove Removes the specified Component setLayout Sets the layout manager

Testing Applets Two ways to run an applet Use the applet viewer appletviewer simple.html Embed applets into Web pages Both need to use the applet tag in HTML files

HTML – An Overview Markup language use tags to represent the meaning and/or content of the enclosed data Some features Not case sensitive Loose syntax Predefined tags Text is the only data type

More Examples The following two tags are equivalent

A Simple HTML File Click on the applet to start the animation. <applet code="SelectionSortApplet.class" width="300" height="300">

Thread A thread is a program unit that is executed independently of other parts of the program The JVM executes each thread for a short time and then switches to another thread A programmer can concentrate on what tasks each thread need to perform and possibly, the communication between threads

Write a Thread Follow the steps Write a class that extends the Thread class Place the code for the task in the run method Create an object of the your thread class Call the start method to activate your thread

Sample Thread Class public class GreetingThread extends Thread{ public GreetingThread(String aGreeting){ greeting = aGreeting; } public void run() { try { for (int i = 1; i <= REPETITIONS; i++) { Date now = new Date(); System.out.println(now + " " + greeting); sleep(DELAY); } } catch (InterruptedException exception){ }

Running A Thread – I public class GreetingThreadTest{ public static void main(String[] args) { GreetingThread t1 = new GreetingThread("Hello, World!"); GreetingThread t2 = new GreetingThread("Goodbye, World!"); t1.start(); t2.start(); }

Sample Output

The Runnable Interface Problems of writing a thread which extends another class, e.g. the Frame class Since Java doesn’t allow multiple inheritance Can implement the Runnable interface instead public class MyFrame extends Frame implements Runnable { public MyFrame() {…} public void run() {…} }

Running A Thread – II Follow the steps Construct a Runnable object Create a thread using the Runnable object Invoke the start method of the thread MyFrame frame = new MyFrame(); Thread myThread = new Thread(frame); myThread.start();

start interrupt