动态网站制作指南 [  QQ表情  ]
[ 投票调查 ]
[ 企业邮箱 ]
[ 网站空间 ]
网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
ASP源码 | .Net源码 | PHP源码 | JSP源码 | JAVA源码 | CGI源码 | VB源码 | C++源码 | Delphi源码 | PB源码 | VF源码 | 汇编 | 服务器
电脑书籍下载:程序设计书籍 | 数据库教程书籍 | 平面与多媒体书籍 | 网络通讯书籍 | 系统管理书籍 | 网络安全书籍 | 认证考试书籍
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > Java教程
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
文章搜索服务
邮件订阅
输入你的邮件地址,
你将不会错过任何关于:
[ Java教程 ]的信息



本月文章推荐
.关于构建一个使用EJB组件的新系统.
.《实时UML与Rational Rose RealT.
.Why Java can be used for games?.
.JXTA概念介绍.
.new 运算符.
.java.net 操练.
.面向对象编程:Java collection更.
.论全世界所有程序员都会犯的错误2.
.教您如何成为 EJB 专家详解系列连.
.Struts快速学习指南之一.
.Java 繁体中文处理完全攻略(二).
.简述JAVA对象的产生与使用.
.EJB 访问代理设计常用的访问方式.
.Eclipse快速上手指南之使用JUnit.
.精通ejb【三】.
.为Web应用程序框架配置JDBC-ODBC.
.Java中鲜为人知的缺点(上).
.java多线程设计模式详解之三.
.用Java动态代理实现AOP.
.setUTCDate 方法.

用Applet写的菜单程序 machine

发表日期:2008-1-5 |



  前几天在Java.sun.com上看见一个用Applet写的菜单程序。由于Applet目前不支持Menu(
据我所知),: 也许这个程序对你有些帮助。
原来的程序似乎不完整,无法编译,我特地到java.sun.com上又载了一个,
source如下:
/*
Copyright: Sun Microsystems 1997. All rights reserved.
Author: Patrick Chan (www.xeo.com) 7/19/96
Version: 1.1
*/

import java.applet.*;
import java.awt.*;
import java.util.*;
import java.net.*;

