日期:2014-05-17 浏览次数:20766 次
<%@ page contentType="text/html; charset=GB2312"%>
<html>
<head>
<title>
用<jsp:plugin>加载Applet
</title>
</head>
<body>
<center>
<font size="3" face="隶书" color="blue">
用<jsp:plugin>加载Applet
</font>
<!-- 用plugin加载Applet -->
<hr />
<jsp:plugin type="applet" code="RollingMessage.class" height="60" width="550">
</jsp:plugin>
</center>
</body>
</html>
import java.awt.*;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
public class RollingMessage extends java.applet.Applet implements Runnable
{
Thread runThread;
String s = "欢饮学习\"Web技术应用基础\"!";
int s_length = s.length();
int x_character = 0;
Font wordFont = new Font("楷体_GB2312", Font.BOLD, 30);
public void start()
{
if (runThread == null)
{
runThread = new Thread(this);
runThread.start();
}
}
public void stop()
{
if (runThread != null)
{
runThread.stop();
runThread = null;
}
}
public void run()
{
while (true)
{
if (x_character++ > s_length)
{
x_character = 0;
}
repaint();
try
{
Thread.sleep(300);
}
catch (InterruptedException e)
{}
}
}
public void paint(Graphics g)
{
g.setFont(wordFont);
g.setColor(Color.BLUE);
g.drawString(s.substring(0, x_character), 8, 50);
}
public static void main(String[] args)
{
Frame f = new Frame("动画程序");
RollingMessage drawTest = new RollingMessage();
drawTest.init();
drawTest.start();
f.add("Center", drawTest);
f.resize(400, 100);
f.show();
}
}