100分求Applet的实例(先放50) http://www.codeguru.com/java/Applet/index.shtml 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 显示“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> 用浏览器观察结果: To ariso(yangxz) :我想找的是比较复杂的Applet,不是HelloWorld之类的东西.如果有复杂的请提供给我.谢谢! 要那么复杂的干什么,随便找一个java应用程序,把它的Frame改成Panel往Applet上一Add,那不就是复杂的么. 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 <[email protected]>"; } 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]; }} 请问 java 相关 大家看看我这样的想法能实现么? 把一个ASCII字符串转换成为一个带符号整数(笔试题) 一个有关小问题 初学者入门完全手册,提问之前看看可以节约大量的积分 请问:interface excepted here这个错误该怎么办啊? 关于J2EE问题? 如果使用javamail是否可以实现email发送,做自己的mail.安全性好么? 有一些问题想请教各位javaweb方面的大哥们 运行时的出错提示! 有那位朋友看过Java2核心技术中的自定义布局管理器,在其中方法preferredLayoutSize的实现是怎样的?看不明白,高手解释一下
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> 用浏览器观察结果:
我想找的是比较复杂的Applet,不是HelloWorld之类的东西.如果有复杂的请提供给我.谢谢!
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 <[email protected]>";
} 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];
}
}