📄 parambannerapplet.java~11~
字号:
package applettest;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
/*
<applet code="ParamBanner" width=300 height=50>
<param name=message value="Java 创造了动态网页!">
<param name=status value="此处为状态栏!">
</applet>
*/
public class ParamBannerApplet
extends Applet
implements Runnable {
private boolean isStandalone = false;
String message;
String status;
Thread t = null;
int state;
boolean stopFlag;
//Get a parameter value
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}
//Construct the applet
public ParamBannerApplet() {
}
//Initialize the applet
public void init() {
setBackground(Color.cyan);
setForeground(Color.red);
try {
message = this.getParameter("message", "Java 创造了动态网页!");
}
catch (Exception e) {
e.printStackTrace();
}
try {
status = this.getParameter("status", "此处为状态栏!");
}
catch (Exception e) {
e.printStackTrace();
}
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
}
//Get Applet information
public String getAppletInfo() {
return "Applet Information";
}
//Get parameter info
public String[][] getParameterInfo() {
String[][] pinfo = {
{
"message", "String", ""}
, {
"status", "String", ""}
,
};
return pinfo;
}
public void start() {
message = getParameter("message");
if (message == null) {
message = "Message not found.";
}
message = " " + message;
status = getParameter("status");
if (status == null) {
status = "此为状态信息!";
}
t = new Thread(this);
stopFlag = false;
t.start();
}
// Entry point for the thread that runs the banner.
public void run() {
char ch;
// Display banner
for (; ; ) {
try {
repaint();
Thread.sleep(1000);
ch = message.charAt(0);
message = message.substring(1, message.length());
message += ch;
repaint();
if (stopFlag) {
break;
}
}
catch (InterruptedException e) {}
}
}
// Pause the banner.
public void stop() {
stopFlag = true;
t = null;
}
// Display the banner.
public void paint(Graphics g) {
g.setFont(new Font("Dialog", Font.PLAIN, 14));
g.drawString(message, 50, 30);
showStatus(status);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -