《Introduction to Java Programming》课程PPT教学课件(Sixth Edition)Chapter 16 Applets and Multimedia

Chapter 16 Applets and multimedia Chapter 12 GUI Basics §10.2,“ Abstract Classes," in Chapter10 Chapter 13 Graphics Chapter 14 Event-Driven programming $10.4, "Inter faces, in Chapter 10 Chapter 15 Creating User Inter faces Chapter 16 Applets and Multimedia Liang, Introduction to Java Programming, Sixth Edition, (c)2005 Pearson Education, Inc. All rights reserved. 0-13-148952-6
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved. 0-13-148952-6 1 Chapter 16 Applets and Multimedia Chapter 12 GUI Basics Chapter 14 Event-Driven Programming Chapter 15 Creating User Interfaces §1 0.2, “Abstract Classes,” in Chapter 1 0 Chapter 13 Graphics Chapter 16 Applets and Multimedia §1 0.4, “Interfaces,” in Chapter 1 0

Objectives To explain how the Web browser controls and executes applets($ 15.2) To describe the init, start, stop, and destroy methods in the applet class (s 15.2) To know how to embed applets in Web pages(8 15.4 To run applets from appletviewer and from Web browsers($ 15.4) To pass string values to applets from HTML(8 15.5) To write a Java program that can run as both an application and an applet(s 156) To get image files using the uRl class and display images in the panel (8 15.9 Optional) To develop a reusable component Image Viewer to display images($ 15.10 Optional) To get audio files and play sound(s 15 12 Optional) To package and deploy Java projects using Java archive files(8 15.13 Optional) To use Swing pluggable look-and-feel (8 15.14 Optional) Liang, Introduction to Java Programming, Sixth Edition, (c)2005 Pearson Education, Inc. All rights reserved. 0-13-148952-6
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved. 0-13-148952-6 2 Objectives To explain how the Web browser controls and executes applets (§ 15.2). To describe the init, start, stop, and destroy methods in the Applet class (§ 15.2). To know how to embed applets in Web pages (§ 15.4). To run applets from appletviewer and from Web browsers (§ 15.4). To pass string values to applets from HTML (§ 15.5). To write a Java program that can run as both an application and an applet (§ 15.6). To get image files using the URL class and display images in the panel (§ 15.9 Optional). To develop a reusable component ImageViewer to display images (§ 15.10 Optional). To get audio files and play sound (§ 15.12 Optional). To package and deploy Java projects using Java archive files (§ 15.13 Optional). To use Swing pluggable look-and-feel (§ 15.14 Optional)

The JApplet Class The applet class is an awt class and is not designed to work with Swing components. To use Swing components in Java applets, it is necessary to create a Java applet that extends javax. swing JApplet, which is a subclass of java applet applet. JApplet inherits all the methods from the applet class. In addition, it provides support for laying out Swing components Liang, Introduction to Java Programming, Sixth Edition, (c)2005 Pearson Education, Inc. All rights reserved. 0-13-148952-6
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved. 0-13-148952-6 3 The JApplet Class The Applet class is an AWT class and is not designed to work with Swing components. To use Swing components in Java applets, it is necessary to create a Java applet that extends javax.swing.JApplet, which is a subclass of java.applet.Applet. JApplet inherits all the methods from the Applet class. In addition, it provides support for laying out Swing components

First Simple applet //WelcomeApplet java: Applet for displaying a message import javax. swing. *i public class WelcomeApplet extends JApplet I /* Initialize the applet * public void init() add (new JLabel(" Welcome to Java, JLabel center))i WelcomeApplet java: Applet for displaying a message import javax. swing. X public class WelcomeApplet extends JApplet i /*大工 ntia1 ize the applet*/ public WelcomeApplet () add (new jlabel(" Welcome to Java" jlabel center))i Liang, Introduction to Java Programming, Sixth Edition, (c)2005 Pearson Education, Inc. All rights reserved. 0-13-148952-6
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved. 0-13-148952-6 4 First Simple Applet // WelcomeApplet.java: Applet for displaying a message import javax.swing.*; public class WelcomeApplet extends JApplet { /** Initialize the applet */ public WelcomeApplet() { add(new JLabel("Welcome to Java", JLabel.CENTER)); } } // WelcomeApplet.java: Applet for displaying a message import javax.swing.*; public class WelcomeApplet extends JApplet { /** Initialize the applet */ public void init() { add(new JLabel("Welcome to Java", JLabel.CENTER)); } }

First Simple applet Welcome Java Applet WelcomeApplet Run Applet Viewer Liang, Introduction to Java Programming, Sixth Edition, (c)2005 Pearson Education, Inc. All rights reserved. 0-13-148952-6
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved. 0-13-148952-6 5 First Simple Applet Welcome Java Applet WelcomeApplet Run Applet Viewer

Applet vs application WelcomeApplet java: Applet for displaying a message import javax. swing. X public class WelcomeApplet extends JApplet /*大工 nitia1 ize the app1et public void init() add(new JLabel (" Welcome to Java JLabel center))i import javax. swIng.大 public class My FrameWithlable public static void main(String[] args)i JFrame frame new JFrame("My FrameWithLable")i frame. add (new JLabel(" Welcome to Java", Jlabel center))i frame setsize(400, 300) frame setvisible(true)i frame setDefaultCloseOperation (JFrame EXIT ON CLOSE)i frame. setLocationRelativeTo(null);// New since JDK 1.4 Liang, Introduction to Java Programming, Sixth Edition, (c)2005 Pearson Education, Inc. All rights reserved. 0-13-148952-6
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved. 0-13-148952-6 6 Applet vs. Application import javax.swing.*; public class MyFrameWithlable{ public static void main(String[] args) { JFrame frame = new JFrame("MyFrameWithLable"); frame.add(new JLabel("Welcome to Java", JLabel.CENTER)); frame.setSize(400, 300); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationRelativeTo(null); // New since JDK 1.4 } } // WelcomeApplet.java: Applet for displaying a message import javax.swing.*; public class WelcomeApplet extends JApplet { /** Initialize the applet */ public void init() { add(new JLabel("Welcome to Java", JLabel.CENTER)); } }

