Java Applets.

Slides:



Advertisements
Similar presentations
Learn about Java applets. Know the differences between Java applets and applications. Designing and using Java applets Running Java applets. Security.
Advertisements

Dept. of Computer Science - SSBN Java Applets Vishnuvardhan.M.
Slides prepared by Rose Williams, Binghamton University Mouse Events + Chapter 17: Applets.
Applets. The Applet Class public class MyApplet extends java.applet.Applet {... /** The no-arg constructor is called by the browser when the Web page.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 16 Applets.
1 Applets. 2 Motivations When browsing the Web, you frequently see the graphical user interface and animation developed using Java. These programs are.
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.
Chapter 12Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Announcements/Reminders l Happy Tax Day! l Project 8 due on Thursday.
Chapter 14 Applets. 2 Knowledge Goals Understand the differing roles of applications and applets Understand how a browser operates Understand the role.
Slides prepared by Rose Williams, Binghamton University Chapter 18 Applets.
Java Applets. Lecture Objectives Learn about Java applets. Know the differences between Java applets and applications. Designing and using Java applets.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 14 Applets, Images,
Chapter 131 Applets and HTML Chapter Reminders Project 8 due Dec 10:30 pm Project 6 regrades due by midnight tonight –Submit all files (including.
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.
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.
HTML Companion. Lecture Objectives Learn about HTML. Know basic HTML tags.
Object Oriented Programming (OOP) LAB # 5 TA. Maram & TA. Mubaraka TA. Kholood & TA. Aamal.
Chapter 20 Applets Slides prepared by Rose Williams, Binghamton University Copyright © 2008 Pearson Addison-Wesley. All rights reserved.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L05 (Chapter 16) Applets.
Applets, HTML and GUI’s Recitation – 04/11/2008 CS 180 Department of Computer Science, Purdue University.
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.
Java Applets. Lecture Objectives  Learn about Java applets.  Know the differences between Java applets and applications.  Designing and using Java.
Chapter 13Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 13 l HTML l Applets Applets and HTML.
19-Sep-15 Air Force Institute of Technology Electrical and Computer Engineering Object-Oriented Programming Design Topic : Applets Maj Joel Young
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.
JAPPLET.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
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.
Putting Applets into Web Pages.  Two things are involved in the process of putting applets onto web pages ◦ The.class files of the applet ◦ The html.
Chapter 8 Introduction to HTML and Applets Fundamentals of Java.
1 Week 1 l HTML l Applets Applets and HTML. 2 Overview l Applets: Java programs designed to run from a document on the Internet l HTML: Hypertext Markup.
Chapter 13. Applets and HTML HTML Applets Computer Programming with JAVA.
Chapter 13Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 13 l HTML l Applets Applets and HTML.
Pravin Yannawar, DOCS, NMU Jalgaon Basic Java : Applets 2 Objectives of This Session Identify the need for Applets Distinguish between Applets and Applications.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 16 Applets and Multimedia.
Chapter 12Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Announcements/Reminders l Next week: »No Lectures »No Labs »Recitation.
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.
Creating Applets. What is an applet? What is an applet? A Java program that runs in a web browser. A Java program that runs in a web browser. An 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.
Chapter 131 Applets and HTML Chapter Objectives learn how to write applets learn to write a simple HTML document learn how to embed an applet in.
Applets, Images, and Audio Chapter 14 CSCI CSCI 1302 – Applets, Images, and Audio2 Outline Introduction The Applet Class –The init Method –The start.
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.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
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.
Chapter 14 Applets. Applets: Introduction Java programs are divided into two main categories, applets and applications An application is an ordinary Java.
Applications Active Web Documents Active Web Documents.
Chapter 8 Introduction to HTML and Applets
A First Look at GUI Applications
Java Applets.
Chapter 13: Advanced GUIs and Graphics
Distributed Computing, M. L. Liu
Distributed Computing, M. L. Liu
Applets and HTML Chapter 13.
Applets.
UNIT-5.
Introduction to Computing Using Java
Java Applets.
Java Applets.
Java applets 1/3/2019.
Chapter 13 Applets and HTML HTML Applets.
JAVA APPLET PREPARED BY Mr. Jahanzaib Ahmed
G6DICP - Lecture 27 Java Applets.
Advanced GUIs and Graphics
Presentation transcript:

Java Applets

Lecture Objectives Learn about Java applets. Know the differences between Java applets and applications. Designing and using Java applets Running Java applets. Security issues with Java applets.

Introduction Java programs are divided into two main categories, applets and applications. An application is an ordinary Java program. An applet is a kind of Java program that can be run across the Internet.

Programming Applets The word applet is meant to suggest a small application. Applets were intended to be small programs run over the Internet: However, there are no size constraints on applets. Applets can be viewed over the Internet, or without any connection to the internet. An applet is similar to a Swing GUI: In fact, almost all of the Swing techniques can be used in applets.

Defining an Applet An applet class is normally defined as a derived class of the class Japplet. The class JApplet is in the package javax.swing. There is also an older class, Applet, which has been superseded by the JApplet class.

Applets in the Class Hierarchy

Designing an Applet An applet class can be designed as a derived class of JApplet in much the same way that regular Swing GUIs are defined as derived classes of Jframe. However, an applet normally defines no constructors. The method init performs the initializations that would be performed in a constructor for a regular Swing GUI

Designing an Applet (Cont’d) Components can be added to an applet in the same way that a component is added to a JFrame The method add is used to add components to an applet in the same way that components are added to a JFrame

Java Applets: An Example 16 } Output using an applet viewer

How Applets Differ from Swing GUIs? Some of the items included in a Swing GUI are not included in an applet Applets do not contain a main or setVisible method Applets are displayed automatically by a Web page or an applet viewer Applets do not have titles Therefore, they do not use the setTitle method They are normally embedded in an HTML document, and the HTML document can add any desired title

How Applets Differ from Swing GUIs? (Cont’d) Applets do not use the setSize method The HTML document takes care of sizing the applet Applets do not have a close-window button Therefore, they do not have a setDefaultCloseOperation method When the HTML document containing the applet is closed, then the applet is automatically closed

Running an Applet An applet class is compiled in the same way as any other Java class However, an applet is run differently from other Java programs The normal way to run an applet is to embed it in an HTML document The applet is then run and viewed through a Web browser

Running an Applet (Cont’d) An applet can also be viewed using an applet viewer An applet viewer is a program designed to run an applet as a stand-alone program The Java appletviewer can be used to run an applet: appletviewer FirstApplet.html It may be necessary, however, to create the HTML document, and place the applet in it

Menus in a JApplet Menus are constructed and added to a JApplet as they are for a Jframe JApplet has a method named setJMenuBar that behaves the same as the setJMenuBar method of a JFrame JApplet can also have menu bars added to a JApplet or to a panel that is part of the JApplet using the add method

Tip: Converting a Swing Application to an Applet The fastest and easiest way to explain how to define an applet, is to explain how to modify a Swing GUI to transform it into an applet Derive the class from the class JApplet instead of from the class Jframe Remove the main method Replace the constructor with a no-parameter method named init The body of the init method can be the same as the body of the deleted constructor, but with some items removed

Tip: Converting a Swing Application to an Applet (2) Delete any invocation of super Delete any method invocations that program the close-window button of a windowing GUI Delete any invocation of setTitle Delete any invocation of setSize The following applet was generated in this way.

The Applet Calculator

Icons: Reminder An icon is a picture It is typically, but not always, a small picture An icon can be stored in a file of many different standard formats Such as .gif, .tiff, or .jpg The class ImageIcon is used to convert a picture file to a Swing icon Then it can be added as a component to any Container class, such as JApplet The class ImageIcon is in the javax.swing package ImageIcon NameOfImageIcon = new ImageIcon("PictureFileName");

Adding Icons to an Applet The easiest way to display an icon in an applet is to place it in a JLabel The following three lines create a label, create an icon, and then add the icon to the label: JLabel aLabel=new JLabel("Welcome to my applet."); ImageIcon dukeIcon = new ImageIcon("duke_waving.gif"); aLabel.setIcon(dukeIcon);

An Applet with an Icon Output using an applet viewer

Inserting an Applet in an HTML Document An applet can be placed in an HTML document with an applet tag: <applet code="PathToApplet" width=Number1 height=Number2> </applet> If given a .class file name only, then the HTML file and the applet file must be in the same directory The PathToApplet can be a full or relative path name

Inserting an Applet in an HTML Document (Cont’d) Note that the name of the .class file, not the .java file, is given Note also that the width and height of the applet is given in this command, and not within the applet class definition The width and height are in pixels The following code, when placed in an HTML document, will display the calculator applet in a browser as shown <applet code="AppletCalculator.class" width=400 height=300> </applet>

An Applet in an HTML Document <head> <title> Vampire Control </title> </head> . . . <applet code="AppletCalculator.class" width=400 height=300> </applet> </html>

The Browser View of Applets

Pitfall: Using an Old Web Browser An old browser may not be able to run applets from an HTML document: Even if a java application runs correctly on the same system. Web browsers do not use the same Java Virtual Machine used to run regular Java applications. An old browser will have an old Java Virtual Machine, or perhaps, no Java Virtual Machine. However, an applet viewer will work, as long as a recent version of Java is installed.

Applets and Security An applet can be a program, written by someone else, that runs on your computer. Whenever someone else's program runs on your computer, there are security questions you should ask: Will it read information from your files? Will it corrupt your operating system? Applets are designed so that they cannot do any of these things (at least easily).