public class XeoMenu extends Applet {
// The background image. This had better not be null.
Image image;

// These two fields are used to do double-buffering.
// The dimensions of bbuf is exactly the dimensions of the applet.
Image bbuf;
Graphics bbufG;

// This field is set to true only when the background image has
// completely loaded.
boolean imageDone;

/* Menu data */
Rectangle[] hitArea;
Rectangle[] srcRect;
Point[] dstPt;
boolean[] down;
String[] url;

/* Submenu data */
String[][] itemUrl;
String[][] item;

// If >= 0, this fields holds the index of the current menu.
// If -1, no menu is current.
int curMenu;

// If >= 0, this fields holds the index of the current menu item.
// If -1, no menu item is current.
int curMenuItem;

// This is an array of rectangles - one rectangle for each menu item.
// Each rectangle specifies the
// location (relative to the left-corner of the applet) of a menu item.
//
// menuItemRect is null when curMenu is -1.
// It becomes non-null when curMenu >= 0.
//
// Note: it would have been better programming to define classes for
// the menu and menu items. However, I decided for this little applet
// to keep the number of class files to a minimum to minimize the download
// time.
Rectangle[] menuItemRect;

// This is the color to paint "behind" the image.
Color bgColor;

// [0] is the text color of a menu item; [1] is the text color of a highlig
hted // menu item.
Color fgMenUColor[] = new Color[2];

// This is the background of a menu item; [1] is the background color of a
// highlighted menu item.
Color bgMenuColor[] = new Color[2];

// marginH is the number of pixels on the left and right edges of the menu.
// marginV is the number of pixels on the top and bottom edges of the menu.
int marginH, marginV;

// This is the font used to display the menu item labels.
Font f;

// This is the font metrics of 'f'.
FontMetrics fm;

public void init() {
int[] ints;

// Grab applet parameters.
image = getImage(getCodeBase(), getParameter("image"));
marginH = Integer.parseInt(getParameter("marginh"));
marginV = Integer.parseInt(getParameter("marginv"));

// Get color parameters.
ints = parseInt(getParameter("bg-color"), " ");
bgColor = new Color(ints[0], ints[1], ints[2]);
ints = parseInt(getParameter("fg-menu-color"), " ");
fgMenuColor[0] = new Color(ints[0], ints[1], ints[2]);
ints = parseInt(getParameter("fg-hi-menu-color"), " ");
fgMenuColor[1] = new Color(ints[0], ints[1], ints[2]);
ints = parseInt(getParameter("bg-menu-color"), " ");
bgMenuColor[0] = new Color(ints[0], ints[1], ints[2]);
ints = parseInt(getParameter("bg-hi-menu-color"), " ");
bgMenuColor[1] = new Color(ints[0], ints[1], ints[2]);

// Create back buffer for double-buffering.
bbuf = createImage(size().width, size().height);
bbufG = bbuf.getGraphics();

// Determine the font from the font-height.
int fh = Integer.parseInt(getParameter("font-height"));
int i = fh;
while (i > 10) {
f = new Font(getParameter("font"), Font.PLAIN, i);
fm = getFontMetrics(f);
if (fm.getHeight() <= fh) {
break;
}
i--;
}

// Get the menu parameters.
for (i=0; ; i++) {
if (getParameter("menu"+i) == null) {
hitArea = new Rectangle[i];
srcRect = new Rectangle[i];
dstPt = new Point[i];
url = new String[i];
down = new boolean[i];
itemUrl = new String[i][];
item = new String[i][];

break;
}
}

for (i=0; i String[] fields = parse(getParameter("menu"+i), getParameter("separ
ator"));
// Get the hit area.
ints = parseInt(fields[0], " ");
hitArea[i] = new Rectangle(ints[0], ints[1], ints[2], ints[3]);

// Get the source image.
ints = parseInt(fields[1], " ");
srcRect[i] = new Rectangle(ints[0], ints[1], ints[2], ints[3]);

// Get the destination point.
ints = parseInt(fields[2], " ");
dstPt[i] = new Point(ints[0], ints[1]);
down[i] = fields[3].equals("d");
url[i] = fields[4];

item[i] = new String[(fields.length-5)/2];
itemUrl[i] = new String[(fields.length-5)/2];
for (int j=0; j item[i][j] = fields[j*2+5];
itemUrl[i][j] = fields[j*2+6];
}
}
}

// s is a string containing 'sep' separators. This method
// breaks up the string at the separators and returns the resulting
// strings in an array. The result may have zero length but is never null.
String[] parse(String s, String sep) {
StringTokenizer st = new StringTokenizer(s, sep);
String result[] = new String[st.countTokens()];

for (int i=0; i result[i] = st.nextToken();
}
return result;
}

// This method is similar to parse() except that the strings are
// assumed to be decimal integers. This method coverts these integer
// strings into integers and returns them in an array.
// The result may have zero length but is never null.
int[] parseInt(String s, String sep) {
StringTokenizer st = new StringTokenizer(s, sep);
int[] result = new int[st.countTokens()];

for (int i=0; i result[i] = Integer.parseInt(st.nextToken());
}
return result;
}

public void paint(Graphics g) {
imageDone = false;
update(g);
}

public void update(Graphics g) {
Graphics g2;

if (!imageDone) {
imageDone = g.drawImage(image, 0, 0, this);
return;
}

bbufG.setColor(bgColor);
bbufG.fillRect(0, 0, size().width, size().height);
bbufG.drawImage(image, 0, 0, this);

if (curMenu >= 0) {
g2 = bbuf.getGraphics();
// Paint the overlay image
g2.clipRect(dstPt[curMenu].x, dstPt[curMenu].y,
srcRect[curMenu].width, srcRect[curMenu].height);
g2.drawImage(image, dstPt[curMenu].x-srcRect[curMenu].x,
dstPt[curMenu].y-srcRect[curMenu].y, this);
g2.dispose();

g2 = bbuf.getGraphics();
for (int i=0; i drawMenuItem(g2, i);
}
g2.dispose();
}
g.drawImage(bbuf, 0, 0, this);
}

void drawMenuItem(Graphics g, int i) {
int x, y, w, height;
// break the menu item label into lines.
String[] line = parse(item[curMenu][i], getParameter("newline"));

int hi = 0;
if (i == curMenuItem) {
hi = 1;
getAppletContext().showStatus(itemUrl[curMenu][i]);
}
g.setColor(bgMenuColor[hi]);
g.fillRect(menuItemRect[i].x, menuItemRect[i].y,
menuItemRect[i].width, menuItemRect[i].height);

// set color for text and box
g.setColor(fgMenuColor[hi]);

// draw box around menu item.
g.drawRect(menuItemRect[i].x, menuItemRect[i].y,
menuItemRect[i].width, menuItemRect[i].height);

// draw label
g.setFont(f);
y = menuItemRect[i].y + marginV;
for (i=0; i g.drawString(line[i],
menuItemRect[i].x+menuItemRect[i].width-fm.stringWidth(line[i])
-marginH, y + fm.getAscent());
y += fm.getHeight();
}
}

public boolean mouseExit(Event evt, int x, int y) {
curMenuItem = curMenu = -1;
repaint();
return true;
}

public boolean mouseEnter(Event evt, int x, int y) {
return mouseMove(evt, x, y);
}

public boolean mouseDown(Event evt, int x, int y) {
try {
String u = null;

if (curMenuItem >= 0 && itemUrl[curMenu].length > 0) {
u = itemUrl[curMenu][curMenuItem];
} else if (curMenu >= 0) {
u = url[curMenu];
}
if (u != null) {
URL url = new URL (getDocumentBase(), u);

if (getParameter("target") != null) {
getAppletContext().showDocument(url, getParameter("target")
); } else {
getAppletContext().showDocument(url);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return true;
}

public boolean mouseMove(Event evt, int x, int y) {
if (curMenu >= 0) {
int sm = inMenu(menuItemRect, x, y);

if (curMenuItem != sm) {
curMenuItem = sm;
repaint();
}
if (sm >= 0) {
return true;
}
curMenu = -1;
}

int m = inMenu(hitArea, x, y);
if (m != curMenu) {
curMenu = m;

// A new menu is now active so compute menuItemRect.
if (m >= 0) {
// Minimum width
int maxWidth = 50;
int maxHeight = 0;

menuItemRect = new Rectangle[item[curMenu].length];
for (int i=0; i String[] line = parse(item[curMenu][i], "^");

for (int j=0; j int w = fm.stringWidth(line[j]);
if (w > maxWidth) {
maxWidth = w;
}
}

menuItemRect[i] = new Rectangle();
menuItemRect[i].height =
parse(item[curMenu][i], "^").length * fm.getHeight()
+ 2 * marginV;
maxHeight += menuItemRect[i].height;
}

// Determine domain of submenus

// Add one extra pixel for the left edge.
maxWidth += 2 * marginH + 1;
if (down[m]) {
y = Math.max(0, Math.min(size().height-maxHeight-1,
dstPt[curMenu].y + srcRect[curMenu].height-1));
} else {
y = Math.max(0, Math.min(size().height-maxHeight-1,
dstPt[curMenu].y - maxHeight));
}
x = dstPt[curMenu].x + srcRect[curMenu].width-maxWidth-1;
for (int i=0; i menuItemRect[i].x = x;
menuItemRect[i].y = y;
menuItemRect[i].width = maxWidth;
y += menuItemRect[i].height;
}
getAppletContext().showStatus(url[curMenu]);
}
}
repaint();
}
return true;
}

// Returns the index of the rectangle in rs containing x and y.
// Returns -1 if either rs is null or x and y is not in rs.
int inMenu(Rectangle[] rs, int x, int y) {
if (rs != null) {
for (int i=0; i if (rs[i].inside(x, y)) {
return i;
}
}
}
return -1;
}
}
上一篇:用AWT组件实现登录对话框 人气:611
下一篇:用ChoiceFormat将数字与字符串联系起来 人气:369
浏览全部Java的内容 Dreamweaver插件下载 常用网页广告代码全集
  最新网站源码 最新软件下载
2008-7-23 Menalto Gallery v2.3 Rc1 多国语
2008-7-23 深度学习网址导航系统 v2.6.1
2008-7-23 因特达crm2008客户关系管理系统
2008-7-23 60度 CMS v1.0 Build 080723
2008-7-23 幻影动漫网视频系统(Ppdong) v1.
2008-7-23 好易祝福墙 2008
2008-7-23 APJE私服发布系统 v2.0 PHP版
2008-7-23 毕业论文在线指导系统源码
2008-7-23 Jacky法律在线网站源码
2008-7-19 UltraEdit 简体中文增强版 14.10
2008-7-19 CentOS 5.2 i386 LiveCD
2008-7-19 Snapture多功能相机 v1.4
2008-7-19 iAcces中文输入法 v1.0Build016
2008-7-19 Cookbook烹饪秘籍 v2.5
2008-7-19 苹果专用DVD转换工具 v1.1.59汉化
2008-7-19 Modem修复软件ZiPhone修改版04.0
2008-7-19 AgileMessenger即时通讯工具美化
2008-7-19 Sketches画图软件 v0.7b6破解版


  发表评论
姓 名: 验证码:
内 容:
[ 汉字翻译拼音 ] [ 广告代码 ] [ 符号对照表 ] [ 进制转换 ] [ 经典小工具 ] [ 个税计算 ] [ 汉字简繁转换 ] [ 普通单位换算 ] [ 公制单位换算 ]
[ 生辰老黄历 ] [ 国内电话区号 ] [ 国家代码与域名缩写 ] [ 文字加密解密 ] [ 健康查询 ] [ 万年历 ] [ 手机号码查询 ] [ ip搜索 ] [ Google PR查询 ]
业务联系 | 广告刊登 | 频道合作 | 投稿荐稿 | 联系方式 | 加入收藏 | RSS订阅
Copyright © 2000-2008 www.knowsky.com All rights reserved | 网络实名:动态网站制作指南 | 沪ICP备05001343号