Applets. What is an Applet?  According to Sun “An applet is a small program that is intended not to be run on its own, but rather to be embedded inside.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 10 Applets.
Advertisements

Learn about Java applets. Know the differences between Java applets and applications. Designing and using Java applets Running Java applets. Security.
Dept. of Computer Science - SSBN Java Applets Vishnuvardhan.M.
Client Side Programming Using Java Applet Outcomes: You will be expected to know: – Java Applets and HTML file; –bytecode and platform independent programs;
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Slides prepared by Rose Williams, Binghamton University Chapter 18 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.
Applets, Graphical User Interfaces, and Threads / Chapter 9 1 Applets, Graphical User Interfaces, and Threads.
Java Applets. Lecture Objectives Learn about Java applets. Know the differences between Java applets and applications. Designing and using Java applets.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L05 (Chapter 16) Applets.
1 Class 8. 2 Chapter Objectives Use Swing components to build the GUI for a Swing program Implement an ActionListener to handle events Add interface components.
Developing User Interfaces (DUI) Chris North cs3724: HCI.
Java Applets. Applets The term Applet refers to a little application. In JAVA the applet is a java program that is embedded within a HTML document and.
TCU CoSc Introduction Programming (with Java) Program Development Environment.
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.
CS413: Java Programming language Applications Applets
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
19-Sep-15 Air Force Institute of Technology Electrical and Computer Engineering Object-Oriented Programming Design Topic : Applets Maj Joel Young
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 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.
Learn about the types of Graphics that are available Develop a basic Graphics applet Develop a basic Graphics application Review the Java API and use.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
1 INF160 IS Development Environments AUBG, COS dept Lecture 04 Title: Computer Applications (Extract from Syllabus)
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.
Lesson 36: The calculator – Java Applets. 1. Creating Your First Applet HelloWorldApp is an example of a Java application, a standalone program. Now you.
Java Applets. 2 Introduction to Java Applet Programs  Applications are stand alone programs executed with Java interpreter executed with Java interpreter.
Java GUI building with Swing. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Introduction to Applets Course Lecture Slides 29 th July 2010.
Graphics in Java Starring: NetBeans Co-Starring: Java.awt.
1 Applets and Course Evaluation Applet Example - Sailing Applet UML Diagrams Applet Web Page Encoding (HTML) Applet Java Coding – Hello World Course Evaluation.
Intro to Applets August 19, 2008 Mrs. C. Furman. Java Applets vs. Java Applications Java Applet: a program that is intended for use on the web. Java Applet:
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. 2 Introduction to Java Applet Programs Applications are ___________________ programs –executed with Java interpreter Applet is a small program.
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.
CompSci 100E 35.1 Graphical User Interfaces: GUIs  Components  Flat Layouts  Hierarchical Layouts  Designing a GUI  Coding a GUI.
Java's Graphical User Interface Toolkit
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.
Java Programming Applets. Topics Write an HTML document to host an applet Understand simple applets Use Labels with simple AWT applets Write a simple.
 GUI – Graphic User Interface  Up to now in the programs we have written all output has been sent to the standard output device i.e.: the DOS console.
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.
Your name CSCI/CMPE 3326 Object-Oriented Programming in Java Dongchul Kim Department of Computer Science University of Texas – Pan American 1.Applet.
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.
Creating a Java Application and Applet
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.
Graphical User Interface (GUI)
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.
1 Applets Programming. Introduction Java programs are divided into two main categories, applets and applications. An application is an ordinary Java program.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 17 : Applets King Fahd University of Petroleum & Minerals College of Computer Science.
GUI.1 Graphical User Interfaces GUIs. GUI.2 The Plan Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUI.
Java Applets.
Java Applets.
Chapter 13: Advanced GUIs and Graphics
Distributed Computing, M. L. Liu
Distributed Computing, M. L. Liu
Applets.
UNIT-5.
Java Applets.
Java Applets.
Java applets 1/3/2019.
G6DICP - Lecture 27 Java Applets.
Advanced GUIs and Graphics
Presentation transcript:

Applets

What is an Applet?  According to Sun “An applet is a small program that is intended not to be run on its own, but rather to be embedded inside another application.”

Applet  An applet is a java program that executes using an appletviewer or a java enabled web browser (such as Internet Explorer).  The appletviewer is a utility for applets that is included with the Java SDK.  The appletviewer or web browser only executes an applet when a HTML document containing the applet is opened in the appletviewer or web browser.

