网站首页
JSP空间
动态资讯
开源项目
技术文档
资源下载
J2EE资源
客户论坛
在线支付
 
  技术文档>>JAVA>>新手入门>>基础入门>查看文档  
  用java设计浮动按钮程序     
  文章作者:未知  文章来源:水木森林  
  查看:112次  录入:管理员--2007-11-17  
 
  广 东 韶 关 市 十 里 亭 电 厂
梁 颖 健
---- 当 今 计 算 机 的 界 面 越 来 越 漂 亮。 随 着ie 和office 97 的 推 出, 又 出 现 一 个 新 颖 的 控 件: 浮 动 按 纽。 现 在vc 中 已 经 可 以 实 现 这 种 设 计, 而java 中 目 前 还 没 有 类 似 的 按 纽。 笔 者 最 近 分 析 浮 动 按 纽 的 特 点, 完 成 了 这 个 设 计。

---- 浮 动 按 纽 特 点 分 析:

---- 不 难 发 现, 浮 动 按 纽 其 实 就 是 一 种 欺 骗 视 觉 的 设 计。 当 按 纽 处 于 有 效 状 态 时, 鼠 标 进 入 按 纽 区 域, 按 纽 的 左 侧 和 上 侧 产 生 一 条 白 色 线, 右 侧 和 下 侧 产 生 一 条 灰 色 线( 窗 体 的 背 景 为 明 灰 色), 就 产 生 了 按 纽 浮 起 的 感 觉; 当 按 下 鼠 标 时, 按 纽 对 侧 的 颜 色 交 换, 同 时 按 纽 中 的 图 象 和 文 字 也 向 右 下 移 动 一 个 象 素 点, 则 产 生 按 纽 凹 入 的 感 觉; 移 出 鼠 标, 灰 白 两 色 消 失, 图 象 和 文 字 回 移 一 个 象 素 点, 恢 复 原 状。 根 据 这 些 特 点, 浮 动 按 纽 存 在 五 种 状 态: 平 面、 浮 起、 按 下、 失 效、 消 失。

---- 据 此, 设 计 一 个 完 整 的 浮 动 按 纽 主 要 围 绕 这 五 种 状 态 来 进 行, 由 另 一 个 类 提 供 提 示 信 息; 如 果 按 纽 没 有 提 供 失 效 状 态 下 的 图 象, 则 使 用 平 面 状 态 下 的 图 像, 过 滤 出 一 个 失 效 图 像, 因 此 又 需 要 一 个 类 完 成 图 像 过 滤。

---- 设 计 浮 动 按 纽 要 点 说 明:

---- 浮 动 按 纽 类 和 工 具 提 示 类 均 由java.awt.canvas 类 派 生, 失 效 图 像 类 由java.awt.image.rgbimagefilter 派 生。

---- 浮 动 按 纽 最 多 需 要 四 个 图 像, 最 少 需 要 一 个 图 像。 图 像 可 以 是 一 个image 或 它 的byte 数 组 形 式。

---- 若 是byte 数 组 形 式, 由java.awt.toolkit 类 下 的createimage 方 法 转 换 为image 形 式。 浮 动 按 纽 消 失 调 用component 类 的setvisible 方 法 完 成, 其 余 四 种 状 态 由paint 方 法 完 成。 设 置 文 本 使 用settext 方 法, 设 置 工 具 提 示 类 实 例 使 用settooltips 方 法( 不 设 置 这 两 项 亦 可)。 产 生 提 示 调 用 工 具 提 示 类 实 例 的setvisible 方 法。 为 感 应 鼠 标 事 件, 对 应mouselistener 接 口 中 的 方 法, 浮 动 按 纽 中 亦 有 五 个 方 法, 并 返 回 一 个 布 尔 值 确 定 是 否 已 执 行。

---- 提 示 信 息 由 工 具 提 示 类 中 的setvisible-run-repaint-update-paint 过 程 完 成。 调 用 类 实 例 时, 若 线 程 处 于 停 止 或 暂 停 状 态, 将 先 启 动 或 恢 复 再 执 行。 提 示 信 息 达 到 提 示 留 屏 时 间 后, 被 清 除( 在 此 期 间, 若 浮 动 按 纽 产 生 第 二 个 事 件, 提 示 亦 会 消 失)。 之 后 达 到 线 程 空 运 行 时 间, 线 程 将 被 暂 停, 直 到 再 有 浮 动 按 纽 使 用 工 具 提 示。 提 示 留 屏 时 间 和 线 程 空 运 行 时 间 的 参 数 通 过setkeep 和setdelay 方 法 修 改, 单 位 为 秒。 在 一 个 窗 体 中, 一 个 工 具 提 示 类 实 例 由 所 有 浮 动 按 纽 类 实 例 共 用。