The Applet Class, cont Applets are created, run, and destroyed by web browser Dont set size for an applet: determined by html file Dont set title for an applet: applets cannot have title bars Can have menus No need to explicitly construct an applet. Construction code placed inside the init method There is no main method An applet cannot be closed. It terminates automatically when the browser No need to call method show An applet is displayed automatically Liang, Introduction to Java Programming, Sixth Edition, (c)2005 Pearson Education, Inc. All rights reserved. 0-13-148952-6
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved. 0-13-148952-6 7 The Applet Class, cont. Applets are created, run, and destroyed by web browser – Don’t set size for an applet: determined by HTML file. – Don’t set title for an applet: applets cannot have title bars. Can have menus. – No need to explicitly construct an applet. Construction code placed inside the init method. – There is no main method. – An applet cannot be closed. It terminates automatically when the browser exit. – No need to call method show. An applet is displayed automatically

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 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 pI roper Liang, Introduction to Java Programming, Sixth Edition, (c)2005 Pearson Education, Inc. All rights reserved. 0-13-148952-6
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved. 0-13-148952-6 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

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 public MyApplet ()( /** Called by the browser after the applet is loaded public void init() /* Called by the browser after the init() method 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( /* Called by the browser when the Web browser exits * publi d destroy() t /* other methods if necessary
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved. 0-13-148952-6 9 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... */ }

