第7章小应用程序与网络程序设计
许勐
中达金桥科技开发有限公司
xumeng@
《Java程序设计》
7/29/2018
1
中达金桥
本章总体纲要
小应用程序
小应用程序HTML标记符
同时是应用程序和小应用程序
声音与图像
URL
基于TCP的网络程序设计
7/29/2018
2
中达金桥
小应用程序
什么是小应用程序?
类的层次结构
JApplet与Applet之间的不同点
小应用程序的生命周期
小应用程序的安全性
7/29/2018
3
中达金桥
什么是小应用程序?
小应用程序是可以嵌入到HTML (Hypertext Markup Language)文件中运行的Java程序
一般是 ( 或 )的子类
通过appletviewer或HTML 浏览器运行
7/29/2018
4
中达金桥
类的层次结构
|
+--
|
+--
|
+--
|
+--
|
+--
7/29/2018
5
中达金桥
JApplet与Applet之间的不同点
类JApplet是类
类JApplet 与Swing组件配套
默认的布局方式不同
JApplet BorderLayout.
Applet FlowLayout.
往容器JApplet中添加组件必须通过contentPane
例如: 给小应用程序添加组件
使用Applet, 代码如下:
(child);
使用 Japplet,代码如下:
().add(child);
7/29/2018
6
中达金桥
小应用程序的生命周期
所有的小应用程序具有如下的四个成员方法:
public void init(): 在小应用程序的生命周期中只会被调用一次,而且是在第一次加载小应用程序时
public void start(): 当小应用程序在启动或重新启动时,会调用此方法
public void stop(): 当小应用程序被图标化或从当前网页转到其它网页时,会调用此方法
public void destroy():在小应用程序的生命周期中只会被调用一次,而且是在(关闭网页之前)卸载小应用程序时
7/29/2018
7
中达金桥
小应用程序的生命周期
初始化状态
(瞬时)
运行
状态
停止
状态
死亡
状态
Start
复原或
重新进入该网页
Start
Stop
关闭浏览器
destroy
第一次加载
建构
Init
图标化或
进入新的网页
7/29/2018
8
中达金桥
实例
// ////////////////////////////////////////////////////////
//
// 编写程序
// 验证上面介绍的
// 小应用程序的生命周期
//
// ////////////////////////////////////////////////////////
7/29/2018
9
中达金桥
实例:
import .*;
import .*;
public class J_PrintState extends JApplet
{
public void init()
{
("init: Applet begins");
} // End of method: init
public void start()
{
("start: Enter applet");
} // End of method: start
public void paint(Graphics g)
{
("paint: Draw applet");
("Applet Demo", 80, 40);
} // End of method: paint
public void stop()
{
("stop: Leave applet");
} // End of method: stop
pub
java课件第七讲 来自淘豆网m.daumloan.com转载请标明出处.