社区
Java SE
帖子详情
100分求Applet的实例(先放50)
flyzhen
2002-02-22 08:53:51
哪位有做好的Applet的例子,能给我一份吗?谢谢。
...全文
77
12
打赏
收藏
100分求Applet的实例(先放50)
哪位有做好的Applet的例子,能给我一份吗?谢谢。
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
12 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
chinajava
2002-02-25
打赏
举报
回复
mport java.applet.Applet;
import java.awt.*;
public class fire extends Applet
implements Runnable
{
boolean first = false;
int ROWS = 0;
int COLS = 0;
int HIDDEN = 0;
int ROWS_SEED = 0;
int ROWS_RESEED = 0;
int MAX_SEED = 0;
int PALETTE_SIZE = 0;
int COOLING_LIMIT = 0;
int COOLING_ROWS = 0;
int COOLING_FACTOR = 0;
Color palette[] = null;
byte Buffer[] = null;
byte Buffer2[] = null;
String message = null;
String textfont = null;
int textsize = 0;
int textX = 0;
int textY = 0;
Color textcolor = null;
Image offScrImage = null;
Graphics offScrGC = null;
Dimension offScrSize = null;
Thread kicker = null;
public String getAppletInfo()
{
return "Fire applet by Javier Rodriguez <jrodrig@data.net.mx>";
}
public String[][] getParameterInfo()
{
String as[][] = {
{
"coolingrows", "int", "number of rows to cool"
}, {
"coolingfactor", "int", "cooling factor"
}, {
"coolinglimit", "int", "cooling threshold"
}, {
"soundtrack", "url", "background sound"
}, {
"text", "String", "message"
}, {
"textcolor", "String", "text color"
}, {
"textfont", "String", "text font"
}, {
"textsize", "int", "text size"
}
};
return as;
}
public void init()
{
COLS = size().width;
ROWS = size().height + HIDDEN;
String s = getParameter("coolinglimit");
if(s != null && s.endsWith("%"))
s = s.substring(0, s.length() - 1);
COOLING_LIMIT = s != null ? (PALETTE_SIZE * Integer.valueOf(s).intValue()) / 100 : (int)((double)PALETTE_SIZE * 0.5D);
s = getParameter("coolingrows");
if(s != null && s.endsWith("%"))
s = s.substring(0, s.length() - 1);
COOLING_ROWS = s != null ? (ROWS * Integer.valueOf(s).intValue()) / 100 : (int)((double)ROWS * 0.80000000000000004D);
s = getParameter("coolingfactor");
COOLING_FACTOR = s != null ? Integer.valueOf(s).intValue() : 2;
ROWS_RESEED = (int)((double)ROWS * 0.95999999999999996D);
s = getParameter("text");
message = s != null ? s : "";
s = getParameter("textfont");
textfont = s != null ? s : "TimesRoman";
s = getParameter("textsize");
textsize = s != null ? Integer.valueOf(s).intValue() : 18;
s = getParameter("textcolor");
textcolor = hexColor(s, Color.white);
Buffer = new byte[COLS * ROWS];
Buffer2 = new byte[COLS * ROWS];
for(int j = 0; j < 16; j++)
palette[j] = new Color(16 * j, 0, 0);
for(int k = 0; k < 16; k++)
palette[16 + k] = new Color(255, 16 * k, 0);
for(int l = 0; l < 32; l++)
palette[32 + l] = new Color(255, 255, 8 * l);
Font font = new Font(textfont, 1, textsize);
FontMetrics fontmetrics = getFontMetrics(font);
int i1 = fontmetrics.getHeight();
int j1 = fontmetrics.stringWidth(message);
textX = (COLS - j1) / 2;
textY = ROWS - HIDDEN - (ROWS - HIDDEN - i1) / 2 - fontmetrics.getDescent();
setFont(font);
for(int i = COLS * (ROWS - ROWS_SEED); i < ROWS * COLS; i++)
Buffer[i] = (byte)(int)(Math.random() * (double)(PALETTE_SIZE - 1));
}
void MainLoop()
{
for(int i = COLS + 1; i < COLS * (ROWS - 1) - 1; i++)
{
int k = Buffer[i - COLS - 1] + Buffer[i - COLS] + Buffer[(i - COLS) + 1] + Buffer[i - 1] + Buffer[i + 1] + Buffer[(i + COLS) - 1] + Buffer[i + COLS] + Buffer[i + COLS + 1];
k >>= 3;
if(k < COOLING_LIMIT && i < COOLING_ROWS * COLS && k > COOLING_FACTOR)
k -= COOLING_FACTOR;
Buffer2[i] = (byte)k;
}
for(int j = COLS * ROWS_RESEED; j < COLS * ROWS; j++)
{
int l = Buffer2[j];
Buffer2[j] = (byte)(int)(((double)l - Math.random() * (double)MAX_SEED) % ((double)PALETTE_SIZE * 1.1000000000000001D));
}
for(int i1 = 0; i1 < COLS * (ROWS - 1); i1++)
Buffer[i1] = Buffer2[i1 + COLS];
}
public final synchronized void update(Graphics g)
{
Dimension dimension = size();
if(offScrImage == null || dimension.width != offScrSize.width || dimension.height != offScrSize.height)
{
offScrImage = createImage(dimension.width, dimension.height);
offScrSize = dimension;
offScrGC = offScrImage.getGraphics();
offScrGC.setFont(getFont());
}
if(offScrGC != null)
{
offScrGC.fillRect(0, 0, dimension.width, dimension.height);
paint(offScrGC);
g.drawImage(offScrImage, 0, 0, null);
}
}
public void paint(Graphics g)
{
MainLoop();
for(int j = 0; j < ROWS - HIDDEN; j++)
{
for(int k = 0; k < COLS; k++)
{
int i = Buffer[j * COLS + k];
i = i >= 0 ? i : -i;
i = i >= PALETTE_SIZE - 1 ? PALETTE_SIZE - 1 : i;
Color color = palette[i];
try
{
offScrGC.setColor(color);
offScrGC.drawLine(k, j, k + 1, j);
}
catch(Exception _ex) { }
}
}
try
{
offScrGC.setColor(textcolor);
offScrGC.drawString(message, textX, textY);
g.drawImage(offScrImage, 0, 0, this);
return;
}
catch(Exception _ex)
{
return;
}
}
public void start()
{
if(kicker == null)
{
kicker = new Thread(this);
kicker.start();
}
}
public void stop()
{
kicker = null;
}
public void run()
{
while(kicker != null)
{
repaint();
try
{
Thread.sleep(15L);
}
catch(InterruptedException _ex) { }
}
}
public boolean mouseDown(Event event, int i, int j)
{
int k = i + j * COLS;
if(k > 81)
{
Buffer[k] = -1;
Buffer[k - COLS] = -1;
Buffer[k + COLS] = -1;
Buffer[k - 1] = -1;
Buffer[k + 1] = -1;
}
return true;
}
public Color hexColor(String s, Color color)
{
try
{
Integer integer = new Integer(0);
s.replace('#', ' ');
s.trim();
integer = Integer.valueOf(s, 16);
return new Color(integer.intValue());
}
catch(Exception _ex)
{
return color;
}
}
public fire()
{
first = true;
ROWS = 50;
COLS = 64;
HIDDEN = 4;
ROWS_SEED = 4;
ROWS_RESEED = 48;
MAX_SEED = 8;
PALETTE_SIZE = 64;
COOLING_LIMIT = 32;
COOLING_ROWS = 42;
COOLING_FACTOR = 2;
palette = new Color[PALETTE_SIZE];
}
}
whyyy78
2002-02-25
打赏
举报
回复
jdk/demo里头很多呀。
wolfsquare
2002-02-25
打赏
举报
回复
要那么复杂的干什么,随便找一个java应用程序,把它的Frame改成Panel往Applet上一Add,那不就是复杂的么.
huang_brid
2002-02-25
打赏
举报
回复
找一本带源码的书,那不就有许多的例子了么?
flyzhen
2002-02-25
打赏
举报
回复
提一下!
flyzhen
2002-02-25
打赏
举报
回复
不是我自己用,是给我的一个朋友的。他在外地,又是个新手,不知道该买什末样的书。
bread213
2002-02-23
打赏
举报
回复
我这儿到是有不少,你要多少
flyzhen
2002-02-23
打赏
举报
回复
To ariso(yangxz) :
我想找的是比较复杂的Applet,不是HelloWorld之类的东西.如果有复杂的请提供给我.谢谢!
flyzhen
2002-02-23
打赏
举报
回复
我的信箱是:fly2zhen@sina.com
ariso
2002-02-23
打赏
举报
回复
显示“Hello,world!”
使用任何一种 Java 开发工具,输入以下程序。存盘,文件名为“hello.java”。
编译这个程序,生成“hello.class”。
import java.applet.*;
import java.awt.*;
public class hello extends Applet
{
public hello()
{
}
public void paint(Graphics g)
{
g.drawString("Hello,world!", 10, 20);
}
}
编写一个超文本网页,并把“hello.class”按以下格式插入:
<html>
<body>
<applet code=hello.class width=320 height=240>
</applet>
</body>
</html>
用浏览器观察结果:
karma
2002-02-23
打赏
举报
回复
http://www.codeguru.com/java/Applet/index.shtml
GJA106
2002-02-22
打赏
举报
回复
联系方式?
java源码包---java 源码 大量
实例
Applet
钢琴模拟程序java源码 2个目标文件,提供基本的音乐编辑功能。编辑音乐软件的朋友,这款
实例
会对你有所帮助。 Calendar万年历 1个目标文件 EJB 模拟银行ATM流程及操作源代码 6个目标文件,EJB来模拟银行ATM...
java源码包2
Applet
钢琴模拟程序java源码 2个目标文件,提供基本的音乐编辑功能。编辑音乐软件的朋友,这款
实例
会对你有所帮助。 Calendar万年历 1个目标文件 EJB 模拟银行ATM流程及操作源代码 6个目标文件,EJB来模拟银行...
java源码包3
Applet
钢琴模拟程序java源码 2个目标文件,提供基本的音乐编辑功能。编辑音乐软件的朋友,这款
实例
会对你有所帮助。 Calendar万年历 1个目标文件 EJB 模拟银行ATM流程及操作源代码 6个目标文件,EJB来模拟银行...
java源码包4
Applet
钢琴模拟程序java源码 2个目标文件,提供基本的音乐编辑功能。编辑音乐软件的朋友,这款
实例
会对你有所帮助。 Calendar万年历 1个目标文件 EJB 模拟银行ATM流程及操作源代码 6个目标文件,EJB来模拟银行...
Java SE
62,634
社区成员
307,269
社区内容
发帖
与我相关
我的任务
Java SE
Java 2 Standard Edition
复制链接
扫一扫
分享
社区描述
Java 2 Standard Edition
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章