复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 14 Applets, Images, and Audio

Chapter 14 Applets Images and audio Prerequisites for part工工工 hapter 8 Inheritance and polymorphism Chapter 9 Abstract Classes and Interfaces Chapter 11 Getting Started with GUI Programmin Chapter 12 Event-Driven Programming 愿生如夏花之绚烂,死如秋叶之静美-泰戈尔 Chapter 13 Creating User Interfaces hapter 14 Applets, Images, Audio Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 1 Chapter 14 Applets, Images, and Audio Prerequisites for Part III Chapter 11 Getting Started with GUI Programming Chapter 8 Inheritance and Polymorphism Chapter 13 Creating User Interfaces Chapter 14 Applets, Images, Audio Chapter 9 Abstract Classes and Interfaces Chapter 12 Event-Driven Programming 愿生如夏花之绚烂,死如秋叶之静美---- 泰戈尔

Objectives To explain how the Web browser controls and executes applets(s 14.2) To describe the init, start, stop, and destroy methods in the applet class ( s 142) To know how to embed applets in Web pages(s 14.4) To run applets from appletviewer and from Web browsers(s 14.4) To pass string values to applets from htMl(8 14.5) To write a Java program that can run as both an application and an applet( s 146) To get image files using the uRl class and display images in the panel( s 14.oPtional) To develop a reusable component Image Viewer to display images(s 14.10 Optional To get audio files and play sound(s 14 12 Optional) To package and deploy Java projects using Java archive files (s 14.13 Optional) o To use Swing pluggable look-and-feel (8 14 14 Optional) Liang, Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 2 Objectives ⚫ To explain how the Web browser controls and executes applets (§ 14.2). ⚫ To describe the init, start, stop, and destroy methods in the Applet class (§ 14.2). ⚫ To know how to embed applets in Web pages (§ 14.4). ⚫ To run applets from appletviewer and from Web browsers (§ 14.4). ⚫ To pass string values to applets from HTML (§ 14.5). ⚫ To write a Java program that can run as both an application and an applet (§ 14.6). ⚫ To get image files using the URL class and display images in the panel (§ 14.9 Optional). ⚫ To develop a reusable component ImageViewer to display images (§ 14.10 Optional). ⚫ To get audio files and play sound (§ 14.12 Optional). ⚫ To package and deploy Java projects using Java archive files (§ 14.13 Optional). ⚫ To use Swing pluggable look-and-feel (§ 14.14 Optional)

Introduction pple PRogram that runs in Applet Container e appletviewer(test utility for applets) Web browser (IE, Communicator) OExecutes when HTML(Hypertext Markup Language) document containing applet is opened and downloaded O Applications run in command windows Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 3 Introduction ⚫Applet Program that runs in Applet Container ⚫appletviewer (test utility for applets) ⚫Web browser (IE, Communicator) Executes when HTML (Hypertext Markup Language) document containing applet is opened and downloaded Applications run in command windows

Launching applets o Applications are http://somelocation/file.html started by a call to the main method HTML file ● Applets have no main method o Class file referenced in Applet Classes the html document Locationhttp://somelocation/file.html Browser loads and Browser runs the applet OJDK includes the Loading. appletviewer application Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai -kaiyu 4 Launching applets ⚫ Applications are started by a call to the main method ⚫ Applets have no main method ⚫ Class file referenced in the HTML document ⚫ Browser loads and runs the Applet ⚫ JDK includes the appletviewer application

The TicTacToe Applet ● You start as player"ⅹ" Fig 3.2 Sample execution of the TicTactoe applet Ap回冈國Ap回囻Ap图匾Ap回冈國Ap□回区 Applet Applet 又。 XI XOX XOX X。 Applet started Applet started Applet started Applet started Applet started Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 5 The TicTacToe Applet ⚫You start as player "X" Fig. 3.2 Sample execution of the TicTacToe applet

The Draw Test Applet Fig 3. 4 mple execution of applet Drawfest Applet Viewer: DrawTest class 口区 Radio Combo button Box Cc回Rots Applet started
Liang,Introduction to Java Programming,revised by Dai-kaiyu 6 The DrawTest Applet Fig. 3.4 Sample execution of applet DrawTest. Combo Box Radio button

The Applet class public class MyApplet extends java applet Applet i /* The no-arg constructor is called by the browser when the web page containing this applet is initially loaded, or reloaded ublic Myappleto i /** Called by the browser after the applet is loaded public void inito /* Called by the browser after the inito method, or every time the web page is visited public void start t /* Called by the browser when the page containing this applet becomes inactive public void stop i /* Called by the browser when the web browser exits */ public void destroyo t /* Other methods if necessary .*/
Liang,Introduction to Java Programming,revised by Dai-kaiyu 7 The Applet Class public class MyApplet extends java.applet.Applet { ... /** The no-arg constructor is called by the browser when the Web page containing this applet is initially loaded, or reloaded */ public MyApplet() { ... } /** Called by the browser after the applet is loaded */ public void init() { ... } /** Called by the browser after the init() method, or every time the Web page is visited */ public void start() { ... } /** Called by the browser when the page containing this applet becomes inactive */ public void stop() { ... } /** Called by the browser when the Web browser exits */ public void destroy() { ... } /** Other methods if necessary... */ }

The Applet class cont when the applet is loaded the Web browser creates an instance of the applet by invoking the applets no-arg constructor o The browser uses the init, start, stop, and destroy methods to control the applet. By default, these methods do nothing. To perform specific functions, they need to be modified in the user's applet so that the browser can call your code properly See figure14.1(a)in textbook Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 8 The Applet Class, cont. ⚫When the applet is loaded, the Web browser creates an instance of the applet by invoking the applet’s no-arg constructor. ⚫ The browser uses the init, start, stop, and destroy methods to control the applet. By default, these methods do nothing. To perform specific functions, they need to be modified in the user's applet so that the browser can call your code properly. See figure14.1 (a) in textbook

11.4.2 Applet lifecycle methods o initO, start, stop), destroy The browser calls this method first initO is called when the applet is loaded User pages back The init() method to your page ompletes and thestarto start is called by method excutes. The start User maximizes method calls the paint() init. and when the start() applet executes user returns to the user interacts aint( with applet and methods that page handles use events execute stope is called when bepaint is el the User pages to another page the user leaves the ca to the spds d User minimizes browser method and then finally to the paint() stop) page destroyo is called destroy() when the browser is closed Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 9 11.4.2 Applet lifecycle methods ⚫ init(), start(), stop(), destroy() ⚫ init() is called when the applet is loaded ⚫ start() is called by init, and when the user returns to the page ⚫ stop() is called when the user leaves the page ⚫ destroy() is called when the browser is closed