Hello World Applet import java.applet.*; import java.awt.*; public class AppletExample extends Applet { public void paint(Graphics g) { g.drawString("Hello World", 50, 25); }//end paint }

Applet  We compile the AppletExample applet using the javac command.  Now we need to create a HTML page file that will include the applet

Basic Applet start  All applets are started via a HTML file </APPLET>  This identifies the name of the main class and the portion of the browser window that should be made available for the applet.

HTML Java Applet This is a HTML file with an embeded applet

Running the Applet  There are two ways of executing the Java applet: 1.Simply double click on the html file which contains the applet. 2.Within the DOS console, use the appletviewer command to execute the applet. E.g. appletviewer Example1.html

OUTPUT

What can an Applet do?  An applet can: –Draw pictures on a web page –Create a new window and draw in it –Play sounds  Multimedia, jpegs’s etc. –Receive input from the user through the keyboard or the mouse –Make a network connection to the server from which it came and can send to and receive arbitrary data from that server.

Applet Security  Main concerns with applets is that the browser downloads code across the network, possibly from an unknown source and executes on the client’s system.  Breeding ground for viruses  As a security measure, the class loader in the Java VM checks the bytecode in the Java class file to make sure they haven’t been tampered with since compilation

Applet Security: What an applet cannot do  Write data on any of the host’s disks.  Read any data from the hosts disks without the users permission. In some environments, notably Netscape, an applet cannot read data from the users disks even with permission.  Delete files.  Read from or write to arbitrary blocks of memory, even on a non-memory protected operating system like the Mac OS. All memory access is strictly controlled.

Applet Security: What an applet cannot do  Java enabled browsers place security features on applets.  IE does not allow applets to access files on the local disk or communicate with systems on the network apart from the web server that provides the HTML page that contains the applet.

Applet Security: What an applet cannot do  An applet provider can sign a Java applet with a digital signature to verify that it comes from a trusted source. If an applet is downloaded by an enabled browser, the client has to decide whether he/she trusts the applet provider. If so, the browser may grant extended powers to the applet.

An applet cannot (continued)  Introduce a virus or trojan horse into the host system.  An applet is not supposed to be able to crash a host system.

Applets vs Applications

GUI Applets  Applets are capable of containing swing GUI components.  It is possible to convert a previously constructed Java application into a Java applet.

Running an Applet class  The applet class is loaded into the VM  The VM creates an object from this class  The VM calls the following methods in the following sequence: –init –start –paint

Entry point methods  init – Executed ONLY at the creation of the applet object. Generally used to setup user interface, variables, etc. (like a constructor)  start - executed each time an appletviewer window is selected as well as at the creation of the object  paint (Graphics) – Used to draw lines/ shapes on the appletviewer window. Can be called at any point by calling ‘repaint()’ which wipes the screen and executes paint again. paint is supplied an object of type graphics which is contains the screen. paint can use methods in this object to draw on the screen.

Converting an Application into an Applet  Remember that an init method of an applet is similar to the main method in an application.  Applications normally are derived from JFrame, whereas Applets are derived from JApplet.  Size and Visibility of the JFrame in an application is set within the application via the setSize and setVisible methods. The size of an Applet should be set within the HTML document  Applets must be declared public.

Example import Java.awt.*; import Java.awt.Window.*; import Java.awt.event.*; import javax.swing.*; class MyApplication extends JFrame { JButton north = new JButton ("North"); JButton south = new JButton ("South"); JButton east = new JButton ("East"); JButton west = new JButton ("West"); JTextArea textArea = new JTextArea(); MyApplication() { setUpGUI(); } public static void main(String[] args) { MyApplication m = new MyApplication(); } void setUpGUI() { Container c = getContentPane(); c.setLayout (new BorderLayout()); c.add (BorderLayout.NORTH, north); c.add (BorderLayout.SOUTH, south); c.add (BorderLayout.EAST, East); c.add (BorderLayout.WEST, West); c.add(BorderLayout.CENTER "Center", new JScrollPane(textArea)); setSize (200,200); setVisible(true); }

Example:Applet /*HTML code necessary to start the Applet <APPLET CODE = "MyJApplet.class" WIDTH= "200" HEIGHT="200"> */

Applet public class MyJApplet extends JApplet { JButton north = new JButton ("North"); JButton south = new JButton ("South"); JButton east = new JButton ("East"); JButton west = new JButton ("West"); JTextArea textArea = new JTextArea(); public void init() { setUpGUI(); } void setUpGUI() { Container c = getContentPane(); c.setLayout (new BorderLayout()); c.add (BorderLayout.NORTH, north); c.add (BorderLayout.SOUTH, south); c.add (BorderLayout.EAST, East); c.add (BorderLayout.WEST, West); c.add(BorderLayout.CENTER "Center", new JScrollPane(textArea)); setSize (200,200); setVisible(true); }