Browser Calling applet methods oade JVM loads the reload enters web page applet class Browser creates the applet Created B invokes initO aftcr inil Initialized Browser BI rowser y return to pa invokes start invokes stop start k slop!) invokes stop Started Stopped eo to exits another page Browser Browser invokes destroy() Destroyed Liang, Introduction to Java Programming, Sixth Edition, (c)2005 Pearson Education, Inc. All rights reserved. 0-13-148952-6
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved. 0-13-148952-6 10 Browser Calling Applet Methods Browser invokes start() Destroyed Browser invokes destroy() Browser invokes stop() Loaded Initialized Browser invokes init() Started Stopped Created Browser creates the applet JVM loads the applet class Browser invokes stop() Browser invokes start()
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 《计算机组装与维护》课程教学资源(PPT课件讲稿)第9章 BIOS设置(设置BIOS).ppt
- 香港城市大学:基序检测的随机化算法(PPT讲稿)Randomized Algorithm for Motif Detection.ppt
- 《数据结构》课程教学资源(PPT课件讲稿)第七章 图及其应用.ppt
- 3D Reconstruction from Images:Image-based Street-side City Modeling.ppt
- 大连理工大学:《计算机网络》课程教学资源(PPT课件讲稿)Chapter 2 应用层 application layer.ppt
- 四川大学:《操作系统 Operating System》课程教学资源(PPT课件讲稿)Chapter 3 Process Description and Control 3.4 Process Control 3.5 Execution of the Operating System 3.6 Unix SVR4 Process Management 3.7 Linux Process management system calls.ppt
- 《数据结构》课程教学资源(PPT课件讲稿)第七章 图 Graph.ppt
- 《数据结构》课程教学资源:实践教学大纲.doc
- 《网络算法学》课程教学资源(PPT课件讲稿)第三章 实现原则.ppt
- 《电脑组装与维护实例教程》教学资源(PPT课件讲稿)第5章 多媒体设备介绍及选购.ppt
- 广西医科大学:《计算机网络 Computer Networking》课程教学资源(PPT课件讲稿)Chapter 02 Network Classification.pptx
- 清华大学:无线网和移动网(PPT课件讲稿)Mobile and wireless network.pptx
- 中国科学技术大学:《计算机体系结构》课程教学资源(PPT课件讲稿)第6章 Data-Level Parallelism in Vector, SIMD, and GPU Architectures.pptx
- 厦门大学:《分布式数据库》课程教学资源(PPT课件讲稿)专题一 分布式数据库介绍.ppt
- 《The C++ Programming Language》课程教学资源(PPT课件讲稿)Lecture 06 OOP with Templates.ppt
- 武汉科技大学中南分校:Windows 2000/XP网络组建与系统管理(系统安装,李燕).ppt
- 电子科技大学:《面向对象程序设计语言C++》课程教学资源(PPT课件讲稿)第五章 构造数据类型.ppt
- 《C语言程序设计》课程电子教案(PPT教学课件)第三章 分支结构.ppt
- 计算机维护与维修(PPT课件讲稿)第十二章 笔记本电脑维护维修.ppt
- 西安电子科技大学:《微机原理与接口技术》课程教学资源(PPT课件讲稿)第四章 汇编语言程序设计(主讲:王晓甜).pptx
- 上海交通大学:《挖掘海量数据集 Mining Massive Datasets》课程教学资源(PPT讲稿)Lecture 06 搜索引擎 Search Engines.ppt
- 《计算机系统安全》课程教学资源(PPT课件讲稿)第二章 黑客常用的系统攻击方法.ppt
- 《C语言程序设计》课程教学资源(PPT课件讲稿)第8章 结构体、共用体与枚举类型.ppt
- 香港浸会大学:Introduction to Linux and PC Cluster.ppt
- 南京大学:《计算机图形学》课程教学资源(PPT课件讲稿)第7讲 图元填充与裁剪算法.pptx
- 北京航空航天大学:SimplyDroid - Efficient Event Sequence Simplification for Android Application.pptx
- 《The C++ Programming Language》课程教学资源(PPT课件讲稿)Lecture 04 Object-Based Programming.ppt
- 中国科学技术大学:Linux内核源代码导读(PPT讲稿,陈香兰).ppt
- 《网上开店实务》课程教学资源(PPT讲稿)学习情境3 网店装修.ppt
- 北京大学:《项目成本管理》课程教学资源(PPT课件讲稿)项目范围计划(主讲:周立新).ppt
- 香港中文大学:Achieving Secure and Cooperative Wireless Networks with Trust Modeling and Game Theory.ppt
- MSCIT 5210/MSCBD 5002:Knowledge Discovery and Data Mining:Chapter 4:Data Warehousing, On-line Analytical Processing and Data Cube.ppt
- 《程序设计基础》课程PPT教学课件(C++)第3讲 C++程序控制结构.ppt
- 四川大学:《数据库技术》课程教学资源(PPT课件讲稿)数据库设计.ppt
- 云计算 Cloud Computing(PPT讲稿)MapReduce进阶.ppt
- 《C语言程序设计》课程电子教案(PPT课件讲稿)第7章 用函数实现模块化程序设计.pptx
- 中国科学技术大学:云计算及安全(PPT讲稿)Cloud Computing & Cloud Security.pptx
- 中国科学技术大学:《信号与图像处理基础 Signal and Image Processing》课程教学资源(PPT课件讲稿)数字图像处理基础 Basics of Digital Image Processing.pptx
- 中国科学技术大学:《信号与图像处理基础 Signal and Image Processing》课程教学资源(PPT课件讲稿)图像压缩编码 Image Compression.pptx
- 《计算机组成原理》课程教学资源(PPT课件讲稿)第3章 计算机的算术运算.pptx