Browser Calling Applet Methods - Loaded JVMloads the B applet ci the applet Created B rowser invokes initO Initialized Browser Browser invokes start invokes stop Started Stopped Browser invokes stop Destroyed)destroye nokes B Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 10 Browser Calling Applet Methods Loaded Initialized Browser invokes init() Started Stopped Destroyed Created Browser creates the applet JVM loads the applet class Browser invokes stop() Browser invokes start() Browser invokes stop() Browser invokes destroy()
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 13 Creating User Interfaces.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 12 Event-Driven Programming.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 11 Getting Started with GUI Programming.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 10 Object-Oriented Modeling(oom).ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 9 Abstract Classes and Interfaces.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 8 Inheritance and Polymorphism.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 7 String.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 6 Objects and Classes.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 5 Arrays.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 4 Methods.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 3 Control Statements.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 2 Primitive Data Types and Operations.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 1 Introduction to Computers, Programs, and Java.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 0 course intro Programming Language(Using Java).ppt
- 复旦大学:《程序设计》课程教学资源(Java Lab)Game of Life_题目要求.pdf
- 复旦大学:《程序设计》课程教学资源(Java Lab)Game of Life.ppt
- 复旦大学:《程序设计》课程教学资源(Java Lab)验证哥德巴赫猜想.ppt
- 复旦大学:《程序设计》课程教学资源(Java Lab)Ansi Temple.ppt
- 复旦大学:《程序设计》课程教学资源(Java Lab)富人Smith的生日 If else Switch.ppt
- 复旦大学:《程序设计》课程教学资源(Java Lab)3.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 15 Exceptions and Assertions.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 16 Simple Input and Output.ppt
- 复旦大学:《信息安全》教学课件_01 Classical Encryption Techniques.pdf
- 复旦大学:《信息安全》教学课件_02 Classical Encryption Techniques(cont.).pdf
- 复旦大学:《信息安全》教学课件_03 Modern Block Ciphers.pdf
- 复旦大学:《信息安全》教学课件_04 Public Key Cryptography, RSA.pdf
- 复旦大学:《信息安全》教学课件_05 Message authentication and Hash function.pdf
- 复旦大学:《信息安全》教学课件_06 The Intro to Information Security.pdf
- 复旦大学:《信息安全》教学课件_07-08 Public Key Infrastructure(PKI)公钥基础设施——公钥技术的应用.pdf
- 复旦大学:《信息安全》教学课件_09 Authentication and supplements.pdf
- 复旦大学:《信息安全》教学课件_10 Authentication Kerberos.pdf
- 复旦大学:《信息安全》教学课件_11.1 IP Security.pdf
- 复旦大学:《信息安全》教学课件_11.2 Web & EC Security.pdf
- 复旦大学:《信息安全》教学课件_12-13 Software Security.pdf
- 复旦大学:《信息安全》教学课件_14 防火墙 Firewall.pdf
- 复旦大学:《信息安全原理》课程教学资源(PPT课件)第1章 信息系统安全概述、第2章 密码学概论(1/3).pdf
- 复旦大学:《信息安全原理》课程教学资源(PPT课件)第2章 密码学概论(2/3).pdf
- 复旦大学:《信息安全原理》课程教学资源(PPT课件)第3章 现代加密算法(2/3).pdf
- 复旦大学:《信息安全原理》课程教学资源(PPT课件)第3章 现代加密算法(2/4).pdf
- 复旦大学:《信息安全原理》课程教学资源(PPT课件)第3章 现代加密算法(3/4).pdf