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.

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

The World Wide Web. 2 The Web is an infrastructure of distributed information combined with software that uses networks as a vehicle to exchange that.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 - Introduction to Java Applets Outline 3.1 Introduction 3.2 Sample Applets from the Java 2.
Chapter 11 Introduction to Computers and Java Chapter 1.
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.
Slides prepared by Rose Williams, Binghamton University Chapter 19 Swing II.
Slides prepared by Rose Williams, Binghamton University Chapter 18 Applets.
Chapter 14 Applets. 2 Knowledge Goals Understand the differing roles of applications and applets Understand how a browser operates Understand the role.
Java Applets. Lecture Objectives Learn about Java applets. Know the differences between Java applets and applications. Designing and using Java applets.
Java Applets. Road Map Introduction to Java Applets Review applets that ship with JDK Make our own simple applets –Introduce inheritance –Introduce the.
1 L44 Introduction to Java Applets. 2 OBJECTIVES  To differentiate between applets and applications.  To observe some of Java's exciting capabilities.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 14 Applets, Images,
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 16 : Swing VI Graphics King Fahd University of Petroleum & Minerals College of Computer.
Chapter 3 - Introduction to Java Applets Outline 3.1Introduction 3.2Thinking About Objects 3.4A Simple Java Applet: Drawing a String 3.5Two More Simple.
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. Lecture Objectives  Learn about Java applets.  Know the differences between Java applets and applications.  Designing and using Java.
Java Programming, 2E Introductory Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
Java How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 16: Java Applets & AWT Fundamentals of Web Programming.
Chapter 16 The World Wide Web. 2 The Web An infrastructure of information combined and the network software used to access it Web page A document that.
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.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 14: Applets and More Starting Out with Java: From Control Structures.
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.
Java Applets. 2 Introduction to Java Applet Programs  Applications are stand alone programs executed with Java interpreter executed with Java interpreter.
Chapter 8 Introduction to HTML and Applets Fundamentals of Java.
Chapter 13. Applets and HTML HTML Applets Computer Programming with JAVA.
Introduction to Java Applets Sangeetha Parthasarathy 05/21/2001.
1 CSC Computer Education (P) Ltd. DESIGNED BY K PRAKASH,
Java Applets. 2 Introduction to Java Applet Programs Applications are ___________________ programs –executed with Java interpreter Applet is a small program.
Lec.10 + (Chapter 8 & 9) GUI Java Applet Jiang (Jen) ZHENG July 6 th, 2005.
Introduction to Java Simple Graphics. Objects and Methods Recall that a method is an action which can be performed by an object. –The action takes place.
Chapter 2: Color and Applets Coming up: Introduction to Graphics.
4 Chapter Four Introduction to HTML. 4 Chapter Objectives Learn basic HTML commands Discover how to display graphic image objects in Web pages Create.
LEARNING HTML PowerPoint #1 Cyrus Saadat, Webmaster.
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.
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
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.
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.
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.
HTML Basics. HTML Coding HTML Hypertext markup language The code used to create web pages.
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.
1 Introduction to Graphics b The last one or two sections of each chapter of the textbook focus on graphical issues b Most computer programs have graphical.
CHAPTER 14 Applets and More Copyright © 2016 Pearson Education, Inc., Hoboken NJ.
HTML-I Basic HTML Elements. HTML (Hyper Text Markup Language) HTML is a document layout and hyperlink- specification language. i.e. a language used to.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 - Introduction to Java Applets Will not cover Section 3.7 Thinking About Objects: Identifying.
1 Applets Programming. Introduction Java programs are divided into two main categories, applets and applications. An application is an ordinary Java program.
CHAPTER 14 Applets and More Copyright © 2016 Pearson Education, Ltd.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 17 : Applets King Fahd University of Petroleum & Minerals College of Computer Science.
Glencoe Introduction to Web Design Chapter 4 XHTML Basics 1 Review Do you remember the vocabulary terms from this chapter? Use the following slides to.
Chapter 8 Introduction to HTML and Applets
Chapter 23 Applets and Java Web Start
Java Applets.
Distributed Computing, M. L. Liu
Distributed Computing, M. L. Liu
Introduction to Computers and Java
4.14 GUI and Graphics Case Study: Creating Simple Drawings (Cont.)
UNIT-5.
Java Applets.
Handout-14 Applets and Graphics
Presentation transcript:

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 placed on applets by the browser’s JVM  What is JVM?  the fundamentals of HTML and how to create a simple Web page  how to write a simple applet and execute it from a Web page or with the applet viewer program

2 Introduction to Applets  There are two types of programs you can create with Java:  applications  applets.  An application is a stand-alone program that runs on your computer.  Applets are Java programs that are usually part of a Web site.  If a user opens the Web site with a Java- enabled browser, the applet is executed inside the browser window.

3 Introduction to Applets  It appears to the user that the applet is part of the Web site.  Applets are stored on a Web server along with the site’s Web pages.  Applets associated with a viewed web page are transmitted to the user’s system.  Once the applets are transmitted, the user’s system executes them.  Applets can be used to extend the capabilities of a Web page.

4 Introduction to Applets  Web pages are normally written in Hypertext Markup Language (HTML).  HTML is static content; whereas, applets are dynamic.  An applet does not have to be on a web server in order to be executed.  They can be stored on the local computer.

5 Applet Limitations  Applets run on the user’s system, NOT the server.  For security purposes, applets can not:  access the local computer file system,  run any other program on the user’s system.  execute operating system procedures.  retrieve information about the user or their system.  make network connections with any system except the server from which the applet was transmitted.  run anonymously.  If an applet displays a window, it will automatically have a message such as “Warning: Applet Window” displayed in it.

