Slides prepared by Rose Williams, Binghamton University Chapter 18 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.
Slides prepared by Rose Williams, Binghamton University Chapter 17 Swing I.
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
Slides prepared by Rose Williams, Binghamton University Chapter 17 Swing I.
Slides prepared by Rose Williams, Binghamton University Chapter 17 Swing I.
Slides prepared by Rose Williams, Binghamton University Chapter 19 Swing II.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 16 Applets.
Slides prepared by Rose Williams, Binghamton University Chapter 13 Interfaces and Inner Classes.
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.
Slides prepared by Rose Williams, Binghamton University Chapter 18 Applets.
Chapter 1 The Facts to Be Explained. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 1-2.
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,
Unit 111 Java GUI Components and Events  Learning Outcomes oDistinguish between GUI components and containers. oIdentify and distinguish top-level containers.
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.
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.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved COS240 Object-Oriented Languages.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
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 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
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
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.
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.
Chapter 8 Introduction to HTML and Applets Fundamentals of Java.
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.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 13 : Swing I King Fahd University of Petroleum & Minerals College of Computer Science.
1 Applets and Course Evaluation Applet Example - Sailing Applet UML Diagrams Applet Web Page Encoding (HTML) Applet Java Coding – Hello World Course Evaluation.
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,
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved COS240 O-O Languages AUBG,
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.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
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.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 15 : Swing III King Fahd University of Petroleum & Minerals College of Computer.
Slides prepared by Rose Williams, Binghamton University Chapter 19 Swing II.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
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.
Chapter 14 Applets. Applets: Introduction Java programs are divided into two main categories, applets and applications An application is an ordinary Java.
Java Applets.
Java Applets.
Java Applets.
Chapter 13: Advanced GUIs and Graphics
Applets.
Java Applets.
Java Applets.
Chapter 13 Applets and HTML HTML Applets.
JAVA APPLET PREPARED BY Mr. Jahanzaib Ahmed
Advanced GUIs and Graphics
Presentation transcript:

Slides prepared by Rose Williams, Binghamton University Chapter 18 Applets

© 2004 Pearson Addison-Wesley. All rights reserved18-2 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

© 2004 Pearson Addison-Wesley. All rights reserved18-3 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

© 2004 Pearson Addison-Wesley. All rights reserved18-4 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

© 2004 Pearson Addison-Wesley. All rights reserved18-5 Applets in the Class Hierarchy

© 2004 Pearson Addison-Wesley. All rights reserved18-6 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

© 2004 Pearson Addison-Wesley. All rights reserved18-7 Designing an Applet 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

© 2004 Pearson Addison-Wesley. All rights reserved18-8 An Applet (Part 1 of 2)

© 2004 Pearson Addison-Wesley. All rights reserved18-9 An Applet (Part 2 of 2)

© 2004 Pearson Addison-Wesley. All rights reserved18-10 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

© 2004 Pearson Addison-Wesley. All rights reserved18-11 How Applets Differ from Swing GUIs 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

© 2004 Pearson Addison-Wesley. All rights reserved18-12 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

© 2004 Pearson Addison-Wesley. All rights reserved18-13 Running an Applet 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

© 2004 Pearson Addison-Wesley. All rights reserved18-14 Applet Examples examples.html

© 2004 Pearson Addison-Wesley. All rights reserved18-15 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

© 2004 Pearson Addison-Wesley. All rights reserved18-16 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 1.Derive the class from the class JApplet instead of from the class Jframe 2.Remove the main method 3.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

© 2004 Pearson Addison-Wesley. All rights reserved18-17 Tip: Converting a Swing Application to an Applet 4.Delete any invocation of super 5.Delete any method invocations that program the close-window button of a windowing GUI 6. Delete any invocation of setTitle 7.Delete any invocation of setSize The following applet was generated in this way

© 2004 Pearson Addison-Wesley. All rights reserved18-18 An Applet Calculator (Part 1 of 9)

© 2004 Pearson Addison-Wesley. All rights reserved18-19 An Applet Calculator (Part 2 of 9)

© 2004 Pearson Addison-Wesley. All rights reserved18-20 An Applet Calculator (Part 3 of 9)

© 2004 Pearson Addison-Wesley. All rights reserved18-21 An Applet Calculator (Part 4 of 9)

© 2004 Pearson Addison-Wesley. All rights reserved18-22 An Applet Calculator (Part 5 of 9)

© 2004 Pearson Addison-Wesley. All rights reserved18-23 An Applet Calculator (Part 6 of 9)

© 2004 Pearson Addison-Wesley. All rights reserved18-24 An Applet Calculator (Part 7 of 9)

© 2004 Pearson Addison-Wesley. All rights reserved18-25 An Applet Calculator (Part 8 of 9)

© 2004 Pearson Addison-Wesley. All rights reserved18-26 An Applet Calculator (Part 9 of 9)