---- 为 保 证 程 序 正 确 输 出, 还 应 注 意 以 下 几 点:

---- 1. 为 保 证 工 具 提 示 类 实 例 可 以 覆 盖 在 窗 体 的 所 有 控 件 上, 工 具 提 示 类 实 例 应 第 一 个 使 用add 方 法 添 加 到 窗 体 中。

---- 2. 浮 动 按 纽 必 须 调 用setvisible 方 法 才 能 显 示 或 消 失。

---- 3. 在 添 加 浮 动 按 纽 前, 应 调 用repaint 方 法 刷 新 屏 幕, 否 则 可 能nullpointerexception 异 常。

---- 4. 此 按 纽 是 针 对frame 设 计, 若 用 到applet 中, 请 修 改 浮 动 按 纽 中 的setentered 方 法 中 的 鼠 标 位 置 计 算。

---- 以 下 是 程 序 代 码:

---- 浮 动 按 纽 类:

import java.awt.*;
import java.awt.image.*;
import java.lang.string;

public class imagebutton extends
canvas implements java.lang.runnable {
// h_bosomspace,v_bosomspace
变量是图像与字体之间
按左右或上下分布时它们之间的间隔
// h_sidespace,v_sidespace
变量是左右两侧和上下两侧的空白区域
// status变量代表五个按纽
状态变量,初始值为消失
// alignment变量代表按纽图像
和文本是水平分布还是上下分布

int x,y,width,height,imagex,imagey,fontx,fonty;
private image normalimage,
enterimage,pressimage,disableimage;
private string text;
private font font = new font("dialog",font.plain,12);
private color basiccolor = color.lightgray;
private java.lang.thread draw;
private boolean imageloaded;

private int h_bosomspace=1,v_bosomspace=1;
private int h_sidespace=3,v_sidespace=3;

private int status = 5;
private final static int normal=1;
private final static int enter=2;
private final static int press=3;
private final static int disable=4;
private final static int hide = 5;

private int alignment;
public final static int horizon = 1;
//图象和字体左右分布
public final static int vertical = 2;
//图象和字体上下分布

private tooltips tooltips; //工具提示例实例
private string explain; //工具提示文本

public imagebutton(byte normalicon[]) {
this(normalicon,normalicon,normalicon,
normalicon,null,horizon);
}
public imagebutton(byte normalicon[],
byte entericon[],byte pressicon[],
byte disableicon[],string text,int alignment) {
if(alignment!=horizon && alignment!=vertical)
throw new numberformatexception
("alignment format error,at the
imagebutton construction");
this.text = text; this.alignment = alignment;
if(normalicon.length!=0)
this.normalimage = gettoolkit().createimage
(normalicon,0,normalicon.length);
if(!(new string(entericon).equals
(new string(normalicon))))
this.enterimage = gettoolkit().createimage
(entericon,0,entericon.length);
if(!(new string(pressicon).equals
(new string(normalicon))))
this.pressimage = gettoolkit().createimage
(pressicon,0,pressicon.length);
if(!(new string(disableicon).equals
(new string(normalicon))))
this.disableimage = gettoolkit().createimage
(disableicon,0,disableicon.length);
loadimage(); definepoint();
}

public imagebutton(image normalimage) {
this(normalimage,null,null,null,null,horizon);
}
public imagebutton(image normalimage,
image enterimage,image pressimage,
image disableimage,string text,int alignment) {
if(alignment!=horizon && alignment!=vertical)
throw new numberformatexception
("alignment format error,at the
imagebutton construction");

this.text = text; this.alignment = alignment;
this.normalimage = normalimage;
this.enterimage = enterimage;
this.pressimage = pressimage;
this.disableimage = disableimage;
loadimage(); definepoint();
}

private void loadimage() {
java.awt.mediatracker tracker =
new java.awt.mediatracker(this);
if(disableimage==null) {
imagefilter filter = new disablefilter();
disableimage = createimage( new filteredimagesource(
normalimage.getsource(),filter));
}
if(enterimage==null) enterimage = normalimage;
if(pressimage==null) pressimage = enterimage;

tracker.addimage(normalimage,0);
tracker.addimage(enterimage,1);
tracker.addimage(pressimage,2);
tracker.addimage(disableimage,3);
try {
tracker.waitforall();
if(tracker.iserrorany()) throw
new interruptedexception
("image load error,at the loadimage method");
} catch(interruptedexception ie) {
ie.printstacktrace();
}
}
//下面这个方法确定按纽的区域,图象、文本的显示位置
private void definepoint() {
int fontwidth=0,fontheight=0,imagewidth,imageheight;

fontmetrics fm = getfontmetrics(font);
if(this.text!=null) {
fontwidth = fm.stringwidth(this.text);
fontheight = fm.getheight();
}
imagewidth = normalimage.getwidth(this);
imageheight = normalimage.getheight(this);

switch(alignment) {
case horizon:
//当按纽中的图象和文字是左右分布时
if(h_sidespace*2 + imagewidth +
h_bosomspace + fontwidth >width)
width = h_sidespace*2 + imagewidth +
h_bosomspace + fontwidth;
if(imageheight + v_sidespace*2 >height)
height = imageheight + v_sidespace*2;
if(fontheight + v_sidespace*2 >height)
height = fontheight + v_sidespace*2;
if(this.text == null) {
imagex = (width - imagewidth)/2;
imagey = (height - imageheight)/2;
fontx=fonty=0;
} else {
imagex = (width - imagewidth
- h_bosomspace - fontwidth)/2;
imagey = (height - imageheight)/2;
fontx = imagex + imagewidth + h_bosomspace;
fonty = (height - fontheight)/2+ fm.getascent();
}
break;
case vertical: //当按纽中的图象和文字是按上下分布时
if(imagewidth + h_sidespace*2 >width)
width = imagewidth + h_sidespace*2;
if(fontwidth + h_sidespace*2 >width)
width = fontwidth + h_sidespace*2;
if(v_sidespace*2 + imageheight +
v_bosomspace + fontheight >height)
height = v_sidespace*2 + imageheight +
v_bosomspace + fontheight;
if(this.text == null) {
imagex = (width - imagewidth)/2;
imagey = (height - imageheight)/2;
fontx=fonty=0;
} else {
imagex = (width-imagewidth)/2;
imagey = (height-imageheight-v_
bosomspace-fontheight)/2;
fontx = (width-fontwidth)/2;
fonty = imagey+imageheight+v_
bosomspace+fm.getascent();
}
break;
}
}
//启动线程
public void start() {
if(draw == null) {
imageloaded = false;
draw = new java.lang.thread
(this,"paint image button");
draw.start();
}
}
//停止线程
public void stop() {
if(draw!=null) {
draw.stop(); draw=null;
}
}
public void run() {
draw.setpriority(thread.min_priority);
while(!imageloaded) {
repaint();
try {
thread.sleep(100);
} catch(interruptedexception ie) {
ie.printstacktrace();
break;
}
}
stop();
}

public void settooltipstext(string explain) {
this.explain = explain;
}
//获得工具提示实例和文本
public void settooltips(tooltips
tooltips,string explain) {
this.tooltips = tooltips;
this.explain = explain;
}

public int getalignment() {
return alignment;
}
//定义浮动按纽布局格式
public void setalignment(int id) {
if(id!=horizon && id!=vertical)
throw new numberformatexception
("alignment format error, at setalignment method");
alignment = id;
settransform();
}
public string gettext() {
return text;
}
public void settext(string text) {
this.text = text;
settransform();
}
public font getfont() {
return font;
}
public void setfont(font font) {
this.font = font;
settransform();
}
//图像与字体以左右、上下分布时彼此之间的空间
public void setbosomspace(int
h_bosomspace,int v_bosomspace) {
if(h_bosomspace < =0 || v_bosomspace < =0)
throw new numberformatexception
("set value error,at setbosomspace method");
this.h_bosomspace = h_bosomspace;
this.v_bosomspace = v_bosomspace;
settransform();
}
//设定左右和上下两侧的空白区域
public void setsidespace(int h_side
space, int v_sidespace) {
if(h_sidespace < =0 || v_sidespace < =0)
throw new numberformatexception
("set value error,at setsidespace method");
this.h_sidespace = h_sidespace;
this.v_sidespace = v_sidespace;
settransform();
}
private void settransform() {
definepoint();
if(status!=hide) {
super.setbounds(x,y,width,height);
repaint();
}
}

public point getlocation() {
return new point(x,y);
}
public void setlocation(point p) {
setlocation(p.x,p.y);
}
public void setlocation(int x,int y) {
setbounds(x,y,this.width,this.height);
}
public dimension getsize() {
return new dimension(this.width,this.height);
}
public void setsize(dimension d) {
setsize(d.width,d.height);
}
public void setsize(int width,int height) {
setbounds(this.x,this.y,width,height);
}
public rectangle getbounds() {
return new rectangle(x,y,width,height);
}
public void setbounds(rectangle r) {
setbounds(r.x,r.y,r.width,r.height);
}
public void setbounds(int x,int
y,int width,int height) {
this.x=x; this.y=y; this.width=
width; this.height=height;
definepoint();
if(status!=hide) {
super.setbounds(this.x,this.
y,this.width,this.height);
start();
}
}

public boolean isvisible(){
return status!=hide?true:false;
}
public boolean isenabled() {
return status!=disable?true:false;
}
public void setvisible(boolean b) {
if(b) {
status = normal;
super.setvisible(true);
super.setbounds(x,y,width,height);
start();
}
else {
status = hide;
super.setvisible(false);
}
}
public void setenabled(boolean b) {
setstatus(b?normal:disable);
}
public void setdisable() {
setenabled(false);
}
public synchronized boolean setclicked() {
if(status==disable) return false;
setstatus(enter);
return true;
}
public synchronized boolean setentered
(point mouse,rectangle frame) {
if(tooltips!=null && explain!=null) {
int toolx=mouse.x-this.x-frame.x*2;
int tooly=mouse.y-this.y-frame.y*2;
tooltips.setvisible(explain,new
point(toolx,tooly),frame);
}
if(status==disable) return false;
setstatus(enter);
return true;
}
public synchronized boolean setexited() {
if(tooltips!=null && explain!=
null && tooltips.isvisible())
tooltips.setcleared();
if(status==disable) return false;
setstatus(normal);
return true;
}
public synchronized boolean setpressed() {
if(tooltips!=null && explain!=
null && tooltips.isvisible())
tooltips.setcleared();
if(status==disable) return false;
setstatus(press);
return true;
}
public synchronized boolean setreleased(point mouse) {
if(status==disable) return false;
if(mouse.x >=0&&mouse.x < =
width-1&&mouse.y >=0&&mouse.y < =height-1)
setstatus(enter);
else
setstatus(normal);
return true;
}
private void setstatus(int id) {
if(id < normal||id >hide)
throw new numberformatexception
("status format error,at the setstatus method");
if(status == hide) return;
//当status的值为hide,
不允许重画,必须通过setvisible方法显示
this.status = id;
repaint();
}

public void repaint() {
repaint(0,0,width,height);
}
public void update(graphics g) {
g.setcolor(getbackground());
g.fillrect(0,0,width,height);
g.setcolor(getforeground());
paint(g);
}
public void paint(graphics g ) {
switch(status) {
case normal:
imageloaded=g.drawimage
(normalimage,imagex,imagey,basiccolor,this);
if(text!=null) {
g.setcolor(color.black);
g.setfont(font);
g.drawstring(text,fontx,fonty);
}
break;
case enter:
g.setcolor(color.white); g.drawrect(0,0,width,height);
g.setcolor(color.gray);
g.drawline(0,height-1,width-1,height-1);
g.drawline(width-1,0,width-1,height-1);
g.drawimage(enterimage,imagex,imagey,basiccolor,this);
if(text!=null) {
g.setcolor(color.blue); g.setfont(font);
g.drawstring(text,fontx,fonty);
}
break;
case press:
g.setcolor(color.gray); g.drawrect(0,0,width,height);
g.setcolor(color.white);
g.drawline(0,height-1,width-1,height-1);
g.drawline(width-1,0,width-1,height-1);
g. drawimage(pressimage,imagex+1,
imagey+1,basiccolor,this);
if(text!=null) {
g.setcolor(color.red); g.setfont(font);
g.drawstring(text,fontx+1,fonty+1);
}
break;
case disable:
g. drawimage(disableimage,imagex,
imagey,basiccolor,this);
if(text!=null) {
g.setcolor(color.gray); g.setfont(font);
g.drawstring(text,fontx,fonty);
}
break;
}
}

}

工具提示类

import java.awt.*;
import java.lang.string;
import java.lang.thread;

public class tooltips extends canvas
implements java.lang.runnable {

/* keep是工具提示留屏时间变量
delay是线程空运行时间变量,
到期线程将被暂停
h_sidespace和v_sidespace
是左右两侧和上下两侧的空白区域
status变量记录线程所处的五种状态,初始值为消失
*/
private font font;
private int x,y,width,height,fontx,fonty;
private int h_sidespace=3,
v_sidespace=3,keep=3,delay=10;
private java.lang.thread draw;
private string text;

private int status = 4;
private final static int draw = 1;
//显示工具提示
private final static int stopdraw = 2;
//停止工具提示并清除
private final static int clear = 3;
//清除工具提示
private final static int hide = 4;
//隐藏工具提示
private final static int suspend = 5;
//暂停线程

public tooltips() {
this(new font("dialog",font.plain,12));
}
public tooltips(font font) {
this.font = font;
}
//提示显示,如果窗体区域不能满足要求,就不会显示
public synchronized void setvisible
(string text,point mouse,rectangle frame) {
if(text==null) return;
this.text = text;
fontmetrics fm = getfontmetrics(font);
int fontwidth = fm.stringwidth(this.text);
int fontheight = fm.getheight();

width = fontwidth + h_sidespace*2;
height = fontheight + v_sidespace*2;
fontx = (width-fontwidth)/2;
fonty = (height - fontheight)/2+fm.getascent();

if(mouse.y-height-20 < 0&&mouse.y
+height+20 >=frame.height) return;
this.x=(mouse.x+width >=
frame.width?(frame.width-width-5 >0?
frame.width-width-5:0):mouse.x);
this.y=(mouse.y+20+height < =
frame.height?mouse.y+20:mouse.y-20-height);

if(draw==null) start();
else if(status == suspend) draw.resume();
status = draw;
}

public synchronized boolean isvisible() {
return (status==draw||status==stopdraw)?true:false;
}
//清除提示文本
public synchronized void setcleared() {
if(status!=draw&&status!=stopdraw) return;
status = clear;
}
public void setdelay(int delay) {
if(delay < 3) //空载时间最少3秒钟
throw new numberformatexception
("delay value error,at the setdelay method");
this.delay = delay;
}
public void setkeep(int keep) {
if(keep < 1) //留屏时间最少1秒钟
throw new numberformatexception
("keep value error,at the setkeep method");
this.keep = keep;
}

public void start() {
if(draw == null) {
draw = new java.lang.thread(this,"draw text");
draw.start();
}
}
public void stop() {
if(draw!=null) {
draw.stop(); draw = null;
}
}
public void run() {
draw.setpriority(thread.norm_priority);
long begintime=new java.util.date().gettime();
while(true) {
switch(status) {
case draw:
super.setbounds(x,y,width,height);
repaint();
begintime = new java.util.date().gettime();
break;
case clear:
super.setbounds(x,y,0,0);
status = hide;
begintime = new java.util.date().gettime();
break;
}
try {
thread.sleep(500);
} catch(interruptedexception ie) {
ie.printstacktrace();
stop();
break;
}

if(status==stopdraw && (new java.util.date()
.gettime()-begintime)/1000 >=keep)
status = clear;
else if(status==hide&&(new java.util.date()
.gettime()-begintime)/1000 >=delay) {
status = suspend; draw.suspend();
}
}

}

public void repaint() {
repaint(0,0,width,height);
}
public void update(graphics g) {
g.setcolor(getbackground());
g.fillrect(0,0,width,height);
g.setcolor(getforeground());
paint(g);
}
public void paint(graphics g) {
if(status==draw||status==stopdraw) {
synchronized(this) {
g.setcolor(color.yellow);
g.fillrect(0,0,width,height);
g.setcolor(color.black);
g.drawrect(0,0,width-1,height-1);
g.setcolor(color.red); g.setfont(font);
g.drawstring(text,fontx,fonty);
status = stopdraw;
}
}
}

}

失效图象过滤类
public class disablefilter extends
java.awt.image.rgbimagefilter {
private int red,green,blue,color;

public int filterrgb(int x,int y,int rgb) {
red = (rgb > >16)&0xff;
green = (rgb > >8)&0xff;
blue = (rgb > >0)&0xff;
if(isrange(red,192,5)&&isrange
(green,192,5)&&isrange(blue,192,5))
color = 192;
else if(isrange(red,255,5)&&isrange
(green,255,5)&&isrange(blue,255,5))
color = 192;
else if(isrange(red,0,5)&&isrange
(green,0,5)&&isrange(blue,0,5))
color = 255;
else
color = 128;
return (rgb&0xff000000|
(color < < 16)|(color < < 8)|color);
}
public boolean isrange(int
color,int base,int margin) {
return color< =base+margin&&color
>=base-margin?true:false;
}
}

---- 本 程 序 在windows95 下, 用borland jbuiler2+jdk1.1.6 调 试 通 过

---- 以 下 另 附 两 个 类, 其 中 一 个 是image 的byte 数 组 类, 另 一 类 是frame 的 派 生 类, 把 这 五 个 类 组 合 一 起, 浮 动 按 纽 即 可 执 行。

import java.awt.*;
import java.awt.event.*;

public class multi extends frame
implements actionlistener,mouselistener{
button butexit = new button();
imagebutton cmdexit = new imagebutton
(imagecode.mbox,imagecode.bomb,
imagecode.sound1,imagecode.mbox,
" 千 古 江 山",imagebutton.horizon);
imagebutton cmdstop =
new imagebutton(imagecode.sound2);
imagebutton cmdinfor =
new imagebutton(imagecode.cowsmall);
tooltips tooltips =
new tooltips(new font("dialog",font.plain,14));

java.lang.thread refresh;

public void actionperformed(actionevent e) {
if(e.getsource() == butexit) {
dispose();
system.exit(0);
}
}
public void mouseclicked(java.awt.event.mouseevent me) {
if(me.getmodifiers()==4) return;
if(me.getsource()==cmdexit && cmdexit.setclicked()) {
cmdstop.setvisible(!cmdstop.isvisible());
}
else if(me.getsource()==cmdstop && cmdstop.setclicked()) {
cmdexit.setenabled(!cmdexit.isenabled());
}
else if(me.getsource()==cmdinfor
&& cmdinfor.setclicked());
}
public void mouseexited(java.
awt.event.mouseevent me) {
if(me.getmodifiers()==4) return;
if(me.getsource()==cmdexit
&& cmdexit.setexited());
else if(me.getsource()==cmdstop
&& cmdstop.setexited());
else if(me.getsource()==cmdinfor
&& cmdinfor.setexited());
}
public void mouseentered
(java.awt.event.mouseevent me) {
if(me.getmodifiers()==4) return;
point mouse = me.getpoint();
rectangle frame = this.getbounds();
if(me.getsource() == cmdexit
&& cmdexit.setentered(mouse,frame));
else if(me.getsource()==cmdstop
&& cmdstop.setentered(mouse,frame));
else if(me.getsource()==cmdinfor
&& cmdinfor.setentered(mouse,frame))
cmdstop.setalignment(cmdstop.getalignment()
==imagebutton.vertical?
imagebutton.horizon : imagebutton.vertical);
}
public void mousepressed(java.awt.event.mouseevent me) {
if(me.getmodifiers()==4) return;
if(me.getsource()==cmdexit
&& cmdexit.setpressed());
else if(me.getsource()==cmdstop
&& cmdstop.setpressed());
else if(me.getsource()==cmdinfor
&& cmdinfor.setpressed());
}
public void mousereleased(java.awt.event.mouseevent me) {
if(me.getmodifiers()==4) return;
point mouse = me.getpoint();
if(me.getsource()==cmdexit
&& cmdexit.setreleased(mouse));
else if(me.getsource()==cmdstop
&& cmdstop.setreleased(mouse));
else if(me.getsource()==cmdinfor
&& cmdinfor.setreleased(mouse));
}

public multi() {
try {
jbinit();
}
catch (exception e) {
e.printstacktrace();
}
}

public static void main(string[] args) {
new multi();
}

private void jbinit() throws nullpointerexception {
dimension d = gettoolkit().getscreensize();
this.setsize(new dimension(536, 307));
this.setlocation((d.width-getsize().
width)/2,(d.height-getsize().height)/2);
this.setlayout(null);
this.settitle(system.getproperty("java.version"));
this.setbackground(color.lightgray);
this.validate(); this.setvisible(true);

this.add(tooltips,null);

butexit.setfont(new font("dialog", 0, 16));
butexit.setbounds(new rectangle(352, 136, 170, 36));
butexit.setlabel("exit frame");
butexit.addactionlistener(this);
this.add(butexit, null);

repaint(0,0,this.getsize().width,this.getsize().height);
cmdexit.setfont(new font("dialog",font.plain,14));
cmdexit.setlocation(new point(10,35));
cmdexit.settooltips(tooltips,
"君不见黄河之水天上来,奔流到海不复回");
cmdexit.setvisible(true);
cmdexit.addmouselistener(this);
this.add(cmdexit,null);

cmdstop.settext("大风起兮");
cmdstop.setfont(new font("dialog",font.plain,14));
cmdstop.setlocation(110,35);
cmdstop.setsize(cmdexit.getsize().
width,cmdexit.getsize().height);
cmdstop.settooltips(tooltips,
"看茫茫大江来天畔,风烟几万年");
cmdstop.setvisible(true);
cmdstop.addmouselistener(this);
this.add(cmdstop,null);

cmdinfor.settext("对潇潇暮雨洒江天");
cmdinfor.setfont(new font("dialog",font.plain,14));
cmdinfor.setlocation(210,260);
cmdinfor.setsize(cmdinfor.getsize().
width+10,cmdexit.getsize().height);
cmdinfor.settooltips(tooltips,
"渐霜风凄紧,关河冷落,残照当楼");
cmdinfor.setvisible(true);
cmdinfor.addmouselistener(this);
this.add(cmdinfor,null);

}

}

public class imagecode {
public static byte mbox[]={
71,73,70,56,57,97,32,0,32,0,-94,0,0,-1,-1,-1,
-49,-49,-49,21,56,-2,0,51,-1,0,0,-1,0,0,-52,
0,0,-103,0,0,0,33,-7,4,1,0,0,1,0,44,0,0,0,0,
32,0,32,0,0,3,-59,24,-70,123,-2,44,-54,-87,
-100,24,120,8,72,123,-67,-104,-109,105,-114,
55,29,-96,99,20,98,-74,-103,12,26,22,-123,97,
15,45,121,-64,-63,49,-45,-76,71,-24,-63,-95,
-56,124,-124,36,43,-109,99,-18,-116,-95,12,-63,
-121,-93,-114,92,79,-119,85,68,-75,94,71,47,-19,
-107,-5,45,-109,-60,101,-81,-103,-119,30,-81,-53,
-31,70,-6,-99,-114,-88,-93,-12,-79,125,-18,36,10,
-39,49,124,56,0,-124,-123,-123,91,123,95,91,-122,
-116,-120,-127,-118,76,0,14,-110,7,-121,-128,114,
-112,33,-110,-108,-100,-114,-104,110,-102,-116,
-106,33,-119,-96,-125,68,-99,-105,
21,-126,-107,-83,-101,-124,-98,
-85,-103,-125,-94,-80,-86,61,-126,85,126,77,89,31,
22,76,121,122,118,59,50,56,-63,35,-67,13,31,-58,-57,
-92,30,62,119,116,-55,98,93,-69,-69,-50,29,40,93,
-49,-37,38,45,-45,-119,-32,90,
69,70,28,9,0,59
};
public static byte bomb[]={
71,73,70,56,57,97,20,0,22,0,-29,0,0,-1,-1,-1,-1,-52,
51,-52,-1,-1,-52,-52,-52,-69,-69,-69,-103,-103,-103,
-120,-120,-120,102,102,102,85,85,85,51,51,51,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,33,-2,78,84,104,105,115,32,
97,114,116,32,105,115,32,105,
110,32,116,104,101,32,112,117,98,108,105,99,32,
100,111,109,97,105,110,46,32,75,101,
118,105,110,32,72,117,103,104,101,115,44,32,107,
101,118,105,110,104,64,101,105,116,46,99,111,109,
44,32,83,101,112,116,101,109,98,101,114,32,49,57,
57,53,0,33,-7,4,1,0,0,2,
0,44,0,0,0,0,20,0,22,0,0,4,-113,48,-55,73,-89,-72,88,
36,-64,-69,-33,73,118,109,94,73,-122,-39,22,0,10,
-80,118,36,-128,-114,-35,-5,125,-40,
-90,4,73,-48,118,-118,68,112,
72,-29,4,10,37,-123,114,-87,-96,-83,20,5,91,-89,64,
45,52,53,31,-31,111,74,-67,-58,0,8,-88,86,49,-104,
122,61,98,4,-11,64,-26,88,-117,28,-91,
26,96,56,-124,-53,111,44,-70,64,
-96,-37,-123,0,121,95,44,85,127,-128,-126,73,7,
-118,8,18,74,-127,103,104,-117,-115,-114,-120,30,
3,65,-115,66,120,-112,-106,67,74,101,-113,112,-99,
-97,102,-94,37,-89,-126,9,85,-85,-84,84,66,
25,76,-79,-78,87,17,0,59
};
public static byte sound1[]={
71,73,70,56,57,97,20,0,22,0,-62,0,0,-1,-1,-1,-1,51,51,
-52,-1,-1,-52,-52,-52,-103,-103,-103,
102,0,0,51,51,51,0,0,0,33,-2,78,84,104,105,
115,32,97,114,116,32,105,
115,32,105,110,32,116,104,101,32,112,117,98,108,
105,99,32,100,111,109,97,105,110,46,32,75,101,118,
105,110,32,72,117,103,104,101,115,44,32,107,101,
118,105,110,104,64,101,105,116,46,99,
111,109,44,32,83,101,112,116,101,109,98,101,
114,32,49,57,57,53,0,33,-7,4,1,0,0,2,0,44,0,0,0,0,
20,0,22,0,0,3,107,40,-70,-36,-2,48,54,-61,66,-112,-22,28,
97,85,-113,7,-79,113,23,9,-123,-64,104,126,13,
-102,114,-98,119,105,52,1,-36,91,-41,21,65,72,
-4,-74,-37,107,119,-31,-71,-124,-62,13,79,-80,52,
6,-111,56,102,113,122,-124,42,-89,-46,42,
-14,42,-51,18,12,-33,111,-46,-44,-100,-47,14,3,
67,84,-121,21,24,-34,6,-76,58,23,51,77,-28,42,54,
36,62,24,125,74,123,26,118,44,123,20,
11,-124,24,-119,-118,11,9,0,59
};
public static byte sound2[]={
71,73,70,56,57,97,20,0,22,0,-62,0,0,-1,-1,-1,
-52,-1,-1,-52,-52,-52,-103,-103,-103,102,102,
102,51,51,51,0,0,0,0,0,0,33,-2,78,84,104,105,
115,32,97,114,116,32,105,
115,32,105,110,32,116,104,101,32,112,117,98,
108,105,99,32,100,111,109,97,105,110,46,32,75,
101,118,105,110,32,72,117,103,104,101,115,44,32,
107,101,118,105,110,104,64,101,105,116,46,99,
111,109,44,32,83,101,112,116,101,109,98,
101,114,32,49,57,57,53,0,33,-7,4,1,0,0,1,0,44,0,0,
0,0,20,0,22,0,0,3,80,24,-70,-36,-2,-50,72,-8,-92,45,116,89,
67,36,-90,27,33,122,80,40,10,87,-55,-99,-101,-15,
69,28,122,-111,85,91,-36,52,-20,-35,74,-34,-20,-81,
-128,-113,49,20,-70,84,47,27,-78,103,0,12,-118,
-52,79,-13,57,84,26,55,65,-119,
51,-121,-51,110,125,55,30,-47,-102,97,-18,
-54,-116,112,16,-51,94,36,0,0,59
};
public static byte cowsmall[]={
71,73,70,56,57,97,27,0,19,0,-12,0,0,-1,-1,-1,-1,-4,
-4,-1,-5,-5,-1,-8,-8,-1,-9,-9,-1,-14,-14,-1,-19,-19,-1,
-25,-25,-1,-28,-28,-1,-37,-37,-1,-42,-42,-1,-51,-51,-64,
-64,-64,-44,-44,-44,-65,-65,-65,-86,-86,-86,127,127,
127,85,85,85,63,63,63,42,42,42,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,33,-7,4,1,0,0,12,0,44,0,0,0,0,27,0,19,
0,0,5,-37,32,35,-114,100,105,-98,100,-12,-96,-24,58,
62,17,20,21,-113,12,65,78,3,-23,
81,36,57,-127,32,-94,39,122,72,38,18,-60,-124,-62,
100,20,100,-58,-55,114,-46,-88,-11,-112,35,8,-59,-79,
-12,53,2,19,-56,-108,73,-127,28,39,17,-20,-120,-62,96,
-90,113,18,-78,60,66,89,
82,-120,34,-57,-115,25,70,-58,-53,123,20,127,
126,48,47,18,18,116,20,1,119,118,18,5,1,13,14,12,
104,17,14,70,36,53,12,113,13,116,90,77,1,6,6,-113,
65,122,44,104,13,20,
15,117,59,5,34,-94,1,12,8,15,8,40,102,-100,86,5,5,57,
16,65,85,58,13,44,16,-94,97,-66,34,8,13,-78,
-64,59,44,15,95,-121,53,43,85,78,59,18,16,46,40,14,6,53,
14,-36,15,-36,12,6,55,-37,44,12,-110,15,-41,47,36,56,
-28,12,43,-24,69,-25,34,42,-28,-15,39,-25,-110,-19,
-20,-42,49,-17,-36,-8,-106,-28,-52,93,115,
-48,-61,-38,-117,7,33,0,0,59
};
public static byte dot[]={
71,73,70,56,57,97,13,0,13,0,-94,-1,0,-1,0,0,
-64,-64,-64,-52,0,0,-103,0,0,-128,0,0,102,0,0,0,0,0,
0,0,0,33,-7,4,1,0,0,1,0,44,0,0,0,0,
13,0,13,0,64,3,42,24,-70,-78,91,-112,12,33,-128,5,
10,22,73,47,118,12,40,6,-43,-105,69,83,-23,-119,-27,
-56,-104,-25,-106,94,15,-38,-83,26,-89,90,
65,62,-13,-82,10,40,1,0,59
};
}
 
 
上一篇: 用java开发代理服务器    下一篇: 用java实现ubb代码
  相关文档
mysql实施jdbc 2.0/3.0 api的新特性学习实践 11-17
java的按位运算符 11-17
详解如何利用itext在jsp中生成pdf报表 11-17
j2ee web服务客户端质量报告(二) 11-16
java.util包简介 如何开发应用之一 11-17
eclipse form程序设计快速入门 11-16
java特效生成器──anfy java 11-17
java入门--关于角色访问控制(rbac) 01-24
java中的参数传递与对象clone详细讲解 11-16
java文萃:世界各地开发高手谈java(上) 11-16
huihoo.org发布了jfoxmx的最新版本1.2 11-17
jvm之class文件结构 11-17
浅论设计 11-17
vj6.0的使用方法(5)applet编写调试过程 11-16
java io学习基础之读写文本文件 11-17
入门:java连接各种数据库的实例 11-17
“网络蚂蚁”的java实现 11-17
j2me综合--jar文件包及jar命令详解 01-10
编程经典技术:spring的巧妙之处 11-17
ejb最佳实践:如何做实体bean的保护 11-17
返回首页 | 关于我们 | J网章程 | JSP空间合租 | 客服中心 | 免责声明 | 常见问题 | 参观机房
本站主机空间代理至厦门市华众网络科技有限公司
《中华人民共和国增值电信业务经营许可证》
编号:闽B2-20050079
@2005-2008福建JSP技术网 版权所有 闽ICP备05000928号
技术电话:13616026886
邮箱:admin@fjjsp.com 站长QQ,点击这里给我发消息