import java.applet.*;
import java.awt.*; public class HelloWorldApplet extends Applet
{
public void paint (Graphics g)
{
g.drawString ("Hello World", 25, 50);
}
}
<html>
<title>The Hello, World Applet</title>
<hr>
<applet code="HelloWorldApplet.class" width="320" height="120">
If your browser was Java-enabled, a "Hello, World"
message would appear here.
</applet>
<hr>
</html>
<applet codebase="http://amrood.com/applets"
code="HelloWorldApplet.class" width="320" height="120">
<applet code="mypackage.subpackage.TestApplet.class"
width="320" height="120">
import java.applet.*;
import java.awt.*;
public class CheckerApplet extends Applet
{
int squareSize = 50;// 初始化默认大小
public void init () {}
private void parseSquareSize (String param) {}
private Color parseColor (String param) {}
public void paint (Graphics g) {}
}
public void init ()
{
String squareSizeParam = getParameter ("squareSize");
parseSquareSize (squareSizeParam);
String colorParam = getParameter ("color");
Color fg = parseColor (colorParam);
setBackground (Color.black);
setForeground (fg);
}
private void parseSquareSize (String param)
{
if (param == null) return;
try {
squareSize = Integer.parseInt (param);
}
catch (Exception e) {
// 保留默认值
}
}
<html>
<title>Checkerboard Applet</title>
<hr>
<applet code="CheckerApplet.class" width="480" height="320">
<param name="color" value="blue">
<param name="squaresize" value="30">
</applet>
<hr>
</html>
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.applet.Applet;
import java.awt.Graphics; public class ExampleEventHandling extends Applet
implements MouseListener { StringBuffer strBuffer; public void init() {
addMouseListener(this);
strBuffer = new StringBuffer();
addItem("initializing the applet ");
} public void start() {
addItem("starting the applet ");
} public void stop() {
addItem("stopping the applet ");
} public void destroy() {
addItem("unloading the applet");
} void addItem(String word) {
System.out.println(word);
strBuffer.append(word);
repaint();
} public void paint(Graphics g) {
//Draw a Rectangle around the applet's display area.
g.drawRect(0, 0,
getWidth() - 1,
getHeight() - 1); //display the string inside the rectangle.
g.drawString(strBuffer.toString(), 10, 20);
} public void mouseEntered(MouseEvent event) {
}
public void mouseExited(MouseEvent event) {
}
public void mousePressed(MouseEvent event) {
}
public void mouseReleased(MouseEvent event) {
} public void mouseClicked(MouseEvent event) {
addItem("mouse clicked! ");
}
}
<html>
<title>Event Handling</title>
<hr>
<applet code="ExampleEventHandling.class"
width="300" height="300">
</applet>
<hr>
</html>
import java.applet.*;
import java.awt.*;
import java.net.*;
public class ImageDemo extends Applet
{
private Image image;
private AppletContext context;
public void init()
{
context = this.getAppletContext();
String imageURL = this.getParameter("image");
if(imageURL == null)
{
imageURL = "java.jpg";
}
try
{
URL url = new URL(this.getDocumentBase(), imageURL);
image = context.getImage(url);
}catch(MalformedURLException e)
{
e.printStackTrace();
// Display in browser status bar
context.showStatus("Could not load image!");
}
}
public void paint(Graphics g)
{
context.showStatus("Displaying image");
g.drawImage(image, 0, 0, 200, 84, null);
g.drawString("www.javalicense.com", 35, 100);
}
}
<html>
<title>The ImageDemo applet</title>
<hr>
<applet code="ImageDemo.class" width="300" height="200">
<param name="image" value="java.jpg">
</applet>
<hr>
</html>
import java.applet.*;
import java.awt.*;
import java.net.*;
public class AudioDemo extends Applet
{
private AudioClip clip;
private AppletContext context;
public void init()
{
context = this.getAppletContext();
String audioURL = this.getParameter("audio");
if(audioURL == null)
{
audioURL = "default.au";
}
try
{
URL url = new URL(this.getDocumentBase(), audioURL);
clip = context.getAudioClip(url);
}catch(MalformedURLException e)
{
e.printStackTrace();
context.showStatus("Could not load audio file!");
}
}
public void start()
{
if(clip != null)
{
clip.loop();
}
}
public void stop()
{
if(clip != null)
{
clip.stop();
}
}
}
<html>
<title>The ImageDemo applet</title>
<hr>
<applet code="ImageDemo.class" width="0" height="0">
<param name="audio" value="test.wav">
</applet>
<hr>

最新文章

  1. SQL Server中cursor的使用步骤
  2. PowerDesigner怎样才能在修改表的字段Name的时候Code不自动跟着变
  3. centOS填坑笔记(一)
  4. Linux资源控制-CPU和内存【转】
  5. PAC(Proxy Auto Config)代理自动配置文件的编写
  6. UITableViewCell 高度自适应
  7. 12 个 Linux 进程管理命令介绍
  8. spring bean中子元素lookup-method和replaced-method
  9. 什么?云数据库也能C位出道?
  10. 从数组中取出N个元素的所有组合——递归实现
  11. c#连接oracle数据库 DBHelper
  12. 在 Tomcat 中自定义 404 页面(简单配置)
  13. vs widows服务的开发
  14. Unity中Button按钮的触发监听事件
  15. Python3.6+Scrapy爬取知名技术文章网站
  16. Altium Designer 正反面布元器件
  17. docker 相关文章
  18. Unity打安卓包 Android 所有错误解决方案大全(几乎囊括所有打包错误 )
  19. Hive 建外链表到 Hbase(分内部表、外部表两种方式)
  20. linux 查看某几行内容与文件分割

热门文章

  1. jquery关于Select元素的操作
  2. maven中的groupId和artifactId 区分
  3. Android如何用一个TextView显示不同颜色得字符
  4. 直击JDD | 陈生强:京东数科的底层是数字化操作系统
  5. 指针数组的初始化和遍历,并且通过for循环方式、函数传参方式进行指针数组的遍历
  6. MySQL--InnoDB 关键特性
  7. D11 列表 list 元祖 字典dict
  8. 对Java面向对象中多态的理解
  9. UVA 10801 多线程最短路
  10. EL表达式获取属性值的原理