/* Simple clock applet demonstrating access from JavaScript
by Danny Goodman (http://www.dannyg.com)
*/
import java.awt.*;
import java.util.*;
import java.text.*;
public class ScriptableClock extends java.applet.Applet implements Runnable {
// control variables
private final boolean GMT = true;
private final boolean LOCALE = false;
private String displayDate;
private Font displayFont;
private Thread thread;
// parameter options
private Color bgColor;
private Color fgColor;
private Rectangle displayArea;
private String fontName;
private int fontSize;
private int fontStyle;
private int height, width;
private boolean timeZone;
@Override
public void init() {
parseArgs();
displayFont = new Font(fontName, fontStyle, fontSize);
timeZone = LOCALE;
displayArea = getBounds();
height = displayArea.height;
width = displayArea.width;
resize(width, height);
}
@Override
public void start() {
if (thread == null) {
thread = new Thread(this);
thread.start();
}
}
@Override
public void stop() {
if (thread != null) {
thread = null;
}
}
public void run() {
while (thread != null) {
Date theDate = new Date();
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM. DateFormat.FULL);
if (timeZone) {
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT-0:00"));
}
displayDate = dateFormat.format(theDate);
repaint();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
}
@Override
public void paint(Graphics g) {
g.setColor(bgColor);
g.fillRect(0, 0, width, height);
g.setColor(fgColor);
g.setFont(displayFont);
FontMetrics fm = getFontMetrics(getFont());
int textWidth = fm.stringWidth(displayDate);
int horizOffset = (width / 2) - (textWidth / 2);
g.drawString(displayDate, 5, 35);
}
/*
Begin public methods for getting
and setting data via LiveConnect
*/
public void setTimeZone(String zone) {
stop();
timeZone = (zone.startsWith("GMT")) ? true : false;
start();
}
public void setFont(String newFont, String newStyle, String newSize) {
stop();
if (newFont != null && newFont.length() != 0) {
fontName = newFont;
}
if (newStyle != null && newStyle.length() != 0) {
setFontStyle(newStyle);
}
if (newSize != null && newSize.length() != 0) {
setFontSize(newSize);
}
displayFont = new Font(fontName, fontStyle, fontSize);
start();
}
public void setColor(String newbgColor, String newfgColor) {
stop();
bgColor = parseColor(newbgColor);
fgColor = parseColor(newfgColor);
start();
}
public String getInfo() {
String result = "Info about ScriptableClock.class\r\n";
result += "Version/Date: 1.0d1/2 May 1996\r\n";
result += "Author: Danny Goodman (dannyg@dannyg.com)\r\n";
result += "Public Variables:\r\n";
result += " (None)\r\n\r\n";
result += "Public Methods:\r\n";
result += " setTimeZone(\"GMT\" | \"Locale\")\r\n";
result += " setFont(\"fontName\",\"Plain\" |\"Bold\" | \"Italic\", \"fontSize\")\r\n";
result += " setColor(\"bgColorName\", \"fgColorName\")\r\n";
result += " colors: Black, White, Red, Green, Blue, Yellow\r\n";
return result;
}
/*
End public methods for scripted access.
*/
private void setFontStyle(String style) {
try {
if (style.equalsIgnoreCase("Plain")) {
fontStyle = Font.PLAIN;
} else if (style.equalsIgnoreCase("Italic")) {
fontStyle = Font.ITALIC;
} else {
fontStyle = Font.BOLD;
}
} catch (Exception e) {
fontStyle = Font.BOLD;
}
}
private void setFontSize(String size) {
try {
fontSize = Integer.parseInt(size);
} catch (Exception e) {
fontSize = 24;
}
}
private void parseArgs() {
fontName = getParameter("font");
if (fontName == null) {
fontName = new String("TimesRoman");
}
String n = getParameter("fontSize");
setFontSize(n);
n = getParameter("fontStyle");
setFontStyle(n);
bgColor = parseColor(getParameter("bgColor"));
if (bgColor == null) {
bgColor = Color.white;
}
fgColor = parseColor(getParameter("fgColor"));
if (fgColor == null) {
fgColor = Color.black;
}
}
private Color parseColor(String c) {
try {
if (c.equalsIgnoreCase("Black")) {
return Color.black;
} else if (c.equalsIgnoreCase("White")) {
return Color.white;
} else if (c.equalsIgnoreCase("Red")) {
return Color.red;
} else if (c.equalsIgnoreCase("Green")) {
return Color.green;
} else if (c.equalsIgnoreCase("Blue")) {
return Color.blue;
} else if (c.equalsIgnoreCase("Yellow")) {
return Color.yellow;
} else {
return Color.black;
}
} catch (Exception e) {
return null;
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
javascript 宝典第七版光盘内容
共730个文件
html:351个
js:143个
gif:104个
5星 · 超过95%的资源 需积分: 10 197 下载量 25 浏览量
2014-02-20
13:12:46
上传
评论 5
收藏 23.56MB RAR 举报
温馨提示
javascript 宝典第七版的随书光盘有代码和英文版的后面几章的PDF文件
资源推荐
资源详情
资源评论
收起资源包目录
javascript 宝典第七版光盘内容 (730个子文件)
Chopin.aif 640KB
Scriabin.aif 389KB
Beethoven.aif 273KB
d.aif 93KB
e.aif 92KB
c.aif 88KB
cSharp.aif 84KB
dSharp.aif 84KB
ScriptableClock.class 6KB
FileReader.class 3KB
JtoJSDemo.class 2KB
mapgame.css 1KB
jsb-evaluator.css 519B
hauntedPlaces.css 414B
jsb-18-05.css 302B
jsb-evaluator-jr.css 290B
jsb24-01.css 150B
jsb-13-01-frame-footnotes.css 95B
jsb24-03.css 89B
jsb-13-01-frameset.css 85B
jsb29-12.css 52B
jsb21-05.css 48B
jsb21-04.css 48B
Academy Awards.csv 3KB
arch.gif 174KB
arch.gif 174KB
arch.gif 174KB
nile.gif 49KB
nile.gif 49KB
desk2.gif 11KB
desk2.gif 11KB
desk2.gif 11KB
desk4.gif 11KB
desk4.gif 11KB
desk4.gif 11KB
cpu2.gif 10KB
cpu1.gif 9KB
dhNav.gif 9KB
dhNav.gif 9KB
desk1.gif 9KB
desk1.gif 9KB
desk1.gif 9KB
desk1.gif 9KB
cpu3.gif 9KB
desk1.gif 9KB
desk1.gif 9KB
desk3.gif 8KB
desk3.gif 8KB
desk3.gif 8KB
desk3.gif 8KB
desk3.gif 8KB
logo.gif 7KB
cpu4.gif 7KB
cr_kraft.gif 7KB
lightnin.gif 5KB
dhIcon.gif 5KB
dhIcon.gif 5KB
resright.gif 4KB
resleft.gif 3KB
camap.gif 2KB
ca.gif 2KB
camap.gif 2KB
sb23.gif 1KB
us11.gif 1KB
Black.gif 1KB
wh86.gif 1KB
nv.gif 1KB
az.gif 1KB
RightDown.gif 1024B
LeftNorm.gif 1024B
LeftDown.gif 1024B
RightNorm.gif 1024B
RightUp.gif 1024B
LeftUp.gif 1024B
updated.gif 1024B
RightDown.gif 1024B
LeftNorm.gif 1024B
LeftDown.gif 1024B
RightNorm.gif 1024B
RightUp.gif 1024B
LeftUp.gif 1024B
ormap.gif 991B
or.gif 991B
ormap.gif 991B
id.gif 929B
Gold.gif 915B
None.gif 907B
Violet.gif 886B
Yellow.gif 855B
wamap.gif 836B
wa.gif 836B
wamap.gif 836B
Orange.gif 826B
Red.gif 819B
ut.gif 806B
info.gif 781B
spacer.gif 765B
Brown.gif 697B
Gray.gif 670B
Silver.gif 668B
共 730 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
coder_fighting
- 粉丝: 4
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
前往页