100分求Applet的实例(先放50)

flyzhen 2002-02-22 08:53:51
哪位有做好的Applet的例子,能给我一份吗?谢谢。
...全文
48 12 打赏 收藏 举报
写回复
12 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
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 SE
加入

6.2w+

社区成员

Java 2 Standard Edition
社区管理员
  • Java SE
申请成为版主
帖子事件
创建了帖子
2002-02-22 08:53
社区公告
暂无公告