6 Introduction to HTML  Hypertext Markup Language (HTML) is the language that Web pages are written in.  Hypertext can contain a link to other content on the web page, or another web page.  A Markup Language allows you to “mark up” a text file by inserting special instructions.  These instructions tell the browser how to format the text and create any hypertext links.  To make a web page, create a text file:  that contains HTML instructions (known as tags),  the text that should be displayed on the Web page, and  typically has a.htm or.html file extension.

7 to HTML Introduction to HTML  This document is called an HTML document.  The tags instruct the browser:  how to format the text,  where to place images,  what to do when the user clicks on a link, etc.  Most HTML tags have an opening tag and a closing tag.  Text  Text  The tags are enclosed in angle brackets ( ).  The closing tag is preceded by a forward slash (/).

8 Document Structure Tags  The tag marks the beginning and ending of an HTML document.  The tag marks the document head, a section containing information about the document.  The document head contains the tag, which is contains the title of the document.

9 Document Structure Tags  After the document head comes the tag.  The document body contains all of the tags and text that produce output in the browser.

10 Creating Applets With Swing  Applets are very similar to the GUI applications.  Hmmmm, what’s a GUI???  Instead of displaying its own window, an applet appears in the browser’s window.  The applet code are:  The differences applet code are:  A GUI application class is derived from JFrame.  An applet class is derived from JApplet.  The JApplet class is part of the javax.swing package.

11 Creating Applets With Swing  A GUI application class has a constructor that creates other components and sets up the GUI.  An applet class does not normally have a constructor.  Instead, it has a method named init that performs the same operations as a constructor.  I know this is confusing, just remember that the two are different.  GUI Application class ≠ to Applet class

12 Creating Applets With Creating Applets With Swing  The differences applet code are (continued):  The following methods are not called in an applet:  super  setSize  setDefaultCloseOperation  pack  setVisible  No main method is needed to create an Applet object.  The browser creates an instance of the class automatically.  Example:  SimpleApplet.java SimpleApplet.java  SimpleApplet.html Here are the print outs. SimpleApplet.html

13 Running an Applet  The process of running an applet is different from that of running an application.  To run an applet, create an HTML document with an APPLET tag, which has the following general format: <APPLET CODE="Filename.class" CODE="Filename.class" WIDTH=“width_value” WIDTH=“width_value” HEIGHT=“height_value”> HEIGHT=“height_value”>  Don’t forget the closing angle bracket.  Attributes should be enclosed in quotes.

14 Running an Applet  Filename.class is the compiled bytecode of the applet, not the.java file.  You can optionally specify a path along with the file name.  If you specify only the file name, it is assumed that the file is in the same directory as the HTML  The browser:  loads specified byte code, and  executes it in an area that is the size specified by the width_value and height_value.

15 Using Appletviewer  The appletviewer program loads and executes an applet without the need for a Web browser.  When running the program, specify the name of an HTML document as a command line argument. appletviewer SimpleApplet.html  This command executes any applet referenced by an APPLET tag in the file SimpleApplet.html.  If the document has more than one APPLET tag, it will execute each applet in a separate window.  Let’s look at an example…..

16 Drawing on Panels  The paintComponent method serves the same purpose as the paint method.  When it is called, the component’s Graphics object is passed as an argument. public void paintComponent(Graphics g)  When overriding this method, first call the base class’s paintComponent method. super.paintComponent(g);

17 A Sample Graphics Applet  View sample program Listing 1.2 sample program sample program  class HappyFace (page 33) Sample screen output

18 A Sample Graphics Applet  The paint method specifies what is drawn in the applet.  The paint method is invoked automatically when the applet is run.

19 Screen Coordinate System  Figure 1.6

20 Screen Coordinate System  The x-coordinate is the number of pixels from the left.  The y-coordinate is the number of pixels from the top (not from the bottom).

21 Drawing Ovals and Circles  The drawOval method draws only the outline of the oval. canvas.drawOval(100, 50, 90, 50); canvas.drawOval(100, 50, 90, 50);  The fillOval method draws a filled-in oval. canvas.fillOval(100, 50, 90, 50); canvas.fillOval(100, 50, 90, 50);

22 Drawing Ovals & Circles  The drawOval and fillOval methods take four arguments.  The first two arguments indicate the upper-left corner of an invisible rectangle around the oval.  The last two arguments indicate the width and height of the oval.  A circle is just an oval whose height is the same as its width.

23 Drawing Ovals and Circles  Figure1.7 The Oval Drawn by canvas.drawOval(100, 50, 90, 50)

24 Size and Positions of Figures  Sizes and positions in a Java applet are given in pixels.  Think of the display surface for the applet as being a two-dimensional grid of individual pixels.

25 Drawing Arcs  The drawArc method draws an arc. drawArc(100, 50, 200, 200, 180, 180); drawArc(100, 50, 200, 200, 180, 180);  The drawArc method takes six arguments.  The first four arguments are the same as the four arguments needed by the drawOval method.  The last two arguments indicate where the arc starts, and the number of degrees through which is sweeps.  0 degrees is horizontal and to the right.

26 Specifying an Arc  Figure 1.8a

27 Specifying an Arc  Figure 1.8b

28 Running and Closing an Applet  There are two ways to run an applet:  Embed the applet in a Web page and run it  Use an applet viewer from the IDE .  There are two corresponding ways to end an applet:  If you are running the applet from a web site, close the page or navigate away from the page  If you are using an applet viewer, use the mouse to click the close-window button.

29 Your Turn  You will have your turn.  First, making the Happy face.  Then, Page 39 Exercise 8.  Now, for starting Chapter 2.