可行性研究报告
1引言
在信息高度发达的今天,酒店业务涉及的各个工作环节已经不再仅仅是传统的住宿、结算业务,而是更广、更全面的服务性行业代表。酒店作为一个服务性行业,从客房的营销即客人的预定开始,到入住登记直至最后退房结帐,整个过程应该能够体现以宾客为中心,提供快捷、方便的服务,给宾客感受一种顾客至上的享受,提高酒店的管理水平,简化各种复杂操作,在最合理最短时间内完成酒店业务规范操作,这样才能令旅客舒适难忘,增加宾客回头率。面对酒店行业内激烈的竞争形势,各酒店均在努力拓展其服务领域的广度和深度。因此,采用全新的计算机网络和管理系统,将成为提高酒店的管理效率,改善服务水准的重要手段之一。
1.1编写目的
本可行性研究报告的编写目的在于,对酒店管理系统作充分的可行性研究分析及指出其存在的重要性。分析、对比原有的酒店管理与用计算机管理和控制的酒店管理系统,明确开发酒店管理系统的方向、有效途径,确定开发本管理系统所采取的步骤、方法及对策。
预期的读者:中间用户(软件的管理人员、开发人员、维护人员)、最终用户(中高级管理人员和酒店业主)。
1.2背景
1.2.1 工程的名称: 酒店管理系统
1.2.2 工程产品的名称: 酒店管理系统
1.2.3 工程组织者: 酒店管理系统开发小组
产品用户: 中高级管理人员和酒店业主或老板
产品设计者: 酒店管理系统开发小组
产品生产者: 酒店管理系统开发小组
1.2.4 产品所有权: 酒店管理系统开发小组拥有
1.3参考资料
《软件工程》 ----张海藩 编著
清华大学出版社
《数据库系统概论》 ----萨师煊 王珊 编著
高等教育出版社
《现代酒店经营》 ----詹益政 编著
南方日报出版社
2可行性研究的前提
2.1要求
系统能够最大限度的利用有限资源快速准确收集、处理、分析统计酒店发生的信息资源。提供各种数据查询方式,方便管理人员进行查询。能够形成各种数据报表,及时准确反映酒店业务情况。系统各模块功能相互独立,利用数据流相互关联,最大的限制错误录入,实现内部资源共享。安全性方面,系统采用计算机管理避免手工输入的弊病,利用计算机进行科学的优化业务流程,构筑合理的管理架构和完善的管理制度。数据采用多级保护,减少酒店数据丢失。
酒店管理系统模块功能简介:前台接待模块,前台收银管理,客房预定管理,客房管理模块,报表管理模块,核数管理,经理查询及辅助决策分析模块,系统设置管理。
本系统预计将于四个月内完成,工程开始时间:20##年1月;结束时间:20##年5月。
2.2目标
酒店管理系统采用科学的管理思想与先进的管理手段的完善结合。可帮助酒店管理人员,对酒店管理过程中大量动态的、错综复杂的数据和信息进行及时准确的分析和处理,从而使酒店管理真正由经验管理进入到科学管理,帮助经营者更好的管理酒店、成本控制和客户来源,从而提高酒店的经营效益。
2.3进行可行性研究的方法
本系统的可行性研究时通过开发小组历时十天的时间调查分析后得出的,主要是通过调查现有的系统,分析开发酒店管理系统所具备的能力及实现的方法。确定出新系统的总体结构,最终形成一个完善的系统软件。
2.4评价尺度
利用目前流行的WINDOWS编程开发一个较为完善的产品,以能够达到提高酒店管理人员的工作效率、减少额外人力、物力资源开销为评价标准。
3对现有系统的分析
3.1 现有系统的处理流程(部分)
3.2工作负荷
在现有的酒店管理系统处理过程中,如果采用人工手动进行管理的话,管理人员所要处理的各种数据信息非常庞大,而且数据信息的保存采用纸张保存,同时,数据保存、数据处理和数据交换等也都需要人工进行,而在这个过程当中很容易出现人为的失误。
3.3费用开支
目前的酒店业务管理需要大量的人力,物力资源,需要为此付出大量的人员工资,住房等;同时,需要花费大量的时间进行各项数据的计算,统计,分析等。
3.4人员
目前的酒店业务管理所需要的人员并不要求具备有很高的专业技术,但却需要很多的人员数量。
3.5 局限性
目前的酒店管理需要的人员数量太多,管理不方便,业务处理时间赶不上需要,响应不及时,数据存储能力不足,处理功能不够,数据处理时间太长,数据安全性,稳定性较差。
4所建议的系统
4.1对所建议系统的说明
酒店计算机管理系统采用业界先进的C/S架构模式,关系数据库采用大型数据库MICRSOFT SQL SERVER 2000,能够存储大量的数据信息,保证数据的安全性,稳定性,减少数据丢失,实现内部资源共享。系统采用C++作为前端开发语言,操作界面为传统Windows用户界面,操作方便,避免手工输入的弊病,能够最大的限制错误录入。
4.2处理流程和数据流程
酒店管理系统流程图:
4.3改进之处
本系统的高度集成化,系统基于现代先进的操作平台 WINDOWS 98 & WINDOWS 2000,运用强大的SQL数据库引擎,数据随手可得;各种报表随时可得,而且一定是最新的资料,当你对报表中某些数据产生疑问,你可以立刻找到相关的原始资料,你不必再从堆积如山的单据中翻找;人人都有责任感使管理者变得轻松,员工特有的权限和操作密码使操作员必须对自己的操作负责。系统即时反映客人消费情况,避免不应有的损失。客人将得到精确细目帐单,系统作到精确为每一笔细节;不管是财务总控还是总经理决策,都需要即时的数据,系统对日常营业资料进行统计分析,使管理者得到极有价值的决策信息:欢迎新客人,不忘老客人,客户历史资料与接待系统和预订系统连为一体,只要客人报上已有帐号或用证件号码,系统会自动寻找客户资料无须再次填写,迅速入住,真正的WINDOWS设计,全面体现多任务,鼠标点击,快捷键等,极其方便。
4.4影响
4.4.1对设备的影响
本系统对计算机硬件配置要求较高。本系统支持Windows 98/2000。对硬件的最低要求:Pentium 166MHz处理器(或同级的兼容处理器),64M内存(推荐为64M,最高为4G),16M显卡,至少500M的硬盘剩余空间。推荐配置:Pentium III 600MH处理器,256M内存,16M显卡,100M自适应网卡,2G的硬盘剩余空间。同时,需要安装打印机外部设备。
4.4.2对软件的影响
本系统支持的操作系统有Windows 98se/ 20## SERVER,需要安装MICROSOFT SQL SERVER2000数据库系统,系统在使用时对其他软件不会发生冲突。
4.4.3对用户单位机构的影响
建议在酒店对工作人员进行培训,通过对系统应用的培训,加强酒店工作人员规范的工作流程及高度责任心;计算机基础及应用平台(WINDOWS 9X/2000)的培训,对操作人员进行酒店管理软件(系统各部分功能)及硬件(打印机)的使用培训;帮助系统管理员建立系统管理、数据维护、软件使用的日常维护能力,操作员经考试合格后方可上岗。
4.4.4对系统运行过程的影响
用户可将本系统随意安装在计算机的任意位置。对输入数据预处理的过程无影响。系统数据统一采用数据库存储,定期对数据进行备份,避免数据丢失。
4.4.5对开发的影响
为了开发这个系统,需要用户的密切配合。用户需要向开发人员解释酒店管理的整个工作流程,帮助开发人员理解酒店管理工作的各个环节。在建立数据库时,需要原有酒店管理系统的各种原始数据表单(如原有的客户资料表,各种合同,合约,报表的原始样式)。同时,为了开发和测试新系统,需要几台配置较好的计算机,接有打印机外部设备。最后,系统数据库中保存的财务数据,各种合约,报表等都必须要进行保密性与安全性等方面的考虑。
4.5局限性
由于开发人员经验不足,日期较短,又因为酒店管理内容繁多,所以所涉及的范围不够全面。目前我们的使用范围非常狭窄,且本软件是我们的初次版本,如果该软件提高版本,本软件需要大量的修改和更新。
4.6技术条件方面的可行性
在当前的限制条件下,本系统的功能目标能够达到;利用现有的技术,本系统的功能能够实现;系统现阶段的发展过程中,利用现有人力和物力是完全具备的能力开发出来的,作为阶段性产品,日后的发展空间大,实现方法逐步简单容易,所以酒店管理系统在技术上是完全可行的。小组开发人员的数量和质量完全能够满足开发本系统的要求,并且能够在规定的期限内开发完成系统。
5可选择的其他系统方案
5.1可选择的其他系统方案
5.1.1 该方案与首选方案的不同
首选方案是应用面向对象技术,它以采用现代流行关系数据库系统MICROSOFT SQL SERVER7.0/2000存放数据信息,基于客户╱服务器的体系结构,从而极大提高了系统速度,维护和继承功能。
5.1.2 本方案的概况
本方案所有界面的思想与选定方案相同,但是它采用结构化设计方法。本方案程序比较复杂,编译过程复杂。
5.1.3 不选此方案的原因
a. 不利于程序的修改,在这种方案中程序用到的数据分布在程序体的各个部分,如修改必在整个程序中寻找,而首选方案是采用大型关系型数据库存储数据,较容易查错并修改。
b. 用结构化设计方法,程序比较复杂,繁琐。
c. 如果数据量较大,就会在程序过程中产生大量冗余,容易使程序出错。
6社会因素方面的可行性
6.1法律方面的可行性
本产品是采用面向对象技术进行开发,是一个相对独立的技术产品,通过正当法律程序开发、应用本产品将会得到合法利益。
6.2使用方面的可行性
例如从用户单位的行政管理、工作制度等方面来看,是否能够使用该软件系统;从用户单位的工作人员的素质来看,是否能满足使用该软件系统的要求等等,都是要考虑的。
a. 对酒店工作制度的管理,人员的调整合理化是可行的;
b. 用户单位的工作人员具有计算机基础知识完全可以使用该产品;
c. 该产品使用的环境为酒店的各个部门。
6.3经济方面的可行性
本产品开发人员少,投资少,技术含量高,同时它带来了无形的,较大的收益,因此本产品在经济上是可行的。
7 产品可检测性
7.1 检测标准
软件标准:软件规模、复杂程度、安全性、可操作性、可观察性、可控制性、冗余的大小。
7.2 检测的方法
通过软件测试:
黑盒测试:主要在软件界面上进行的测试。
白盒测试:在重要逻辑路径进行测试,检测重要数据结构的有效性。
8 产品的可生产性
酒店管理系统使用面向对象编程语言可以达到开发效果,有着技术的先进性和可行性。
8.1 生产标准
8.1.1 质量标准
正确性:程序是否按程序流程图及数据字典完成程度。
可靠性:安全运行时间越长越好。
可用性:是否能够解决实际的存在问题。
完整性:对未授权的人员访问此系统软件可控性强。
灵活性:修改一个程序的工作量。
8.1.2 生产工艺
光盘可满足装载。
9 可行性综合分析
9.1 技术方面
本工程产品开发周期为四个月,在技术方面采用面向对象技术与数据库相结合方法来实现。要求所有数据信息的储存都由数据库来完成,而这些数据信息的调用必须由面向对象编程设计完成。
9.1.2 社会方面
酒店方面的大力支持,对我们工程的进程非常有利。
9.2 竞争者分析
目前,大部分的相应软件都是用结构化设计方法。并且其功能方面不够完善。他们的软件对用户的要求过高,并需要长时间的培训,我们不仅在技术上占有先进性,而且当产品生产出来后可大大减轻用户的负担。这会保证我们在竞争中占有很大的优势。
9.3 可行性结论
综上所述,本工程的技术成熟先进、完备,测试手段可靠,具有良好的市场拓展,系统设计合理层次分明,实用性强,投资与收益比例适当,具有一定开发价值,因此本工程可立即开始。
10 结论
综上所述,本工程的技术成熟、完备,测试手段可靠,具有良好的市场拓展,因此本工程可立即开始。
第二篇:酒店管理系统源代码
Sunsdk包
1)System包
CsHashtable.java
/*
* @(#)CsHashtable.java 1.24 03/12/19
*
* public class
*
* Copyright 20## CazoSoft, Inc. All rights reserved.
*/
package sunsdk.system;
import java.util.*;
/**
* <code> CsHashtable </code>
* <p>
* 该类的作用是封装哈希表
* <p>
* <strong>注意: </strong> 本类使用的哈希表方法 put, 可能存在不安全因素
* <p>
* 相关类:Hashtable
*
* @author 鲜强
* @version 2006.3.28 22:18
* @see java.util.Hashtable
* @since CAZOSOFT 1.0
*/
public class CsHashtable {
/**
* 静态变量功能: 构造一个 hashtable 供其他函数使用
*/
private static Hashtable hTable = new Hashtable();
/**
* 构造函数功能: 构造函数为静态的不能创建对象
*/
private CsHashtable() {
}
/**
* 放入对象函数功能: 把对象放入哈希表,对象为Object类型
*
* @param key :
* 键值, Object 对象
* @param value :
* 对象, Object 对象
*/
public static void put(Object key, Object value) {
hTable.put(key, value);
}
/**
* 返回对象函数功能: 从哈希表中取出对象,返回为Object类型
*
* @param key :
* 键值
* @return : 一个 Object 对象
*/
public static Object get(Object key) {
return hTable.get(key);
}
/**
* 返回大小函数功能: 返回哈希表的大小
*
* @return : 一个 int 哈希表长度值
*/
public static int size() {
return hTable.size();
}
/**
* 移除一个对象
*
* @param key : 接受一个要移除的键值
*/
public static Object remove(Object key) {
return hTable.remove(key);
}
}/**
Sunini.java
*##############################################################################
*
* [ 项目名 ] :
* [ 公司名 ] : SunshineSOFT
* [ 模块名 ] : 对于INI文件的相关操作
* [ 文件名 ] : sunini.java
* [ 相关文件 ] : config.ini
* [ 文件实现功能] : 读取和保存INI文件
* [ 作者 ] : 顾俊
* [ 版本 ] : 1.1
* ----------------------------------------------------------------------------
* [ 备注 ] :
* ----------------------------------------------------------------------------
* [ 修改记录 ] :
*
* [ 日 期 ] [版本] [修改人] [修改内容]
* 2006/03/31 1.0 顾俊 创建
* 2006/04/06 1.1 顾俊 修改读取函数
* ##--------------------------------------------------------------------------
* 版权所有(c) 20##-2007, SunshineSOFT Corporation
* --------------------------------------------------------------------------##
*
* [ 函数说明 ] :
*
* [## private sunini() {} ]:
* 功能: 构造函数
*
* [## public static String getIniKey (String k) {} ]:
* 功能: 获得INI文件中的指定键的键值
*
* [## public static void setIniKey (String k, String v) {} ]:
* 功能: 设置k键的键值为v对象
*
* [## public static void saveIni (String k[]) {} ]:
* 功能: 将k字符数组中所有键所对应的键值保存到INI文件中
*
* [ 遗留问题 ] : setIniKey ()方法不能处理键值中的转义字符
*
*##############################################################################
*/
package com.sunshine.sunsdk.system;
import java.util.*;
import java.io.*;
public class sunini {
private static Properties ini = null;
static {
try {
ini = new Properties ();
ini.load (new FileInputStream ("config.ini"));
}catch (Exception ex) {
System.out.println ("Load CONFIG.INI is false!!");
}//End try
}
/**=======================================================================**
* [## private sunini() {} ]: 构造函数
* 参数 :无
* 返回值:无
* 修饰符:private
* 功能 :防止实例化sunini对象
**=======================================================================**
*/
private sunini() {
}
/**=======================================================================**
* [## public static String getIniKey (String k) {} ]:
* 参数 :String对象表示键
* 返回值:String对象表示k键所对应的键值,如果失败则返回空串
* 修饰符:public static 可以不实例化对象而直接调用方法
* 功能 :获得INI文件中的指定键的键值
**=======================================================================**
*/
public static String getIniKey (String k) {
if(!ini.containsKey (k)) { //是否有 k 这个键
System.out.println ("The [ " + k + " ] Key is not exist!!");
return "";
}//End if(!ini.containsKey (k))
return ini.get (k).toString ();
}
/**=======================================================================**
* [## public static void setIniKey (String k, String v) {} ]:
* 参数 :String k对象表示键,String v对象表示键值
* 返回值:无
* 修饰符:public static 可以不实例化对象而直接调用方法
* 功能 :设置k键的键值为v对象
**=======================================================================**
*/
public static void setIniKey (String k, String v) {
if(!ini.containsKey (k)) { //是否有 k 这个键
System.out.println ("The [ " + k + " ] Key is not exist!!");
return;
}//End if(!ini.containsKey (k))
ini.put (k, v);
}
/**=======================================================================**
* [## public static void saveIni (String k[]) {} ]:
* 参数 :String k[]字符串数组表示要保存的所有键
* 返回值:无
* 修饰符:public static 可以不实例化对象而直接调用方法
* 功能 :将k字符数组中所有键所对应的键值保存到INI文件中
**=======================================================================**
*/
public static void saveIni (String k[]) {
try {
FileWriter fw = new FileWriter ("config.ini");
BufferedWriter bw = new BufferedWriter ( fw );
//循环变量i是k字符串数组的下标
for (int i = 0; i < k.length; i++) {
bw.write (k[i] + "=" + getIniKey (k[i]));
bw.newLine ();
}//End for
bw.close ();
fw.close ();
}catch (Exception ex) {
System.out.println ("Save CONFIG.INI is false.");
}//End try
}
}
Suntools.java
/**
*##############################################################################
*
* [ 项目名 ] :
* [ 公司名 ] : SunshineSOFT
* [ 模块名 ] : 工具函数
* [ 文件名 ] : suntools.java
* [ 相关文件 ] :
* [ 文件实现功能] : 测试数据是否合法及流水号自动分配
* [ 作者 ] : 顾俊
* [ 版本 ] : 1.2
* ----------------------------------------------------------------------------
* [ 备注 ] :
* ----------------------------------------------------------------------------
* [ 修改记录 ] :
*
* [ 日 期 ] [版本] [修改人] [修改内容]
* 2006/04/07 1.0 顾俊 建立isDate()函数
* 2006/04/08 1.1 顾俊 添加函数 #A, #B, #C, #D
* 2006/04/08 1.2 顾俊 添加函数 #E, #F, #G
* ##--------------------------------------------------------------------------
* 版权所有(c) 20##-2007, SunshineSOFT Corporation
* --------------------------------------------------------------------------##
*
* [ 函数说明 ] :
*
* [## private suntools () {} ] :
* 功能: 防止实例化suntools对象
*
* [## public static boolean isDate (String date) {} ]:
* 功能: 判断日期字符串是否合法函数
*
* [## public static boolean isNum (String in) {} ]: #A
* 功能: 测试字符串是否由数字(0-9)组成
*
* [## public static boolean isNum (String in, int length, double min, double max) {} ]: #B
* 功能: 测试字符串表示的数值及范围,且字符串只能是数字组成
*
* [## public static String getNumber (int type) {} ]: #C
* 功能: 自动分配单据编号, 自动递增
*
* [## public static void savNumber (String num, int type) {} ]: #D
* 功能: 将已用编号保存到INI文件
*
* [## public static double getConsumeFactor(String sDate, String eDate) {} ]: #E
* 功能: 计算酒店计费天数 按INI文件中设置的
*
* [## public static double getClockFactor(String sDate, String eDate) {} ]: #F
* 功能: 计算酒店钟点房计费系数 按INI文件中设置的
*
* [## public static String getConsumeHour(String sDate, String eDate) {} ]: #G
* 功能: 计算两个时间之间有几小时几分
*
*
* [ 遗留问题 ] :
*
*
*##############################################################################
*/
package com.sunshine.sunsdk.system;
import java.util.*;
import java.text.*;
import java.sql.*;
import com.sunshine.sunsdk.sql.*;
public class suntools {
public static final int Number_RZ = 0; //表示销售单号
public static final int Number_YD = 1; //表示进货单号
public static final int Number_JS = 1; //表示进货单号
/**=======================================================================**
* [## private suntools () {} ]: 构造函数
* 参数 :无
* 返回值:无
* 修饰符:private
* 功能 :防止实例化suntools对象
**=======================================================================**
*/
private suntools () {
}
/**=======================================================================**
* [## public static boolean isDate (String date) {} ]:
* 参数 :String对象表示日期的字符串
* 返回值:boolean 合法返回true
* 修饰符:public static 可以不实例化对象而直接调用方法
* 功能 :判断日期字符串是否合法函数
**=======================================================================**
*/
public static boolean isDate (String date) {
SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd hh:mm:ss");
String isdate = date;
if(date.length() == 10) //如果只有日期,函数自动加上00:00:00
isdate = date + " 00:00:00";
try {
sdf.parse (isdate);
return true;
}
catch (Exception ex) {
System.out.println ("feetools.isDate(): The DATE format is error .");
return false;
}
}
/**=======================================================================**
* [## public static boolean isNum (String in) {} ]:
* 参数 :String对象表示被测字符串
* 返回值:boolean 合法返回true
* 修饰符:public static 可以不实例化对象而直接调用方法
* 功能 :测试字符串是否由数字(0-9)组成
**=======================================================================**
*/
public static boolean isNum (String in) {
return isNum (in, 0, 0, 0);
}
/**=======================================================================**
* [## public static boolean isNum (String in, int length, double min, double max) {} ]:
* 参数 :String对象表示被测字符串
* length变量表示字符串最大长度,取值0,表示没有长度限定
* min,max变量限定了String对象表示的数值范围,当(length > 0)时
* 返回值:boolean 合法返回true
* 修饰符:public static 可以不实例化对象而直接调用方法
* 功能 :测试字符串表示的数值及范围,且字符串只能是数字组成
**=======================================================================**
*/
public static boolean isNum (String in, int length, double min, double max) {
String num = in;
int point = 0; //'.'的个数
int len = num.length ();
if(length > 0) {
if(len > length || len == 0) { //判断字符串长度,不合法空返回false
System.out.println ("suntools.isNum(): Length error.");
return false;
}//Endif
}//End if(length > 0)
else
if(len == 0) { //判断字符串是否为空,空返回false
System.out.println ("suntools.isNum(): String is NULL");
return false;
}//End if(len == 0)
for (int i = len - 1; i >=0; i--) { //判断字符串只能是数字
char ac = num.charAt (i);
if(ac == '.' && point == 0 && i!= 0) { //如果是'.'字符,且是第一次出现,且不是只有一个点
if(i > len - 4) { //判断小数位只能是两位
point++;
continue;
}//Endif
}//Endif
if(ac < '0' || ac > '9' ) {
System.out.println ("suntools.isNum(): Character isn't ( '0' - '9' )");
return false;
}//Endif
}//Endfor
if(length !=0) {
double s = Double.parseDouble (num); //现在len为字符串表示的数值
if(s < min || s >max) { //限制范围min-max之间
System.out.println ("suntools.isNum(): Amount limit error. ");
return false;
}//Endif
}//End if(length != 0)
return true;
}
/**=======================================================================**
* [## public static String getNumber (int type) {} ]:
* 参数 :int变量表示要获得什么类型的单号(见类头常量)
* 返回值:String对象: 单号;
* 修饰符:public static 可以不实例化对象而直接调用方法
* 功能 :自动分配单据编号, 自动递增
**=======================================================================**
*/
public static String getNumber (int type) {
GregorianCalendar gc = new GregorianCalendar();
String tp, number, month, day; //单号标头, 单号记数位, 为月份, 为天
int numLen = 0; //单号的默认位数
if(type == Number_RZ) { //要获取销售单号
tp = sunini.getIniKey ("LodgName");
number = sunini.getIniKey ("LodgNumber");
}else if(type == Number_YD){ //要获取进货单号
tp = sunini.getIniKey ("EngaName");
number = sunini.getIniKey ("EngaNumber");
}else {
tp = sunini.getIniKey ("ChouName");
number = sunini.getIniKey ("ChouNumber");
}
numLen = number.length (); //得到单号的默认位数
number = Integer.parseInt (number) + 1 + ""; //将单号增1,再转成字符串
//判断记数号是否超位(超出要求长度)
if(number.equals ((int)Math.pow (10, numLen - 1) + "") && number.length() > 1)
number = number.substring(1); //单号记数位清零
//for循环,用'0'为number补位 (i = 当前号码位数, i < numLen)
for (int i = number.length (); i < numLen; i++) {
number = "0" + number;
}//Endfor
//为月份补'0'
month = gc.get (GregorianCalendar.MONTH) + 1 + "";
if( month.length() == 1)
month = "0" + month;
//为天补'0'
day = gc.get (GregorianCalendar.DAY_OF_MONTH) + "";
if( day.length () == 1)
day = "0" + day;
//连接单号标头,日期,记数位;组成单据号码
tp = tp + gc.get (GregorianCalendar.YEAR) + month + day + number;
return tp; //返回单号
}
/**=======================================================================**
* [## public static void savNumber (String num, int type) {} ]:
* 参数 :String对象表示要保存的单号
* int变量表示要保存什么类型的单号(见类头常量)
* 返回值:无
* 修饰符:public static 可以不实例化对象而直接调用方法
* 功能 :将已用编号保存到INI文件
**=======================================================================**
*/
public static void savNumber (String num, int type) {
//INI文件中的键名
String ini[] = { "[SOFTINFO]", "UserName", "CompName", "[CONFIG]", "Soft_First",
"Default_Link" , "Default_Page", "Sys_style", "[NUMBER]",
"LodgName", "LodgNumber", "EngaName", "EngaNumber", "ChouName",
"ChouNumber", "[HABITUS]", "Ck_Habitus", "Ck_Minute", "[PARTTIME]",
"In_Room", "Out_Room1", "Out_Room2", "InsuDay", "ClockRoom1",
"ClockRoom2", "InsuHour1", "InsuHour2", "[JDBC]", "DBFname",
"UserID", "Password", "IP", "Access", "[ODBC]", "LinkName" };
String bt;
if(type == Number_RZ) {
bt = sunini.getIniKey ("LodgName");
sunini.setIniKey ("LodgNumber", num.substring (bt.length () + 8));
}
else if(type == Number_YD){
bt = sunini.getIniKey ("EngaName");
sunini.setIniKey ("EngaNumber", num.substring (bt.length () + 8));
} else{
bt = sunini.getIniKey ("ChouName");
sunini.setIniKey ("ChouNumber", num.substring (bt.length () + 8));
}
//保存到INI文件
sunini.saveIni (ini);
}
/**=======================================================================**
* [## public static double getConsumeFactor(String sDate, String eDate) {} ]:
* 参数 :String sDate对象表示开始时间
* String eDate变量表示结束时间
* 返回值:double
* 修饰符:public static 可以不实例化对象而直接调用方法
* 功能 :计算酒店计费天数 按INI文件中设置的
**=======================================================================**
*/
//获得消费系数
public static double getConsumeFactor(String sDate, String eDate) {
//获得开始日期时间的--年--月--日--时--分--秒
String syh [] = sDate.trim ().split(" ");
String symd[] = syh[0].trim().split("-");
String shms[] = syh[1].trim().split(":");
int sy = Integer.parseInt(symd[0]);
int sM = Integer.parseInt(symd[1]);
int sd = Integer.parseInt(symd[2]);
int sh = Integer.parseInt(shms[0]);
int sm = Integer.parseInt(shms[1]);
int ss = Integer.parseInt(shms[2]);
//获得结束日期时间的--年--月--日--时--分--秒
String eyh [] = eDate.trim ().split(" ");
String eymd[] = eyh[0].trim().split("-");
String ehms[] = eyh[1].trim().split(":");
int ey = Integer.parseInt(eymd[0]);
int eM = Integer.parseInt(eymd[1]);
int ed = Integer.parseInt(eymd[2]);
int eh = Integer.parseInt(ehms[0]);
int em = Integer.parseInt(ehms[1]);
int es = Integer.parseInt(ehms[2]);
//获得sDate的long值
long sdt = new Timestamp(sy, sM, sd, sh, sm, ss, 0).getTime();
//获得eDate的long值
long edt = new Timestamp(ey, eM, ed, eh, em, es, 0).getTime();
double db = 0;
if(sdt > edt) { //不合法 开始日期一定要小于结束日期
db = -1;
return db;
}//Endif
if(sdt == edt) { //无时间差
db = 0;
return db;
}//Endif
int insuDay = (int)(edt - sdt)/3600000;
if(insuDay < 24) { //入住不到一天
if(Integer.parseInt(sunini.getIniKey("InsuDay")) == 1)
db = 1; //按全天计费
else {
if(insuDay > 1 && insuDay < 12)
db = 0.5; //如果不按全天计费,则大于1小时按半天计费
else
db = 1; //如果不按全天计费,则大于12小时按全天计费
}//Endif
return db;
}//Endif
//几点之后按新的一天计费
int inRoom = Integer.parseInt(sunini.getIniKey("In_Room"));
if(sh < inRoom) {
db = 0.5;
}//Endif
sh = inRoom; //多的时间已经加了系数,去掉多余的
//几点之后按半天计费
int outRoom1 = Integer.parseInt(sunini.getIniKey("Out_Room1"));
int outRoom2 = Integer.parseInt(sunini.getIniKey("Out_Room2"));
if(eh > outRoom1 && eh < outRoom2) {
db = db + 0.5;
eh = outRoom1; //多的时间已经加了系数,去掉多余的
}else if(eh >= outRoom2) {
db = db + 1;
eh = outRoom2;
}//Endif
//计算入住时间
sdt = new Timestamp(sy, sM, sd, sh, sm, ss, 0).getTime();
edt = new Timestamp(ey, eM, ed, eh, em, es, 0).getTime();
db = db + (edt - sdt)/86400000;
return db;
}
/**=======================================================================**
* [## public static double getClockFactor(String sDate, String eDate) {} ]:
* 参数 :String sDate对象表示开始时间
* String eDate变量表示结束时间
* 返回值:double
* 修饰符:public static 可以不实例化对象而直接调用方法
* 功能 :计算酒店钟点房计费系数 按INI文件中设置的
**=======================================================================**
*/
public static double getClockFactor(String sDate, String eDate) {
//获得开始日期时间的--年--月--日--时--分--秒
String syh [] = sDate.trim ().split(" ");
String symd[] = syh[0].trim().split("-");
String shms[] = syh[1].trim().split(":");
int sy = Integer.parseInt(symd[0]);
int sM = Integer.parseInt(symd[1]);
int sd = Integer.parseInt(symd[2]);
int sh = Integer.parseInt(shms[0]);
int sm = Integer.parseInt(shms[1]);
int ss = Integer.parseInt(shms[2]);
//获得结束日期时间的--年--月--日--时--分--秒
String eyh [] = eDate.trim ().split(" ");
String eymd[] = eyh[0].trim().split("-");
String ehms[] = eyh[1].trim().split(":");
int ey = Integer.parseInt(eymd[0]);
int eM = Integer.parseInt(eymd[1]);
int ed = Integer.parseInt(eymd[2]);
int eh = Integer.parseInt(ehms[0]);
int em = Integer.parseInt(ehms[1]);
int es = Integer.parseInt(ehms[2]);
//获得sDate的long值
long sdt = new Timestamp(sy, sM, sd, sh, sm, ss, 0).getTime();
//获得eDate的long值
long edt = new Timestamp(ey, eM, ed, eh, em, es, 0).getTime();
//获得时间差
double db = 0;
if(sdt > edt) { //不合法 开始日期一定要小于结束日期
db = -1;
return db;
}//Endif
//获得两个时间之间有多少秒
edt = (edt - sdt) / 1000;
//--------------------------------------------------------------------//
if(edt <= 60 * Integer.parseInt(sunini.getIniKey("ClockRoom1"))) {
db = 0; //开房后几分钟开始计费,读INI文件设置
return db;
}//Endif
//--------------------------------------------------------------------//
if(edt / 60 < 60 * Integer.parseInt(sunini.getIniKey("ClockRoom2"))) {
db = 1; //不足几小时按一个单位计费
return db;
}//Endif
//--------------------------------------------------------------------//
//除以上可能的正常计费公式如下
db = edt / 3600; //获得过去的小时数
edt = edt % 3600 / 60; //获得多余的分钟数
if(edt > Integer.parseInt(sunini.getIniKey("InsuHour2")) && edt <= Integer.parseInt(sunini.getIniKey("InsuHour1"))) {
db = db + 0.5; //超过多少分,但小于多少分部分,收半价
}else if(edt > Integer.parseInt(sunini.getIniKey("InsuHour2"))) {
db = db + 1; //超过多少分的,收全价
}//Endif
//--------------------------------------------------------------------//
return db;
}
/**=======================================================================**
* [## public static String getConsumeHour(String sDate, String eDate) {} ]:
* 参数 :String sDate对象表示开始时间
* String eDate变量表示结束时间
* 返回值:String
* 修饰符:public static 可以不实例化对象而直接调用方法
* 功能 :计算两个时间之间有几小时几分
**=======================================================================**
*/
public static String getConsumeHour(String sDate, String eDate) {
//获得开始日期时间的--年--月--日--时--分--秒
String syh [] = sDate.trim ().split(" ");
String symd[] = syh[0].trim().split("-");
String shms[] = syh[1].trim().split(":");
int sy = Integer.parseInt(symd[0]);
int sM = Integer.parseInt(symd[1]);
int sd = Integer.parseInt(symd[2]);
int sh = Integer.parseInt(shms[0]);
int sm = Integer.parseInt(shms[1]);
int ss = Integer.parseInt(shms[2]);
//获得结束日期时间的--年--月--日--时--分--秒
String eyh [] = eDate.trim ().split(" ");
String eymd[] = eyh[0].trim().split("-");
String ehms[] = eyh[1].trim().split(":");
int ey = Integer.parseInt(eymd[0]);
int eM = Integer.parseInt(eymd[1]);
int ed = Integer.parseInt(eymd[2]);
int eh = Integer.parseInt(ehms[0]);
int em = Integer.parseInt(ehms[1]);
int es = Integer.parseInt(ehms[2]);
//获得sDate的long值
long sdt = new Timestamp(sy, sM, sd, sh, sm, ss, 0).getTime();
//获得eDate的long值
long edt = new Timestamp(ey, eM, ed, eh, em, es, 0).getTime();
//获得时间差
sdt = edt - sdt;
//生成过去多少时间的字符串
String t = sdt / 3600000 + "小时" + sdt % 3600000 / 60000 + "分";
return t;
}
}
ToCap.java
/*
* @(#)ToCap.java 1.24 03/12/19
*
* Copyright 20## CazoSoft, Inc. All rights reserved.
*/
package sunsdk.system;
/**
* <code> ToCap </code>
* <p>
* 本类用于转化中文大写人民币
*
* @author 鲜强
* @version 22.14, 04/05/06
* @since CAZOSOFT 1.0
*/
public class ToCap {
/**
* 用户设置大写钱数(100,000,000 (一亿)以内).
*
* @param money :
* String 接收用户的正实数.
* @return : String 包括圆整或角分的中文大写人民币,如果不合法,将返回空(null)
*/
public String setMoney(String money) {
String re = null;
double num;
//测试数据是否合法
try {
num = Double.parseDouble(money.trim());
if (num < 100000000 && num >= 0) {
//合法, 使用字符串开始转换
re = this.mySetMoney(money);
}//end if
} catch (Exception ex) {
}//end try
//返回值
return re;
}
/**
* 大写转换函数. 功能: 转换数字为中文大写
*
* @param num :
* int 接受整数
* @return : String 大写数字零到玖.
*/
private String setDaXie(int num) {
String re = null;
switch (num) {
case 0:
re = "零";
break;
case 1:
re = "壹";
break;
case 2:
re = "贰";
break;
case 3:
re = "叁";
break;
case 4:
re = "肆";
break;
case 5:
re = "伍";
break;
case 6:
re = "陆";
break;
case 7:
re = "柒";
break;
case 8:
re = "捌";
break;
case 9:
re = "玖";
break;
default:
break;
}
return re;
}
/**
* 处理大写人民币
*
* @param num :
* String 接收处理过的字符串(实为数字).
* @return : 返回处理过的大写人民币.
*/
private String mySetMoney(String num) throws Exception {
//要返回的字符串
String re = "";
//转换过程
String setNum = null;
int index = num.indexOf(".");
//处理整数
if (index == -1) {
setNum = num;
} else {
setNum = num.substring(0, index);
}
int weiShu = setNum.length();
if (weiShu > 0) {
int leng = setNum.length();
int numYuan = Integer.parseInt("" + setNum.charAt(weiShu - 1));
String zhuanYuan = setDaXie(numYuan);
re = zhuanYuan;
//个位
if (weiShu > 1) {
int numShi = Integer.parseInt("" + setNum.charAt(weiShu - 2));
String zhuanShi = setDaXie(numShi);
//十位
re = zhuanShi + "拾" + re;
if (weiShu > 2) {
int numBai = Integer.parseInt(""
+ setNum.charAt(weiShu - 3));
String zhuanBai = setDaXie(numBai);
//百位
re = zhuanBai + "佰" + re;
if (weiShu > 3) {
int numQian = Integer.parseInt(""
+ setNum.charAt(weiShu - 4));
String zhuanQian = setDaXie(numQian);
//千位
re = zhuanQian + "仟" + re;
if (weiShu > 4) {
int numWan = Integer.parseInt(""
+ setNum.charAt(weiShu - 5));
String zhuanWan = setDaXie(numWan);
//万位
re = zhuanWan + "万" + re;
if (weiShu > 5) {
int numShiWan = Integer.parseInt(""
+ setNum.charAt(weiShu - 6));
String zhuanShiWan = setDaXie(numShiWan);
//十万位
re = zhuanShiWan + "拾" + re;
if (weiShu > 6) {
int numBaiWan = Integer.parseInt(""
+ setNum.charAt(weiShu - 7));
String zhuanBaiWan = setDaXie(numBaiWan);
//百万位
re = zhuanBaiWan + "佰" + re;
if (weiShu > 7) {
int numQianWan = Integer.parseInt(""
+ setNum.charAt(weiShu - 8));
String zhuanQianWan = setDaXie(numQianWan);
//千万位
re = zhuanQianWan + "仟" + re;
}//end qianwan
}//end baiwan
}//end shiwan
}//end wan
}//end qian
}//end bai
}//end shi
}//end yuan
//处理小数
if (index != -1) {
String xiaoShu = num.substring(index + 1, num.length());
int leng = xiaoShu.length();
int numJiao = Integer.parseInt("" + xiaoShu.charAt(0));
String zhuanJiao = setDaXie(numJiao);
int numFen;
if (leng == 1) {
numFen = 0;
}//end if
numFen = Integer.parseInt("" + xiaoShu.charAt(1));
String zhuanFen = setDaXie(numFen);
//十分位+百分位
if (numJiao == 0 && numFen != 0 || numJiao != 0 && numFen != 0) {
re = re + "圆" + zhuanJiao + "角" + zhuanFen + "分";
} else {
re = re + "圆整";
}//end if
} else {
re = re + "圆整";
}//end index
return re;
}
}
2)swing包
CsUIManager.java
/*
* @(#)CsUIManager.java 20##-4-13
*
* public class
*
* Copyright 20## CazoSoft, Inc. All rights reserved.
*/
package sunsdk.swing;
import java.awt.*;
import javax.swing.*;
import javax.swing.plaf.metal.*;
/**
* <code> CsUIManager </code>
* <p>
* 说明:本类为外观管理器
* <p>
* <strong>警告:</strong>
* 使用金属(BOLD)外观时,输入中文会有异常,但不影响系统运行
* <p>
* 相关库文件:o.jar
*
* @author 鲜强
* @version 20##-4-13 23:05:39
* @since CAZOSOFT 1.0
*/
public class CsUIManager {
//Windows 外观
public static final int WINDOWS = 0;
//Java 默认外观
public static final int METAL = 1;
//Linux 外观
public static final int MOTIF = 2;
//WindowsClassic 外观
public static final int WINDOWSCLASSIC = 3;
//Alloy 外观
public static final int ALLOY = 4;
//Alloy 玻璃外观
public static final int GLASSTHEMEALLOY = 5;
//Alloy 迷幻外观
public static final int ACIDTHEMEALLOY = 6;
//Alloy 贝多因外观
public static final int BEDOUIDTHEMEALLOY = 7;
//Alloy 默认外观
public static final int DEAFULTTHEMEALLOY = 8;
//Bold 外观
public static final int BOLD = 9;
/**
* 界面风格选择器
*
* @param cp
* 接受要改变的控件
* @param style
* 接受界面下标
* @return 返回成功设置与否
*/
public static boolean setUI(Component cp, int style) {
try {
switch (style) {
case 0:
UIManager.setLookAndFeel("com.sun.java.swing.plaf."
+ "windows.WindowsLookAndFeel");
break;
case 1:
UIManager.setLookAndFeel("javax.swing.plaf."
+ "metal.MetalLookAndFeel");
break;
case 2:
UIManager.setLookAndFeel("com.sun.java.swing.plaf."
+ "motif.MotifLookAndFeel");
break;
case 3:
UIManager.setLookAndFeel("com.sun.java.swing.plaf."
+
"windows.WindowsClassicLookAndFeel");
break;
case 4:
UIManager.setLookAndFeel("com.incors.plaf."
+ "alloy.AlloyLookAndFeel");
break;
case 5:
UIManager.setLookAndFeel("soft.wes.feels."
+ "GlassThemeAlloyLookAndFeel");
break;
case 6:
UIManager.setLookAndFeel("soft.wes.feels."
+ "AcidThemeAlloyLookAndFeel");
break;
case 7:
UIManager.setLookAndFeel("soft.wes.feels."
+ "BedouinThemeAlloyLookAndFeel");
break;
case 8:
UIManager.setLookAndFeel("soft.wes.feels."
+ "DefaultThemeAlloyLookAndFeel");
break;
case 9:
UIManager.put("swing.boldMetal", Boolean.FALSE);
//可设置对话框外观
JDialog.setDefaultLookAndFeelDecorated(true);
//可设置设置窗口外观
JFrame.setDefaultLookAndFeelDecorated(true);
Toolkit.getDefaultToolkit().setDynamicLayout(true);
System.setProperty("sun.awt.noerasebackground",
"true");
UIManager.setLookAndFeel(new MetalLookAndFeel());
break;
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "更换风格失败,以原风格显
示");
return false;
}
SwingUtilities.updateComponentTreeUI(cp);
cp.repaint();
return true;
}
}
FStartWindow.java
/**
*##############################################################################
*
* [ 模块名 ] : 系统启动界面
* [ 文件名 ] : FStartWindow.java
* [ 文件实现功能 ] : 完成初始化系统运行环境
* [ 版本 ] : 1.0
* ----------------------------------------------------------------------------
* [ 备注 ] : 用于初始化运行环境,连接数据库
* ----------------------------------------------------------------------------
* [ 修改记录 ] :
*
* [ 日 期 ] [修改人] [修改内容]
* 2006/03/22 顾俊 创建
*
* ##--------------------------------------------------------------------------
* 版权所有(c) 20##-2007, SunshineSOFT Corporation
* --------------------------------------------------------------------------##
*
* [ 函数说明 ] :
*
* [## public FStartWindow(String picName, Frame f, int waitTime) {} ] :
* 参数 : String 对象,表示界面背景图片;
* Frame 对象,表示父窗口;
* int 变量,表示启动界面等待的时间
* 返回值 : 无
* 修饰符 : public
* 功能 : 本类的构造函数
*
*##############################################################################
*/
package com.sunshine.sunsdk.swing;
import javax.swing.*;
import java.awt.*;
public class FStartWindow extends JWindow {
ImageIcon image;
JLabel pic;
//构造函数
public FStartWindow(String picName, Frame f, int waitTime) {
super(f);
ImageIcon image = new ImageIcon(picName);
JLabel pic = new JLabel(image);
this.getContentPane().add(pic, BorderLayout.CENTER);
//调整图片大小到屏幕中央
this.pack();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension labelSize = pic.getPreferredSize();
setLocation(screenSize.width/2 - (labelSize.width/2),
screenSize.height/2 - (labelSize.height/2));
final int PAUSE = waitTime;
final Runnable closerRunner = new Runnable() {
public void run() {
setVisible(false);
dispose();
//System.exit(0);
}
}; //End closerRunner
Runnable waitRunner = new Runnable() {
public void run() {
try {
Thread.sleep(PAUSE);
SwingUtilities.invokeAndWait(closerRunner);
}
catch(Exception e) {
e.printStackTrace();
// 能够捕获InvocationTargetException
// 能够捕获InterruptedException
}
}
}; //End waitRunner
setVisible(true);
Thread waitThread = new Thread(waitRunner, "SplashThread");
waitThread.start();
}
}
JQFrame.java
/**
*##############################################################################
*
* [ 项目名 ] :
* [ 公司名 ] : SunshineSOFT
* [ 模块名 ] : 防QQ的自缩窗口
* [ 文件名 ] : JQFrame.java
* [ 相关文件 ] :
* [ 文件实现功能] : 窗口靠近屏幕上方时,自动缩起
* [ 作者 ] : 顾俊
* [ 版本 ] : 1.0
* ----------------------------------------------------------------------------
* [ 备注 ] :
* ----------------------------------------------------------------------------
* [ 修改记录 ] :
*
* [ 日 期 ] [版本] [修改人] [修改内容]
* 2006/04/29 1.0 顾俊 创建
* ##--------------------------------------------------------------------------
* 版权所有(c) 20##-2007, SunshineSOFT Corporation
* --------------------------------------------------------------------------##
*
* [ 函数说明 ] :
*
* [## public Login() {} ]:
* 功能: JQFrame 的构造函数
*
* [## public void setSize(int w, int h) {} ]:
* 功能: 设置窗口尺寸
*
* [## public void setStep(int s) {} ]:
* 功能: 设置的窗口动作步长
*
*
* [ 遗留问题 ] :
*
*##############################################################################
*/
package com.sunshine.sunsdk.swing;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import com.sunshine.sunsdk.swing.*; //公共类包
import com.sunshine.sunsdk.system.*;
public class JQFrame
extends JFrame
implements MouseListener {
private boolean winState = true; //窗口伸缩标志
private int sunWidth = 200; //窗口默认宽度
private int minHieght = 5; //窗口缩起后的高度
private int maxHieght = 506; //窗口展开后的高度
private int step = 15; //窗口动作步长
/**=======================================================================**
* [## public JQFrame() {} ]:
* 参数 :无
* 返回值:无
* 修饰符:public
* 功能 :JQFrame 的构造函数
**=======================================================================**
*/
public JQFrame() {
super("JQFrame");
//对窗口加鼠标监听
this.addMouseListener(this);
//设置窗口左上角图标
ImageIcon ia = new ImageIcon("pic/ico.gif");
this.setIconImage(ia.getImage());
//设置窗口默认大小
this.setBounds(55, 55, sunWidth, maxHieght);
//设置窗口不可改变大小
this.setResizable(false);
}
/**=======================================================================**
* [## public void setSize(int w, int h) {} ]:
* 参数 :int w 表示窗口宽度 int h 表示窗口高度
* 返回值:无
* 修饰符:public
* 功能 :设置窗口尺寸
**=======================================================================**
*/
public void setSize(int w, int h) {
sunWidth = w;
maxHieght = h;
super.setSize(w, h);
}
/**=======================================================================**
* [## public void setStep(int s) {} ]:
* 参数 :int s 表示要设置的窗口动作步长
* 返回值:无
* 修饰符:public
* 功能 :设置窗口的动作步长
**=======================================================================**
*/
public void setStep(int s) {
if(s > 4) {
step = s; //设置窗口动作步长
}//Endif
}
/**=======================================================================**
* MouseListener 监听
**=======================================================================**
*/
public void mouseClicked(MouseEvent me) {
}
public void mousePressed(MouseEvent me) {
}
public void mouseReleased(MouseEvent me) {
if(this.getY() < 0) {
//如果窗口的Y坐标小于0,则将其置0,缩起窗口
this.setLocation(this.getX(), 0);
for (int i = this.getHeight(); i > minHieght; i-=step) {
if(i - minHieght <= step) {
i = minHieght;
}//Endif
super.setSize(this.getWidth(), i);
}//Endfor
winState = false;
}//Endif
}
public void mouseEntered(MouseEvent me) {
if(me.getSource() == this) { //如果鼠标进入窗口
if(this.getY() == 0 && !winState) { //如果窗口在屏幕北边且已缩起
//展开窗口
for (int i = minHieght; i < maxHieght; i+=step) {
if(i + step >= maxHieght) {
i = maxHieght;
}//Endif
super.setSize(this.getWidth(), i);
}//Endfor
winState = true;
}//Endif
}//Endif
}
public void mouseExited(MouseEvent me) {
if(me.getSource() == this) { //如果鼠标移出窗口
int mx = me.getX();
int my = me.getY();
//如果是在窗口内部控件上则返回
if(mx > 0 && mx < sunWidth && my < maxHieght) {
return;
}//Endif
if(this.getY() == 0 && winState) { //如果窗口在屏幕北边且已展开
//缩起窗口
for (int i = maxHieght; i >= minHieght; i-=step) {
if(i - minHieght <= step) {
i = minHieght;
}//Endif
super.setSize(this.getWidth(), i);
}//Endfor
winState = false;
}//Endif
}//Endif
}
}
SlitherMenu.java
/**
*##############################################################################
*
* [ 项目名 ] :
* [ 公司名 ] : SunshineSOFT
* [ 模块名 ] : 滑动菜单
* [ 文件名 ] : SlitherMenu.java
* [ 相关文件 ] :
* [ 文件实现功能] : 防QQ一样的滑动菜单
* [ 作者 ] : 顾俊
* [ 版本 ] : 1.0
* ----------------------------------------------------------------------------
* [ 备注 ] :
* ----------------------------------------------------------------------------
* [ 修改记录 ] :
*
* [ 日 期 ] [版本] [修改人] [修改内容]
* 2006/04/18 1.0 顾俊 创建
* ##--------------------------------------------------------------------------
* 版权所有(c) 20##-2007, SunshineSOFT Corporation
* --------------------------------------------------------------------------##
*
* [ 函数说明 ] :
*
* [## public SlitherMenu() {} ]:
* 功能: 滑动菜单的构造函数 (无部局面板)
*
* [## public void addPanel(String name,String ico, int index, int quantity) {} ]:
* 功能: 制作按键模板,并加入主模板
*
* [## public void addButton(String ico, String name, String tooltip, int index) {} ]:
* 功能: 制作功能按键,并加入相应的模板中
*
* [## public void initButtonPanelDimension() {} ]:
* 功能: 初始化每个按键模板的最大尺寸(在主窗口的setVisible()方法之前使用)
*
* [## public void setInitMenu() {} ]:
* 功能: 设置初始化后展开第一项菜单(在主窗口的setVisible()方法之后使用)
*
* [## public void setMenuDimension(int w,int h) {} ]:
* 功能: 设置菜单宽度和高度(在初始化菜单后加入组件之前使用)
*
* [## public void setMenuLocation(int x, int y) {} ]:
* 功能: 设置菜单的坐标(在初始化菜单后加入组件之前使用)
*
* [## public void setTitleHeight(int h) {} ]:
* 功能: 设置模板标题按键高度(当标题按键有背景图标时才使用本方法)
*
* [## public void setButtonPanelBackground(Color bg) {} ]:
* 功能: 设置按键模板背景颜色(在初始化菜单后加入组件之后使用)
*
* [## public String getSelectButtonName() {} ]:
* 功能: 获得选中的按键名
*
* [## private void slither(int index) {} ]:
* 功能: 处理菜单滑动效果
*
* [ 遗留问题 ] : 1、在改变窗口大小时,不能重画菜单
* 2、不能给各按键模板设置背景图案
* 3、不能改变按键的前景颜色
*
*##############################################################################
*/
package sunsdk.swing;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class SlitherMenu
extends JPanel
implements ActionListener {
//按键模板数组
private ArrayList template = new ArrayList();
//放置按键面板的数组
private ArrayList buttonPanels = new ArrayList();
//触发ActionListener事件的按键名
private String selectButtonName = "";
//当前展开模板的序号
private int selectPanelNumber = 0;
//将要展开模板的序号
private int selectPanelNumberNew = 0;
//模板总数
private int panelconut = 0;
//定义滑动菜单的坐标
private int sm_X = 0;
private int sm_Y = 0;
//定义滑动菜单的宽度和高度
private int slitherMenuBar_Width = 60;
private int slitherMenuBar_Height = 300;
//按键组模板缩起后的高度
private int titleHeight = 28;
/**=======================================================================**
* [## public SlitherMenu() {} ]: 构造函数
* 参数 :无
* 返回值:无
* 修饰符:public
* 功能 :滑动菜单的构造函数 (无部局面板)
**=======================================================================**
*/
public SlitherMenu() {
super(null); //设置主面板为无部局
}
/**=======================================================================**
* [## public void addPanel(String name,String ico, int index, int quantity) {} ]:
* 参数 :String name 表示按键模板的标题按键名
* String ico 表示标题栏的背景图标
* int index 表示按键模板的索引序号
* int quantity表示模板内将要放入按键的数量
* 返回值:无
* 修饰符:public
* 功能 :制作按键模板,并加入主模板
**=======================================================================**
*/
public void addPanel(String name,String ico, int index, int quantity) {
JButton titleButton;
JScrollPane spPanel;
JPanel panelMain, buttonPanel;
titleButton = new JButton(name, new ImageIcon(ico)); //制作标题按键
panelMain = new JPanel(new BorderLayout(0, 0)); //框架面板为边界部局
buttonPanel = new JPanel(new GridLayout(quantity, 1)); //按键组面板为表格部局
spPanel = new JScrollPane(buttonPanel); //制作滚动面板
spPanel.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
//设置标题按键属性, 如果图标为空,则默认Java原有属性
if(ico.length() > 0) {
titleButton.setFocusPainted(false); //设置焦点外框为假
titleButton.setBorderPainted(false); //设置按键无边框
titleButton.setContentAreaFilled(false); //设置按键背景色透明
titleButton.setHorizontalTextPosition(SwingConstants.CENTER); //设置Ico与文字居中
//panelMain.setBorder(new LineBorder(new Color(184, 207, 229)));//加外框线
}//Endif
//对标题按键加事件监听
titleButton.addActionListener(this);
titleButton.setName(index+ ""); //设置框架面板标志
panelMain.add("North", titleButton); //加入标题按键
panelMain.add("Center",spPanel); //加入按键组面板
this.add(panelMain); //放入菜单面板
panelconut++; //面板记数器+1
template.add(index, panelMain); //将按键模板存入数组
buttonPanels.add(index, buttonPanel); //将放置按键的面板存入数组
}
/**=======================================================================**
* [## public void addButton(String ico, String name, String tooltip, int index) {} ]:
* 参数 :String name 表示功能按键的名字
* String ico 表示功能按键的背景图标
* String tooltip 表示按键的气泡提示文本
* int index 表示按键要放入哪个模板
* 返回值:无
* 修饰符:public
* 功能 :制作功能按键,并加入相应的模板中
**=======================================================================**
*/
public void addButton(String ico, String name, String tooltip, int index) {
JButton button = new JButton(name, new ImageIcon(ico));
button.setToolTipText(tooltip); //设置按键提示
button.setBorderPainted(false); //设置按键无边框
button.setContentAreaFilled(false); //设置按键背景色透明
button.setHorizontalTextPosition(SwingConstants.CENTER);//设置Ico与文字居中
button.setVerticalTextPosition(SwingConstants.BOTTOM);//设置Ico相对文字的位置
button.addActionListener(this); //加事件监听
((JPanel)buttonPanels.get(index)).add(button); //将按键加入按键面板
}
/**=======================================================================**
* [## public void initButtonPanelDimension() {} ]:
* 参数 :无
* 返回值:无
* 修饰符:public
* 功能 :初始化每个按键模板的最大尺寸(在主窗口的setVisible()方法之前使用)
**=======================================================================**
*/
public void initButtonPanelDimension() {
for (int i = 0; i < panelconut; i++) {
((JPanel)template.get(i)).setBounds(sm_X, sm_Y, slitherMenuBar_Width,
slitherMenuBar_Height - titleHeight * (panelconut - 1));
}//Endfor
}
/**=======================================================================**
* [## public void setInitMenu() {} ]:
* 参数 :无
* 返回值:无
* 修饰符:public
* 功能 :设置初始化后展开第一项菜单(在主窗口的setVisible()方法之后使用)
**=======================================================================**
*/
public void setInitMenu() {
if(panelconut > 0) {
JPanel mainMenu = (JPanel)template.get(0); //展开第一项菜单
int titlesHeight = (panelconut - 1) * titleHeight; //获得其它模板标题的高度总和
int height = slitherMenuBar_Height - titlesHeight;
mainMenu.setBounds(sm_X, sm_Y, slitherMenuBar_Width, height);
//处理其它菜单标题
for (int i = 1; i < panelconut; i++) {
((JPanel)template.get(i)).setBounds(sm_X, sm_Y + height + (i - 1) * titleHeight,
slitherMenuBar_Width, titleHeight);
}//Endfor
}else {
String msg = "没有按键模板可组织。";
JOptionPane.showMessageDialog(null, msg, "错误",JOptionPane.ERROR_MESSAGE);
}//Endif
}
/**=======================================================================**
* [## public void setMenuDimension(int w,int h) {} ]:
* 参数 :int w 表示菜单宽度,int h 表示菜单高度
* 返回值:无
* 修饰符:public
* 功能 :设置菜单宽度和高度(在初始化菜单后加入组件之前使用)
**=======================================================================**
*/
public void setMenuDimension(int w,int h) {
if(panelconut == 0) {
slitherMenuBar_Width = w;
slitherMenuBar_Height = h;
}else {
String msg = "setMenuDimension()方法请在加入组件之前使用。";
JOptionPane.showMessageDialog(null, msg, "警告",JOptionPane.WARNING_MESSAGE);
}//Endif
}
/**=======================================================================**
* [## public void setMenuLocation(int x, int y) {} ]:
* 参数 :int x 表示菜单的横向坐标,int y 表示菜单的纵向坐标
* 返回值:无
* 修饰符:public
* 功能 :设置菜单的坐标(在初始化菜单后加入组件之前使用)
**=======================================================================**
*/
public void setMenuLocation(int x, int y) {
if(panelconut == 0) {
sm_X = x;
sm_Y = y;
}else {
String msg = "setMenuLocation()方法请在加入组件之前使用。";
JOptionPane.showMessageDialog(null, msg, "警告",JOptionPane.WARNING_MESSAGE);
}//Endif
}
/**=======================================================================**
* [## public void setTitleHeight(int h) {} ]:
* 参数 :int h 表示按键模板的标题键的高度
* 返回值:无
* 修饰符:public
* 功能 :设置模板标题按键高度(当标题按键有背景图标时才使用本方法)
**=======================================================================**
*/
public void setTitleHeight(int h) {
titleHeight = h;
}
/**=======================================================================**
* [## public void setButtonPanelBackground(Color bg) {} ]:
* 参数 :Color 对象表示按键模板的背景颜色
* 返回值:无
* 修饰符:public
* 功能 :设置按键模板背景颜色(在初始化菜单后加入组件之后使用)
**=======================================================================**
*/
public void setButtonPanelBackground(Color bg) {
if(panelconut > 0) {
for (int i = 0; i < panelconut; i++) {
((JPanel)buttonPanels.get(i)).setBackground(bg);
}//Endfor
}else {
String msg = "setButtonPanelBackground()方法请在加入组件之后使用。";
JOptionPane.showMessageDialog(null, msg, "警告",JOptionPane.WARNING_MESSAGE);
}//Endif
}
/**=======================================================================**
* [## public String getSelectButtonName() {} ]:
* 参数 :无
* 返回值:String 对象表示触发事件的功能按键的名字
* 修饰符:public
* 功能 :获得选中的按键名
**=======================================================================**
*/
public String getSelectButtonName() {
return selectButtonName;
}
/**=======================================================================**
* [## private void slither(int index) {} ]:
* 参数 :无
* 返回值:无
* 修饰符:private
* 功能 :处理菜单滑动效果
**=======================================================================**
*/
private void slither(int index) {
//获得其它标题的高度总和
int sp_h = slitherMenuBar_Height - titleHeight * (panelconut - 1);
if(index == selectPanelNumber) { //如果是当前面板,则不处理
return;
}else if(index > selectPanelNumber) { //菜单上移动作
int sp_y = titleHeight * (selectPanelNumber + 1);
for (int i = sp_h; i >= titleHeight; i --) {
//当前展开面板缩起
((JPanel)template.get(selectPanelNumber)).setSize(slitherMenuBar_Width, i);
//处理当前展开面板与将要展开面板之间的标题
for (int j = selectPanelNumber + 1; j < index; j++) {
int other_Y = ((JPanel)template.get(j)).getY() - 1;
((JPanel)template.get(j)).setLocation(sm_X, other_Y);
}//Endfor
//新面板展开
int index_Y = ((JPanel)template.get(index)).getY() - 1;
int index_H = ((JPanel)template.get(index)).getHeight() + 1;
((JPanel)template.get(index)).setBounds(sm_X, index_Y, slitherMenuBar_Width, index_H);
}//Endfor
}else if(index < selectPanelNumber) { //下移动作
int sp_y = titleHeight * (selectPanelNumber - 2);
for (int i = sp_h; i >= titleHeight; i --) {
//当前展开面板缩起
int spy = ((JPanel)template.get(selectPanelNumber)).getY() + 1;
((JPanel)template.get(selectPanelNumber)).setBounds(sm_X, spy, slitherMenuBar_Width, i);
//处理当前展开面板与将要展开面板之间的标题
for (int j = selectPanelNumber - 1; j > index; j--) {
int other_Y = ((JPanel)template.get(j)).getY() + 1;
((JPanel)template.get(j)).setLocation(sm_X, other_Y);
}//Endfor
//新面板展开
int index_H = ((JPanel)template.get(index)).getHeight() + 1;
((JPanel)template.get(index)).setSize(slitherMenuBar_Width, index_H);
}//Endfor
}//Endif
this.validate(); //确定当前菜单的变化
}
/**=======================================================================**
* ActionListener 监听
**=======================================================================**
*/
public void actionPerformed ( ActionEvent ae ) {
//获得触发事件的按键Name
selectButtonName = ((JButton)ae.getSource()).getName();
if(selectButtonName != null) { //不为空则选择的就是标题按键
//获得被选中模板的序号
selectPanelNumberNew = Integer.parseInt(selectButtonName);
//处理菜单滑动效果
slither(selectPanelNumberNew);
selectPanelNumber = selectPanelNumberNew;
}
else {
//获得功能按键的名字
selectButtonName = ((JButton)ae.getSource()).getText();
}//Endif
}
}
sunswing.java
/**
*##############################################################################
*
* [ 项目名 ] :
* [ 公司名 ] : SunshineSOFT
* [ 模块名 ] : 窗口相关的设置
* [ 文件名 ] : sunswing.java
* [ 相关文件 ] : swing.Theme.*
* [ 文件实现功能] : 设置窗口属性
* [ 作者 ] : 顾俊
* [ 版本 ] : 1.0
* ----------------------------------------------------------------------------
* [ 备注 ] :
* ----------------------------------------------------------------------------
* [ 修改记录 ] :
*
* [ 日 期 ] [版本] [修改人] [修改内容]
* 2006/04/01 1.0 顾俊 创建
* 2006/04/19 1.1 顾俊 加入窗口主题
* ##--------------------------------------------------------------------------
* 版权所有(c) 20##-2007, SunshineSOFT Corporation
* --------------------------------------------------------------------------##
*
* [ 函数说明 ] :
*
* [## private sunswing() {} ]:
* 功能: 构造函数
*
* [## public static void setWindowStyle (char style) {} ]:
* 功能: 设置窗口风格
*
* [## public static void setWindowCenter (Component cp) {} ]:
* 功能: 设置窗口在屏幕居中
*
*
* [ 遗留问题 ] :
*
*##############################################################################
*/
package com.sunshine.sunsdk.swing;
import javax.swing.*;
import javax.swing.plaf.metal.MetalLookAndFeel;
import java.awt.*;
import com.sunshine.sunsdk.swing.Theme.*;
public class sunswing {
//窗口外观风格常量
public static final int SYSTEM_STYLE = '0';
public static final int JAVA_STYLE = '1';
public static final int METAL_STYLE = '2';
/**=======================================================================**
* [## private sunswing() {} ]: 构造函数
* 参数 :无
* 返回值:无
* 修饰符:private
* 功能 :防止实例化sunswing对象
**=======================================================================**
*/
private sunswing() {
}
/**=======================================================================**
* [## public static void setWindowStyle (int style) {} ]:
* 参数 :int,表示代表风格种类的常量(见类头常量)
* 返回值:无
* 修饰符:public static 可以不实例化对象而直接调用方法
* 功能 :设置窗口风格
**=======================================================================**
*/
public static void setWindowStyle (char style) {
try {
switch (style) {
case '0':
UIManager.setLookAndFeel ("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
break;
case '1':
UIManager.setLookAndFeel ("javax.swing.plaf.metal.MetalLookAndFeel");
break;
case '2':
UIManager.put ("swing.boldMetal", Boolean.FALSE);
//可设置对话框外观
JDialog.setDefaultLookAndFeelDecorated (true);
//可设置设置窗口外观
JFrame.setDefaultLookAndFeelDecorated (true);
Toolkit.getDefaultToolkit().setDynamicLayout (true);
System.setProperty ( "sun.awt.noerasebackground", "true");
UIManager.setLookAndFeel (new MetalLookAndFeel());
//设置窗口色调主题
MetalLookAndFeel.setCurrentTheme(new DarkGoldMetalTheme());
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
}//End switch (style)
}
catch (Exception ex) {
ex.printStackTrace();
}//End try
}
/**=======================================================================**
* [## public static void setWindowCenter(Component cp) {} ]:
* 参数 :Component对象,表示要居中的窗口
* 返回值:无
* 修饰符:public static 可以不实例化对象而直接调用方法
* 功能 :设置窗口在屏幕居中
**=======================================================================**
*/
public static void setWindowCenter(Component cp) {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
cp.setLocation (screenSize.width / 2 - (cp.getWidth() / 2),
screenSize.height / 2 - (cp.getHeight() / 2));
}
}
TJButton.java
/**
*##############################################################################
*
* [ 项目名 ] :
* [ 公司名 ] : SunshineSOFT
* [ 模块名 ] : 制作带ICO和气泡提示的按键
* [ 文件名 ] : TJButton.java
* [ 相关文件 ] :
* [ 文件实现功能] : 制作带ICO和气泡提示的按键
* [ 作者 ] : 顾俊
* [ 版本 ] : 1.1
* ----------------------------------------------------------------------------
* [ 备注 ] :
* ----------------------------------------------------------------------------
* [ 修改记录 ] :
*
* [ 日 期 ] [版本] [修改人] [修改内容]
* 2006/03/31 1.0 顾俊 创建
* 2006/04/06 1.1 顾俊 增加构造函数
* 2006/04/20 1.1 顾俊 增加监听效果
* ##--------------------------------------------------------------------------
* 版权所有(c) 20##-2007, SunshineSOFT Corporation
* --------------------------------------------------------------------------##
*
* [ 函数说明 ] :
*
* [## public TJButton(String picName, String text, String toolTip) {} ]:
* 功能: 构造函数 制作带ICO和气泡提示的按键
*
* [## public TJButton(String picName, String text, String toolTip,boolean flag) {} ]:
* 功能: 制作带ICO和气泡提示的工具栏按键
*
* [## private buildButton(String picName, String text, String toolTip,boolean flag) {} ]:
* 功能: 制作带ICO和气泡提示的工具栏按键,仅类内使用
*
* [ 遗留问题 ] :
*
*##############################################################################
*/
package com.sunshine.sunsdk.swing;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class TJButton
extends JButton
implements MouseListener {
/**=======================================================================**
* [## public TJButton(String picName, String text, String toolTip) {} ]
* 构造函数
* 参数 :String picName 表示按键上的ICO文件名
* String text 表示按键的名称
* String toolTip 表示按键的ToolTip标示
* 返回值:无
* 修饰符:public
* 功能 :制作带ICO和气泡提示的按键
**=======================================================================**
*/
public TJButton(String picName, String text, String toolTip) {
buildButton(picName, text, toolTip, false);
}
/**=======================================================================**
* [## public TJButton(String picName, String text, String toolTip,boolean flag) {} ]
* 构造函数
* 参数 :String picName 表示按键上的ICO文件名
* String text 表示按键的名称
* String toolTip 表示按键的ToolTip标示
* boolean 表示按键为大图标工具栏模式
* 返回值:无
* 修饰符:public
* 功能 :制作带ICO和气泡提示的工具栏按键
**=======================================================================**
*/
public TJButton(String picName, String text, String toolTip,boolean flag) {
buildButton(picName, text, toolTip, flag);
}
/**=======================================================================**
* [## private buildButton(String picName, String text, String toolTip,boolean flag) {} ]
* 制作按键函数
* 参数 :String picName 表示按键上的ICO文件名
* String text 表示按键的名称
* String toolTip 表示按键的ToolTip标示
* boolean 表示按键为大图标工具栏模式
* 返回值:无
* 修饰符:private
* 功能 :制作带ICO和气泡提示的工具栏按键,仅类内使用
**=======================================================================**
*/
private void buildButton(String picName, String text, String toolTip,boolean flag) {
this.setIcon (new ImageIcon (picName));
this.setText (text);
this.setToolTipText (toolTip);
if(flag) {
//this.setBorderPainted (false);
this.setContentAreaFilled(false); //设置背景色透明
this.setHorizontalTextPosition (SwingConstants.CENTER);
this.setVerticalTextPosition (SwingConstants.BOTTOM);
}//End if(flag)
this.addMouseListener(this);
}
/**=======================================================================**
* MouseListener 监听
**=======================================================================**
*/
public void mouseClicked (MouseEvent me) {
}
public void mousePressed (MouseEvent me) {
}
public void mouseReleased(MouseEvent me) {
}
public void mouseEntered (MouseEvent me) {
this.setForeground(new Color(156, 126, 66));
this.setBackground(new Color(234, 223, 203));
}
public void mouseExited (MouseEvent me) {
this.setForeground(new Color( 87, 87, 47));
this.setBackground(new Color(231, 215, 183));
}
}
TJList.java
/**
*##############################################################################
*
* [ 项目名 ] :
* [ 公司名 ] : SunshineSOFT
* [ 模块名 ] : 带监听的JList列表框
* [ 文件名 ] : TJList.java
* [ 相关文件 ] :
* [ 文件实现功能] : 带监听的文本区域
* [ 作者 ] : 顾俊
* [ 版本 ] : 1.0
* ----------------------------------------------------------------------------
* [ 备注 ] :
* ----------------------------------------------------------------------------
* [ 修改记录 ] :
*
* [ 日 期 ] [版本] [修改人] [修改内容]
* 2006/04/25 1.0 顾俊 创建
* ##--------------------------------------------------------------------------
* 版权所有(c) 20##-2007, SunshineSOFT Corporation
* --------------------------------------------------------------------------##
*
* [ 函数说明 ] :
*
* [## public TJList() {} ]:
* 功能: 构造函数
*
* [ 遗留问题 ] :
*
*##############################################################################
*/
package com.sunshine.sunsdk.swing;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class TJList
extends JList
implements MouseListener {
public TJList() {
//设置显示的行数
this.setVisibleRowCount(5);
//设置前景色和后景色
this.setForeground(new Color(141, 131, 106));
this.setBackground(new Color(244, 238, 227));
//加鼠标监听
this.addMouseListener(this);
}
/**=======================================================================**
* MouseListener 监听
**=======================================================================**
*/
public void mouseClicked (MouseEvent me) {
}
public void mousePressed (MouseEvent me) {
}
public void mouseReleased(MouseEvent me) {
}
public void mouseEntered (MouseEvent me) {
this.setForeground(new Color( 87, 87, 47));
this.setBackground(new Color(248, 242, 230));
}
public void mouseExited (MouseEvent me) {
this.setForeground(new Color(141, 131, 106));
this.setBackground(new Color(244, 238, 227));
}
}
TJMoneyField.java
/**
*##############################################################################
*
* [ 项目名 ] :
* [ 公司名 ] : SunshineSOFT
* [ 模块名 ] : 金额文本框
* [ 文件名 ] : TJMoneyField.java
* [ 相关文件 ] :
* [ 文件实现功能] : 金额文本框
* [ 作者 ] : 顾俊
* [ 版本 ] : 1.0
* ----------------------------------------------------------------------------
* [ 备注 ] :
* ----------------------------------------------------------------------------
* [ 修改记录 ] :
*
* [ 日 期 ] [版本] [修改人] [修改内容]
* 2006/04/16 1.0 顾俊 创建
* ##--------------------------------------------------------------------------
* 版权所有(c) 20##-2007, SunshineSOFT Corporation
* --------------------------------------------------------------------------##
*
* [ 函数说明 ] :
*
* [## public TJMoneyField () {} ]:
* 功能: 构造函数 金额输入本文框,默认长度6
*
* [## public TJMoneyField (String text) {} ]:
* 功能: 构造函数 金额输入本文框,默认长度10
*
* [## public TJMoneyField (String text, int length) {} ]:
* 功能: 构造函数 建立一个指定金额和长度的金额输入本文框
*
* [## private void setLayout (int l) {} ]:
* 功能: 设置金额输入本文框的对齐方式和和列数并加焦点监听
*
* [## private void buildMoneyField (String text, boolean build) {} ]:
* 功能: 制作金额输入本文框
*
* [## public String getText () {} ]:
* 功能: 获得文本框金额 重写了JTextField的getText()方法
*
* [## public void setText (String text) {} ]:
* 功能: 设置文本框金额 重写了JTextField的setText()方法
*
* [ 遗留问题 ] :
*
*##############################################################################
*/
package com.sunshine.sunsdk.swing;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import com.sunshine.sunsdk.system.*;
import com.sunshine.sunsdk.swing.*;
public class TJMoneyField
extends TJTextField
implements FocusListener {
/**=======================================================================**
* [## public TJMoneyField () {} ]: 构造函数
* 参数 :无
* 返回值:无
* 修饰符:public
* 功能 :金额输入本文框,默认长度6
**=======================================================================**
*/
public TJMoneyField () {
buildMoneyField ("0.00",true);
setLayout (6); //设置部局
}
/**=======================================================================**
* [## public TJMoneyField (String text) {} ]: 构造函数
* 参数 :String 对象表示文本框初始化的金额
* 返回值:无
* 修饰符:public
* 功能 :金额输入本文框,默认长度10
**=======================================================================**
*/
public TJMoneyField (String text) {
buildMoneyField (text, true);
setLayout (10); //设置部局
}
/**=======================================================================**
* [## public TJMoneyField (String text, int length) {} ]: 构造函数
* 参数 :String 对象表示文本框初始化的金额
* int 变量表示文本框的长度
* 返回值:无
* 修饰符:public
* 功能 :建立一个指定金额和长度的金额输入本文框
**=======================================================================**
*/
public TJMoneyField (String text, int length) {
buildMoneyField (text, true);
setLayout (length); //设置部局
}
/**=======================================================================**
* [## private void setLayout (int l) {} ]: 构造函数
* 参数 :int 变量表示文本框的长度
* 返回值:无
* 修饰符:private
* 功能 :设置金额输入本文框的对齐方式和和列数并加焦点监听
**=======================================================================**
*/
private void setLayout (int l) {
this.setColumns(l); //设置文本框列数
this.setHorizontalAlignment (JTextField.RIGHT); //设置文本右对齐
this.addFocusListener(this); //加焦点监听
}
/**=======================================================================**
* [## private void buildMoneyField (String text, boolean build) {} ]:
* 参数 :String 对象表示金额 制作金额本文框
* boolean 变量表示是新建文本框还是焦点事件调用
* 返回值:无
* 修饰符:private
* 功能 :制作金额输入本文框
**=======================================================================**
*/
private void buildMoneyField (String text, boolean build) {
//判断金额是否合法
if(suntools.isNum (text, 11, 0, 9999999.99)) {
//去掉金额开头的'0'
text = Double.parseDouble(text) + "";
//判断如果只有一位小数则补'0'
if(text.length() - text.indexOf('.') == 2) {
text = Double.parseDouble(text) + "0";
}//Endif
super.setText("¥" + text); //设置文本
}//Endif
else {
JOptionPane.showMessageDialog(null, "金额格式错误,或者是金额超出范围:[ 0-9999999.99 ] ...", "错误", JOptionPane.ERROR_MESSAGE);
if(build) //如果是new本类时发生错误,则系统自动退出
System.exit(0);
else {
super.setText ("0");
this.requestFocus(true);//用户使用时发生错误,则重新输入
}//Endif
}//Endif
}
/**=======================================================================**
* [## public String getText () {} ]: 获得文本框金额
* 参数 :无
* 返回值:String 对象表示文本框的金额值
* 修饰符:public
* 功能 :获得文本框金额
**=======================================================================**
*/
public String getText () {
return super.getText().substring(1);
}
/**=======================================================================**
* [## public void setText (String text) {} ]: 设置文本框金额
* 参数 :String 对象表示要设置文本框的金额值
* 返回值:无
* 修饰符:public
* 功能 :设置文本框金额
**=======================================================================**
*/
public void setText (String text) {
buildMoneyField (text, false);
}
/**=======================================================================**
* FocusListener 监听
**=======================================================================**
*/
public void focusGained (FocusEvent fe) {
//焦点监听
super.setText ("0");
}
public void focusLost (FocusEvent fe) {
//失去焦点监听
String t = super.getText();
if(t.length() > 1)
t = t.substring(1);
buildMoneyField (t, false);
}
}
TJPasswordField.java
/**
*##############################################################################
*
* [ 项目名 ] :
* [ 公司名 ] : SunshineSOFT
* [ 模块名 ] : 带监听的密码文本框
* [ 文件名 ] : TJPasswordField.java
* [ 相关文件 ] :
* [ 文件实现功能] : 带监听的密码文本框
* [ 作者 ] : 顾俊
* [ 版本 ] : 1.0
* ----------------------------------------------------------------------------
* [ 备注 ] :
* ----------------------------------------------------------------------------
* [ 修改记录 ] :
*
* [ 日 期 ] [版本] [修改人] [修改内容]
* 2006/04/19 1.0 顾俊 创建
* ##--------------------------------------------------------------------------
* 版权所有(c) 20##-2007, SunshineSOFT Corporation
* --------------------------------------------------------------------------##
*
* [ 函数说明 ] :
*
* [## public TJPasswordField(String text) {} ]:
* 功能: 构造函数
*
* [## public TJPasswordField(String text, int column) {} ]:
* 功能: 构造函数
*
* [## public void setLineWidth(int l) {} ]:
* 功能: 设置外框线宽
*
* [ 遗留问题 ] :
*
*##############################################################################
*/
package com.sunshine.sunsdk.swing;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
public class TJPasswordField
extends JPasswordField
implements MouseListener, FocusListener {
private int thickness = 1;
public TJPasswordField() {
setStyle();
}
public TJPasswordField(int col) {
super(col);
setStyle();
}
public TJPasswordField(String text) {
super(text);
setStyle();
}
public TJPasswordField(String text, int column) {
super(text, column);
setStyle();
}
public void setLineWidth(int l) {
thickness = l;
this.setBorder(new LineBorder(new Color(159, 145, 118), thickness));
}
private void setStyle() {
this.setForeground(new Color( 87, 87, 47));
this.setBackground(new Color(248, 242, 230));
this.setBorder(new LineBorder(new Color(159, 145, 118), thickness));
this.addMouseListener(this);
this.addFocusListener(this);
}
/**=======================================================================**
* MouseListener 监听
**=======================================================================**
*/
public void mouseClicked (MouseEvent me) {
}
public void mousePressed (MouseEvent me) {
}
public void mouseReleased(MouseEvent me) {
}
public void mouseEntered (MouseEvent me) {
this.setBorder(new LineBorder(new Color(241, 171, 84), thickness));
}
public void mouseExited (MouseEvent me) {
this.setBorder(new LineBorder(new Color(159, 145, 118), thickness));
}
/**=======================================================================**
* FocusListener 监听
**=======================================================================**
*/
public void focusGained (FocusEvent fe) {
this.setBorder(new LineBorder(new Color(241, 171, 84), thickness));
}
public void focusLost (FocusEvent fe) {
this.setBorder(new LineBorder(new Color(159, 145, 118), thickness));
}
}
TJTextField.java
/**
*##############################################################################
*
* [ 项目名 ] :
* [ 公司名 ] : SunshineSOFT
* [ 模块名 ] : 带监听的文本区域
* [ 文件名 ] : TJTextField.java
* [ 相关文件 ] :
* [ 文件实现功能] : 带监听的文本区域
* [ 作者 ] : 顾俊
* [ 版本 ] : 1.0
* ----------------------------------------------------------------------------
* [ 备注 ] :
* ----------------------------------------------------------------------------
* [ 修改记录 ] :
*
* [ 日 期 ] [版本] [修改人] [修改内容]
* 2006/04/19 1.0 顾俊 创建
* ##--------------------------------------------------------------------------
* 版权所有(c) 20##-2007, SunshineSOFT Corporation
* --------------------------------------------------------------------------##
*
* [ 函数说明 ] :
*
* [## public TJTextArea(int r, int c) {} ]:
* 功能: 构造函数
*
* [ 遗留问题 ] :
*
*##############################################################################
*/
package com.sunshine.sunsdk.swing;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class TJTextArea
extends JTextArea
implements MouseListener {
public TJTextArea(int r, int c) {
super(r, c);
this.setForeground(new Color(161, 149, 121));
this.setBackground(new Color(233, 227, 214));
this.addMouseListener(this);
}
/**=======================================================================**
* MouseListener 监听
**=======================================================================**
*/
public void mouseClicked (MouseEvent me) {
}
public void mousePressed (MouseEvent me) {
}
public void mouseReleased(MouseEvent me) {
}
public void mouseEntered (MouseEvent me) {
this.setForeground(new Color( 87, 87, 47));
this.setBackground(new Color(248, 242, 230));
}
public void mouseExited (MouseEvent me) {
this.setForeground(new Color(161, 149, 121));
this.setBackground(new Color(233, 227, 214));
}
}
TJTextField.java
/**
*##############################################################################
*
* [ 项目名 ] :
* [ 公司名 ] : SunshineSOFT
* [ 模块名 ] : 带监听的文本框
* [ 文件名 ] : TJTextField.java
* [ 相关文件 ] :
* [ 文件实现功能] : 带监听的文本框
* [ 作者 ] : 顾俊
* [ 版本 ] : 1.0
* ----------------------------------------------------------------------------
* [ 备注 ] :
* ----------------------------------------------------------------------------
* [ 修改记录 ] :
*
* [ 日 期 ] [版本] [修改人] [修改内容]
* 2006/04/19 1.0 顾俊 创建
* ##--------------------------------------------------------------------------
* 版权所有(c) 20##-2007, SunshineSOFT Corporation
* --------------------------------------------------------------------------##
*
* [ 函数说明 ] :
*
* [## public TJTextField(String text) {} ]:
* 功能: 构造函数
*
* [## public TJTextField(String text, int column) {} ]:
* 功能: 构造函数
*
* [## public void setLineWidth(int l) {} ]:
* 功能: 设置外框线宽
*
* [ 遗留问题 ] :
*
*##############################################################################
*/
package com.sunshine.sunsdk.swing;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
public class TJTextField
extends JTextField
implements MouseListener, FocusListener {
private int thickness = 1;
public TJTextField() {
setStyle();
}
public TJTextField(int col) {
super(col);
setStyle();
}
public TJTextField(String text) {
super(text);
setStyle();
}
public TJTextField(String text, int column) {
super(text, column);
setStyle();
}
public void setLineWidth(int l) {
thickness = l;
this.setBorder(new LineBorder(new Color(159, 145, 118), thickness));
}
private void setStyle() {
this.setForeground(new Color( 87, 87, 47));
this.setBackground(new Color(248, 242, 230));
this.setBorder(new LineBorder(new Color(159, 145, 118), thickness));
this.addMouseListener(this);
this.addFocusListener(this);
}
/**=======================================================================**
* MouseListener 监听
**=======================================================================**
*/
public void mouseClicked (MouseEvent me) {
}
public void mousePressed (MouseEvent me) {
}
public void mouseReleased(MouseEvent me) {
}
public void mouseEntered (MouseEvent me) {
this.setBorder(new LineBorder(new Color(241, 171, 84), thickness));
}
public void mouseExited (MouseEvent me) {
this.setBorder(new LineBorder(new Color(159, 145, 118), thickness));
}
/**=======================================================================**
* FocusListener 监听
**=======================================================================**
*/
public void focusGained (FocusEvent fe) {
this.setBorder(new LineBorder(new Color(241, 171, 84), thickness));
}
public void focusLost (FocusEvent fe) {
this.setBorder(new LineBorder(new Color(159, 145, 118), thickness));
}
}
ViewList.java
/**
*##############################################################################
*
* [ 项目名 ] :
* [ 公司名 ] : SunshineSOFT
* [ 模块名 ] : ViewList控件
* [ 文件名 ] : ViewList.java
* [ 相关文件 ] :
* [ 文件实现功能] : 生成和我的电脑差不多的面板
* [ 作者 ] : 顾俊
* [ 版本 ] : 1.0
* ----------------------------------------------------------------------------
* [ 备注 ] :
* ----------------------------------------------------------------------------
* [ 修改记录 ] :
*
* [ 日 期 ] [版本] [修改人] [修改内容]
* 2006/04/19 1.0 顾俊 创建
* ##--------------------------------------------------------------------------
* 版权所有(c) 20##-2007, SunshineSOFT Corporation
* --------------------------------------------------------------------------##
*
* [ 函数说明 ] :
*
* [## public ViewList(int buttons) {} ]:
* 功能: 构造函数,并制作主面板
*
* [## public void remeButtons() {} ]:
* 功能: 补按键空位
*
* [## public JButton getButton(String roomNum) {} ]:
* 功能: 获得面板中的指定按键
*
* [## public void setButtonImage(String buttonName, String state) {} ]:
* 功能: 设置按键图片
*
* [## public void addButton(String name) {} ]:
* 制作功能按键,并加入相应的模板中,返回JButton方便主程序加监听
*
* [ 遗留问题 ] :
*
*##############################################################################
*/
package com.sunshine.sunsdk.swing;
import javax.swing.*;
import java.awt.*;
import java.util.*;
public class ViewList extends JPanel {
//放置按键的数组
private Hashtable buttons = new Hashtable();
//放置按键的面板
private JPanel panelMain;
//ViewList 里面横向按键的个数,和行数
private int column = 6;
private int row = 5;
//面板内按键总数
private int buttonTotal = 30;
//按键记数器
private int buttonCount = 0;
/**=======================================================================**
* [## public ViewList(int buttons) {} ]: 构造函数,并制作主面板
* 参数 :int buttons 表示ViewList中的按键数量
* 返回值:无
* 修饰符:public
* 功能 :构造函数,并制作主面板
**=======================================================================**
*/
public ViewList(int buttons) {
super(new BorderLayout());
JScrollPane spMain; //定义滚动面板
//根据按键数据计算面板的行数和列数
int vRow = buttons / column;
if(vRow > row) { //如果有足够的按键数量,则设置面板行数,
if(buttons % column > 0) { //否则使用默认行数 row = 5
row = vRow + 1;
}else {
row = vRow;
}//Endif
buttonTotal = buttons; //获得按键总数
}//Endif
//建立按键面板
panelMain = new JPanel(new GridLayout(row, 1, 5, 15));
//设置默认背景色
panelMain.setBackground(new Color(248, 242, 230));
spMain = new JScrollPane(panelMain);
//加入主面板
this.add("Center", spMain);
}
/**=======================================================================**
* [## public void remeButtons() {} ]: 补按键空位
* 参数 :无
* 返回值:无
* 修饰符:public
* 功能 :补按键空位,如果按键数量不足 column * row 则加空JLabel补位,
* 不然总局会乱 注意,此方法一定要在加完所有按键后使用
**=======================================================================**
*/
public void remeButtons() {
if(buttonCount < buttonTotal) {
for (int i = 0; i < buttonTotal - buttonCount; i++) {
JLabel lb = new JLabel(" ");
panelMain.add(lb); //补空位
}//Endfor
}//Endif
}
/**=======================================================================**
* [## public JButton getButton(String roomNum) {} ]:
* 参数 :String roomNum 对象表示按键名字,也就是房间号
* 返回值:JButton
* 修饰符:public
* 功能 :获得面板中的指定按键
**=======================================================================**
*/
public JButton getButton(String roomNum) {
return (JButton)buttons.get(roomNum);
}
/**=======================================================================**
* [## public void setButtonImage(String buttonName, String state) {} ]:
* 参数 :String buttonName 对象表示按键在哈希表中的键名
* String State 对象表示房间状态
* 返回值:无
* 修饰符:public
* 功能 :设置按键图片
**=======================================================================**
*/
public void setButtonImage(String buttonName, String state) {
String picName = "";
if(state.equals("可供"))
picName = "pic/room/prov.gif";
else if(state.equals("占用"))
picName = "pic/room/pree.gif";
else if(state.equals("预订"))
picName = "pic/room/rese.gif";
else if(state.equals("钟点"))
picName = "pic/room/clock.gif";
else if(state.equals("脏房"))
picName = "pic/room/clean.gif";
else if(state.equals("停用"))
picName = "pic/room/stop.gif";
((JButton)buttons.get(buttonName)).setIcon(new ImageIcon(picName));
}
/**=======================================================================**
* [## public void addButton(String name) {} ]:
* 参数 :String name 表示功能按键的名字
* 返回值:JButton
* 修饰符:public
* 功能 :制作功能按键,并加入相应的模板中,返回JButton方便主程序加监听
**=======================================================================**
*/
public JButton addButton(String name) {
JButton button = new JButton(name);
button.setBorderPainted(false); //设置按键无边框
button.setContentAreaFilled(false); //设置按键背景色透明
button.setHorizontalTextPosition(SwingConstants.CENTER);//设置Ico与文字居中
button.setVerticalTextPosition(SwingConstants.BOTTOM);//设置Ico相对文字的位置
panelMain.add(button); //将按键加入按键面板
buttons.put(name, button); //将按键存入哈希表
buttonCount++; //按键记数器+1
return button;
}
}
Swing包.theme包
DarkGoldMetalTheme.java
/**
*##############################################################################
*
* [ 项目名 ] :
* [ 公司名 ] : SunshineSOFT
* [ 模块名 ] : 暗金色主题类
* [ 文件名 ] : DarkGoldMetalTheme.java
* [ 相关文件 ] :
* [ 文件实现功能] : 配置窗口为暗金色主题
* [ 作者 ] : 顾俊
* [ 版本 ] : 1.0
* ----------------------------------------------------------------------------
* [ 备注 ] :
* ----------------------------------------------------------------------------
* [ 修改记录 ] :
*
* [ 日 期 ] [版本] [修改人] [修改内容]
* 2006/04/19 1.0 顾俊 创建
* ##--------------------------------------------------------------------------
* 版权所有(c) 20##-2007, SunshineSOFT Corporation
* --------------------------------------------------------------------------##
*
* [ 函数说明 ] :
*
* [## public String getName() {} ]:
* 功能: 返回主题名
*
* [ 遗留问题 ] :
*
*##############################################################################
*/
package com.sunshine.sunsdk.swing.Theme;
import javax.swing.*;
import javax.swing.plaf.*;
import javax.swing.plaf.metal.*;
import javax.swing.border.*;
import java.awt.*;
public class DarkGoldMetalTheme extends DefaultMetalTheme {
public String getName() { return "Sandstone"; }
private final ColorUIResource primary1 = new ColorUIResource( 87, 87, 47);
private final ColorUIResource primary2 = new ColorUIResource(159, 151, 111);
private final ColorUIResource primary3 = new ColorUIResource(199, 183, 143);
private final ColorUIResource secondary1 = new ColorUIResource(111, 111, 111);
private final ColorUIResource secondary2 = new ColorUIResource(184, 173, 151);
private final ColorUIResource secondary3 = new ColorUIResource(231, 215, 183);
protected ColorUIResource getPrimary1() { return primary1; }
protected ColorUIResource getPrimary2() { return primary2; }
protected ColorUIResource getPrimary3() { return primary3; }
protected ColorUIResource getSecondary1() { return secondary1; }
protected ColorUIResource getSecondary2() { return secondary2; }
protected ColorUIResource getSecondary3() { return secondary3; }
}
DesertMetalTheme.java
/**
*##############################################################################
*
* [ 项目名 ] :
* [ 公司名 ] : SunshineSOFT
* [ 模块名 ] : 沙漠色主题类
* [ 文件名 ] : DesertMetalTheme.java
* [ 相关文件 ] :
* [ 文件实现功能] : 配置窗口为沙漠色主题
* [ 作者 ] : 顾俊
* [ 版本 ] : 1.0
* ----------------------------------------------------------------------------
* [ 备注 ] :
* ----------------------------------------------------------------------------
* [ 修改记录 ] :
*
* [ 日 期 ] [版本] [修改人] [修改内容]
* 2006/04/30 1.0 顾俊 创建
* ##--------------------------------------------------------------------------
* 版权所有(c) 20##-2007, SunshineSOFT Corporation
* --------------------------------------------------------------------------##
*
* [ 函数说明 ] :
*
* [## public String getName() {} ]:
* 功能: 返回主题名
*
* [ 遗留问题 ] :
*
*##############################################################################
*/
package com.sunshine.sunsdk.swing.Theme;
import javax.swing.*;
import javax.swing.plaf.*;
import javax.swing.plaf.metal.*;
import javax.swing.border.*;
import java.awt.*;
public class DesertMetalTheme extends DefaultMetalTheme {
public String getName() { return "Desert"; }
private final ColorUIResource primary1 = new ColorUIResource(147, 118, 30);
private final ColorUIResource primary2 = new ColorUIResource(219, 177, 50);
private final ColorUIResource primary3 = new ColorUIResource(237, 195, 67);
private final ColorUIResource secondary1 = new ColorUIResource(170, 121, 53);
private final ColorUIResource secondary2 = new ColorUIResource(200, 167, 68);
private final ColorUIResource secondary3 = new ColorUIResource(243, 208, 100);
protected ColorUIResource getPrimary1() { return primary1; }
protected ColorUIResource getPrimary2() { return primary2; }
protected ColorUIResource getPrimary3() { return primary3; }
protected ColorUIResource getSecondary1() { return secondary1; }
protected ColorUIResource getSecondary2() { return secondary2; }
protected ColorUIResource getSecondary3() { return secondary3; }
}
3)sql包
Journal.java
/**
*##############################################################################
*
* [ 项目名 ] :
* [ 公司名 ] : SunshineSOFT
* [ 模块名 ] : 日志操作处理
* [ 文件名 ] : Journal.java
* [ 相关文件 ] :
* [ 文件实现功能] : 写操作日志到数据库
* [ 作者 ] : 顾俊
* [ 版本 ] : 1.1
* ----------------------------------------------------------------------------
* [ 备注 ] :
* ----------------------------------------------------------------------------
* [ 修改记录 ] :
*
* [ 日 期 ] [版本] [修改人] [修改内容]
* 2006/04/19 1.0 顾俊 创建
* ##--------------------------------------------------------------------------
* 版权所有(c) 20##-2007, SunshineSOFT Corporation
* --------------------------------------------------------------------------##
*
* [ 函数说明 ] :
*
* [## private Journal() {} ]:
* 功能: 防止本类不能被实例化
*
* [## public static String getNowDTime() {} ]:
* 功能: 返回当前日期时间
*
* [## public static boolean writeJournalInfo(String user, String content,int infoIndex) {} ]:
* 功能: 记录操作日志
*
* [ 遗留问题 ] :
*
*##############################################################################
*/
package com.sunshine.sunsdk.sql;
import java.util.*;
import com.sunshine.sunsdk.sql.sunsql;
public class Journal {
public static final int TYPE_LG = 0; //操作员登录
public static final int TYPE_RT = 1; //房间类型操作
public static final int TYPE_RI = 2; //房间信息操作
public static final int TYPE_US = 3; //客户信息操作
public static final int TYPE_CZ = 4; //操作员设置
public static final int TYPE_JF = 5; //计费设置
public static final int TYPE_DA = 6; //数据操作
public static String brief[] = { "操作员登录", "房间类型操作", "房间信息操作",
"客户信息操作", "操作员设置","计费设置","数据操作"};
/**=======================================================================**
* [## private Journal() {} ]: 构造函数
* 参数 :无
* 返回值:无
* 修饰符:private
* 功能 :防止本类不能被实例化
**=======================================================================**
*/
private Journal() {
}
/**=======================================================================**
* [## public static String getNowDTime() {} ]: 返回当前日期时间
* 参数 :无
* 返回值:String 对象表示当前系统时间
* 修饰符:public
* 功能 :返回当前日期时间
**=======================================================================**
*/
public static String getNowDTime() {
GregorianCalendar gc = new GregorianCalendar();
return gc.getTime().toLocaleString();
}
/**=======================================================================**
* [## public static boolean writeJournalInfo(String user, String content,int infoIndex) {} ]:
* 参数 :String user 表示当前操作员
* String content 表示操作内容
* int infoIndex 操作类型
* 返回值:boolean
* 修饰符:public
* 功能 :记录操作日志
**=======================================================================**
*/
public static boolean writeJournalInfo(String user, String content,int infoIndex) {
String dt = getNowDTime(); //获得当前时间
content = user + " 在 " + dt + " " + content; //操作内容
long pk = sunsql.getPrimaryKey(); //获得主键
String sqlCode = "insert into record(pk,time,operator,brief,content) values(" +
pk + ",'" + dt + "','" + user + "','" + brief[infoIndex] + "','" + content + "')";
if(sunsql.executeUpdate(sqlCode) == 0) { //写操作日志
return false;
}//Endif
return true;
}
}
sunsql.java
/**
*##############################################################################
*
* [ 项目名 ] :
* [ 公司名 ] : SunshineSOFT
* [ 模块名 ] : 数据库连接
* [ 文件名 ] : sunsql.java
* [ 相关文件 ] :
* [ 文件实现功能] : 连接及操作数据库
* [ 作者 ] : 顾俊
* [ 版本 ] : 1.3
* ----------------------------------------------------------------------------
* [ 备注 ] :
* ----------------------------------------------------------------------------
* [ 修改记录 ] :
*
* [ 日 期 ] [版本] [修改人] [修改内容]
* 2006/03/31 1.0 顾俊 重新组织
* 2006/04/05 1.1 顾俊 添加ODBC连接方式
* 2006/04/08 1.2 顾俊 添加函数 #A, #B, #C, #D
* 2006/04/25 1.2 顾俊 添加函数 #E
* ##--------------------------------------------------------------------------
* 版权所有(c) 20##-2007, SunshineSOFT Corporation
* --------------------------------------------------------------------------##
*
* [ 函数说明 ] :
*
* [## private sunsql() {} ] :
* 功能: 防止实例化sunsql对象
*
* [## public static int executeUpdate(String sql) {} ] :
* 功能: 执行对数据库更改的sql命令,并返回更改所影响的行数
*
* [## public static ResultSet executeQuery(String sql) {} ] :
* 功能: 执行对数据库的select查询功能,并返回查询所得到的结果
*
* [## public static int recCount(ResultSet rs)) {} ] :
* 功能: 获得指定结果集的记录数量
*
* [## public static long getPrimaryKey() {} ] : #A
* 功能: 通过服务器当前的时间获得一个主键
*
* [## public static void initJComboBox (JComboBox cb, String sqlCode) {} ] : #B
* 功能: 按SQL语句从数据库选出Items加入JComboBox
*
* [## public static void initJList (JList jt, String sqlCode) {} ] : #E
* 功能: 按SQL语句从数据库选出数据加入JList
*
* [## public static void initDTM (DefaultTableModel fdtm, String sqlCode) {} ] : #C
* 功能: 按SQL语句从数据库中获得数据(结果集),添加到fdtm中(也可以说JTable中)
*
* [## public static int runTransaction (String updateCode[]) {} ] : #D
* 功能: 利用事务的模式以updateCode中的sql语句对数据库进行更新
*
*
* [ 遗留问题 ] :
*
* [ 数据库连接关闭问题 ] : 现在: 只有应用程序完全退出时数据库连接才关闭
* 目的: 每次数据库操作完成后都要关闭
*
*
*##############################################################################
*/
package com.sunshine.sunsdk.sql;
import java.sql.*;
import javax.swing.*;
import javax.swing.table.*;
import com.sunshine.sunsdk.system.*;
public class sunsql {
private static Statement ste = null;
private static Connection conn = null;
static {
try {
if(sunini.getIniKey ("Default_Link").equals ("1")) { //JDBC连接方式
String user = sunini.getIniKey ("UserID");
String pwd = sunini.getIniKey ("Password");
String ip = sunini.getIniKey ("IP");
String acc = sunini.getIniKey ("Access");
String dbf = sunini.getIniKey ("DBFname");
String url = "jdbc:microsoft:sqlserver://" + ip + ":" + acc + ";" + "databasename=" + dbf;
//注册驱动
DriverManager.registerDriver (new com.microsoft.jdbc.sqlserver.SQLServerDriver());
//获得一个连接
conn = DriverManager.getConnection (url, user, pwd);
}
else {
//注册驱动 //JDBCODBC连接方式
DriverManager.registerDriver (new sun.jdbc.odbc.JdbcOdbcDriver());
//获得一个连接
conn = DriverManager.getConnection ("jdbc:odbc:" + sunini.getIniKey("LinkName"));
}
//设置自动提交为false
conn.setAutoCommit (false);
//建立高级载体
ste = conn.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
}
catch (Exception ex) {
JOptionPane.showMessageDialog (null, "数据库连接失败...", "错误", JOptionPane.ERROR_MESSAGE);
System.exit(0);
//ex.printStackTrace();
}//End try
}
/**=======================================================================**
* [## private sunsql() {} ]: 构造函数
* 参数 :无
* 返回值:无
* 修饰符:private
* 功能 :防止实例化sunsql对象
**=======================================================================**
*/
private sunsql(){
}
/**=======================================================================**
* [## public static int executeUpdate(String sql) {} ] :
* 参数 :String 对象, 表示需要执行的sql语句
* 返回值:int, 表示此sql语句对数据库影响了几行
* 修饰符:public static 可以不实例化对象而直接调用方法
* 功能 :执行对数据库更改的sql命令,并返回更改所影响的行数
**=======================================================================**
*/
public static int executeUpdate(String sql) {
// System.out.println ("Update SQL : " + sql);
int i = 0 ;
try {
i = ste.executeUpdate(sql) ;
conn.commit();
}catch(Exception e) {
e.printStackTrace() ;
}//End try
return i ;
}
/**=======================================================================**
* [## public static int runTransaction (String updateCode[]) {} ] :
* 参数 :String[]是字符串数组, 表示需要执行的所有sql语句
* 返回值:int, 表示sql语句执行的情况, (i==数组长度)为更新成功
* 修饰符:public static 可以不实例化对象而直接调用方法
* 功能 :利用事务的模式以updateCode中的sql语句对数据库进行更新
**=======================================================================**
*/
public static int runTransaction (String updateCode[]) {
int ok = 0, i = 0;
int row = updateCode.length; //更新语句的数量
try {
for (i = 0; i < row; i++) {
ok = ste.executeUpdate (updateCode[i]); //执行SQL语句
if(ok == 0) { //如果不成功,则跳出循环
System.out.println ("sunsql.runTransaction(): updateCode[" + i + "] 失败" + ok);
break;
}
System.out.println ("sunsql.runTransaction(): updateCode[" + i + "] 成功 " + ok);
}
//根据变量 ok 判断上面循环是否正常运行完毕
if(ok == 0) {
conn.rollback (); //(ok == 0)表示更新过程中出错,回滚数据
System.out.println ("sunsql.runTransaction(): Update data false, rollback");
}
else {
conn.commit (); //(ok != 0)基本上是所有SQL语句运行成功, 则提交给数据库
System.out.println ("sunsql.runTransaction(): Update finish");
}
}
catch (Exception ex) {
System.out.println ("sunsql.runTransaction(): Update false ...");
}
return i;
}
/**=======================================================================**
* [## public static ResultSet executeQuery(String sql) {} ] :
* 参数 :String 对象, 表示需要执行的sql语句
* 返回值:ResultSet对象, 表示此查询语句返回的结果集
* 修饰符:public static 可以不实例化对象而直接调用方法
* 功能 :执行对数据库的select查询功能,并返回查询所得到的结果
**=======================================================================**
*/
public static ResultSet executeQuery(String sql) {
// System.out.println ("Query SQL : " + sql);
ResultSet rs = null ;
try {
rs = ste.executeQuery(sql) ;
}catch(Exception e) {
e.printStackTrace() ;
}//End try
return rs ;
}
/**=======================================================================**
* [## public static int recCount(ResultSet rs)) {} ] :
* 参数 :ResultSet 对象, 表示目标结果集
* 返回值:int, 表示结果集中的记录个数
* 修饰符:public static 可以不实例化对象而直接调用方法
* 功能 :获得指定结果集的记录数量
**=======================================================================**
*/
public static int recCount(ResultSet rrs) {
int i = 0;
try {
if(rrs.getRow() != 0)
rrs.beforeFirst();
//while用于计算rs的记录条数
while(rrs.next())
i++;
rrs.beforeFirst();
}catch(Exception ex) {
ex.printStackTrace();
}//End try
return i;
}
/**=======================================================================**
* [## public static long getPrimaryKey() {} ] :
* 参数 :无
* 返回值:long, 表示从服务器获得的主键
* 修饰符:public static 可以不实例化对象而直接调用方法
* 功能 :通过服务器当前的时间获得一个主键
**=======================================================================**
*/
public static long getPrimaryKey() {
long pk = 0;
try {
//获得服务器时间
ResultSet rs = executeQuery("select getdate()");
rs.next();
pk = rs.getTimestamp(1).getTime();
}
catch (Exception ex) {
System.out.println ("sunsql.getPrimaryKey (): false");
}
return pk;
}
/**=======================================================================**
* [## public static void initJComboBox (JComboBox cb, String sqlCode) {} ] :
* 参数 :JComboBox表示要加数据的下拉框, String对象表示一条SQL语句
* 返回值:JComboBox, 表示返回一个加好Item的JComboBox对象
* 修饰符:public static 可以不实例化对象而直接调用方法
* 功能 :按SQL语句从数据库选出Items加入JComboBox
**=======================================================================**
*/
public static void initJComboBox (JComboBox cb, String sqlCode) {
cb.removeAllItems();
try {
ResultSet rs = executeQuery (sqlCode);
int row = recCount (rs);
rs.beforeFirst ();
//从结果集中取出Item加入JComboBox中
for (int i = 0; i < row; i++) {
rs.next();
cb.addItem (rs.getString (1));
}
}
catch (Exception ex) {
System.out.println ("sunsql.initJComboBox (): false");
}
}
/**=======================================================================**
* [## public static void initJList (JList jt, String sqlCode) {} ] :
* 参数 :JList表示要加数据的列表框, String对象表示一条SQL语句
* 返回值:无
* 修饰符:public static 可以不实例化对象而直接调用方法
* 功能 :按SQL语句从数据库选出数据加入JList
**=======================================================================**
*/
public static void initJList (JList jt, String sqlCode) {
try {
ResultSet rs = executeQuery (sqlCode);
int row = recCount (rs);
String list[] = new String[row];
//从结果集中取出数据存入数组中
for (int i = 0; i < row; i++) {
rs.next();
list[i] = rs.getString(1);
}//Endfor
jt.setListData(list); //初始化List
}
catch (Exception ex) {
System.out.println ("sunsql.initJList(): false");
}//Endtry
}
/**=======================================================================**
* [## public static void initDTM (DefaultTableModel fdtm, String sqlCode) {} ] :
* 参数 :DefaultTableModel对象表示要添充数据的表模式
* String对象表示一条SQL语句
* 返回值:无
* 修饰符:public static 可以不实例化对象而直接调用方法
* 功能 :按SQL语句从数据库中获得数据,添加到fdtm中(也可以说JTable中)
**=======================================================================**
*/
public static void initDTM (DefaultTableModel fdtm, String sqlCode) {
try {
ResultSet rs = executeQuery( sqlCode ); //获得结果集
int row = recCount( rs ); //获得结果集中有几行数据
ResultSetMetaData rsm =rs.getMetaData(); //获得列集
int col = rsm.getColumnCount(); //获得列的个数
String colName[] = new String[col];
//取结果集中的表头名称, 放在colName数组中
for (int i = 0; i < col; i++) {
colName[i] = rsm.getColumnName( i + 1 );
}//End for
rs.beforeFirst();
String data[][] = new String[row][col];
//取结果集中的数据, 放在data数组中
for (int i = 0; i < row; i++) {
rs.next();
for (int j = 0; j < col; j++) {
data[i][j] = rs.getString (j + 1);
//System.out.println (data[i][j]);
}
}//End for
fdtm.setDataVector (data, colName);
}
catch (Exception ex) {
System.out.println ("sunsql.initDTM (): false");
}//End try
}
}
4)公共类的说明教程
滑动菜单
SlitherMenu.java
/**
*##############################################################################
*
* [ 项目名 ] :
* [ 公司名 ] : SunshineSOFT
* [ 模块名 ] : 滑动菜单
* [ 文件名 ] : SlitherMenu.java
* [ 相关文件 ] :
* [ 文件实现功能] : 防QQ一样的滑动菜单
* [ 作者 ] : 顾俊
* [ 版本 ] : 1.0
* ----------------------------------------------------------------------------
* [ 备注 ] :
* ----------------------------------------------------------------------------
* [ 修改记录 ] :
*
* [ 日 期 ] [版本] [修改人] [修改内容]
* 2006/04/18 1.0 顾俊 创建
* ##--------------------------------------------------------------------------
* 版权所有(c) 20##-2007, SunshineSOFT Corporation
* --------------------------------------------------------------------------##
*
* [ 函数说明 ] :
*
* [## public SlitherMenu() {} ]:
* 功能: 滑动菜单的构造函数 (无部局面板)
*
* [## public void addPanel(String name,String ico, int index, int quantity) {} ]:
* 功能: 制作按键模板,并加入主模板
*
* [## public void addButton(String ico, String name, String tooltip, int index) {} ]:
* 功能: 制作功能按键,并加入相应的模板中
*
* [## public void initButtonPanelDimension() {} ]:
* 功能: 初始化每个按键模板的最大尺寸(在主窗口的setVisible()方法之前使用)
*
* [## public void setInitMenu() {} ]:
* 功能: 设置初始化后展开第一项菜单(在主窗口的setVisible()方法之后使用)
*
* [## public void setMenuDimension(int w,int h) {} ]:
* 功能: 设置菜单宽度和高度(在初始化菜单后加入组件之前使用)
*
* [## public void setMenuLocation(int x, int y) {} ]:
* 功能: 设置菜单的坐标(在初始化菜单后加入组件之前使用)
*
* [## public void setTitleHeight(int h) {} ]:
* 功能: 设置模板标题按键高度(当标题按键有背景图标时才使用本方法)
*
* [## public void setButtonPanelBackground(Color bg) {} ]:
* 功能: 设置按键模板背景颜色(在初始化菜单后加入组件之后使用)
*
* [## public String getSelectButtonName() {} ]:
* 功能: 获得选中的按键名
*
* [## private void slither(int index) {} ]:
* 功能: 处理菜单滑动效果
*
* [ 遗留问题 ] : 1、在改变窗口大小时,不能重画菜单
* 2、不能给各按键模板设置背景图案
* 3、不能改变按键的前景颜色
*
*##############################################################################
*/
//package sunsdk.swing;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class SlitherMenu
extends JPanel
implements ActionListener {
//按键模板数组
private ArrayList template = new ArrayList();
//放置按键面板的数组
private ArrayList buttonPanels = new ArrayList();
//触发ActionListener事件的按键名
private String selectButtonName = "";
//当前展开模板的序号
private int selectPanelNumber = 0;
//将要展开模板的序号
private int selectPanelNumberNew = 0;
//模板总数
private int panelconut = 0;
//定义滑动菜单的坐标
private int sm_X = 0;
private int sm_Y = 0;
//定义滑动菜单的宽度和高度
private int slitherMenuBar_Width = 60;
private int slitherMenuBar_Height = 300;
//按键组模板缩起后的高度
private int titleHeight = 28;
/**=======================================================================**
* [## public SlitherMenu() {} ]: 构造函数
* 参数 :无
* 返回值:无
* 修饰符:public
* 功能 :滑动菜单的构造函数 (无部局面板)
**=======================================================================**
*/
public SlitherMenu() {
super(null); //设置主面板为无部局
}
/**=======================================================================**
* [## public void addPanel(String name,String ico, int index, int quantity) {} ]:
* 参数 :String name 表示按键模板的标题按键名
* String ico 表示标题栏的背景图标
* int index 表示按键模板的索引序号
* int quantity表示模板内将要放入按键的数量
* 返回值:无
* 修饰符:public
* 功能 :制作按键模板,并加入主模板
**=======================================================================**
*/
public void addPanel(String name,String ico, int index, int quantity) {
JButton titleButton;
JScrollPane spPanel;
JPanel panelMain, buttonPanel;
titleButton = new JButton(name, new ImageIcon(ico)); //制作标题按键
panelMain = new JPanel(new BorderLayout(0, 0)); //框架面板为边界部局
buttonPanel = new JPanel(new GridLayout(quantity, 1)); //按键组面板为表格部局
spPanel = new JScrollPane(buttonPanel); //制作滚动面板
spPanel.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
//设置标题按键属性, 如果图标为空,则默认Java原有属性
if(ico.length() > 0) {
titleButton.setFocusPainted(false); //设置焦点外框为假
titleButton.setBorderPainted(false); //设置按键无边框
titleButton.setContentAreaFilled(false); //设置按键背景色透明
titleButton.setHorizontalTextPosition(SwingConstants.CENTER); //设置Ico与文字居中
//panelMain.setBorder(new LineBorder(new Color(184, 207, 229)));//加外框线
}//Endif
//对标题按键加事件监听
titleButton.addActionListener(this);
titleButton.setName(index+ ""); //设置框架面板标志
panelMain.add("North", titleButton); //加入标题按键
panelMain.add("Center",spPanel); //加入按键组面板
this.add(panelMain); //放入菜单面板
panelconut++; //面板记数器+1
template.add(index, panelMain); //将按键模板存入数组
buttonPanels.add(index, buttonPanel); //将放置按键的面板存入数组
}
/**=======================================================================**
* [## public void addButton(String ico, String name, String tooltip, int index) {} ]:
* 参数 :String name 表示功能按键的名字
* String ico 表示功能按键的背景图标
* String tooltip 表示按键的气泡提示文本
* int index 表示按键要放入哪个模板
* 返回值:无
* 修饰符:public
* 功能 :制作功能按键,并加入相应的模板中
**=======================================================================**
*/
public void addButton(String ico, String name, String tooltip, int index) {
JButton button = new JButton(name, new ImageIcon(ico));
button.setToolTipText(tooltip); //设置按键提示
button.setBorderPainted(false); //设置按键无边框
button.setContentAreaFilled(false); //设置按键背景色透明
button.setHorizontalTextPosition(SwingConstants.CENTER);//设置Ico与文字居中
button.setVerticalTextPosition(SwingConstants.BOTTOM);//设置Ico相对文字的位置
button.addActionListener(this); //加事件监听
((JPanel)buttonPanels.get(index)).add(button); //将按键加入按键面板
}
/**=======================================================================**
* [## public void initButtonPanelDimension() {} ]:
* 参数 :无
* 返回值:无
* 修饰符:public
* 功能 :初始化每个按键模板的最大尺寸(在主窗口的setVisible()方法之前使用)
**=======================================================================**
*/
public void initButtonPanelDimension() {
for (int i = 0; i < panelconut; i++) {
((JPanel)template.get(i)).setBounds(sm_X, sm_Y, slitherMenuBar_Width,
slitherMenuBar_Height - titleHeight * (panelconut - 1));
}//Endfor
}
/**=======================================================================**
* [## public void setInitMenu() {} ]:
* 参数 :无
* 返回值:无
* 修饰符:public
* 功能 :设置初始化后展开第一项菜单(在主窗口的setVisible()方法之后使用)
**=======================================================================**
*/
public void setInitMenu() {
if(panelconut > 0) {
JPanel mainMenu = (JPanel)template.get(0); //展开第一项菜单
int titlesHeight = (panelconut - 1) * titleHeight; //获得其它模板标题的高度总和
int height = slitherMenuBar_Height - titlesHeight;
mainMenu.setBounds(sm_X, sm_Y, slitherMenuBar_Width, height);
//处理其它菜单标题
for (int i = 1; i < panelconut; i++) {
((JPanel)template.get(i)).setBounds(sm_X, sm_Y + height + (i - 1) * titleHeight,
slitherMenuBar_Width, titleHeight);
}//Endfor
}else {
String msg = "没有按键模板可组织。";
JOptionPane.showMessageDialog(null, msg, "错误",JOptionPane.ERROR_MESSAGE);
}//Endif
}
/**=======================================================================**
* [## public void setMenuDimension(int w,int h) {} ]:
* 参数 :int w 表示菜单宽度,int h 表示菜单高度
* 返回值:无
* 修饰符:public
* 功能 :设置菜单宽度和高度(在初始化菜单后加入组件之前使用)
**=======================================================================**
*/
public void setMenuDimension(int w,int h) {
if(panelconut == 0) {
slitherMenuBar_Width = w;
slitherMenuBar_Height = h;
}else {
String msg = "setMenuDimension()方法请在加入组件之前使用。";
JOptionPane.showMessageDialog(null, msg, "警告",JOptionPane.WARNING_MESSAGE);
}//Endif
}
/**=======================================================================**
* [## public void setMenuLocation(int x, int y) {} ]:
* 参数 :int x 表示菜单的横向坐标,int y 表示菜单的纵向坐标
* 返回值:无
* 修饰符:public
* 功能 :设置菜单的坐标(在初始化菜单后加入组件之前使用)
**=======================================================================**
*/
public void setMenuLocation(int x, int y) {
if(panelconut == 0) {
sm_X = x;
sm_Y = y;
}else {
String msg = "setMenuLocation()方法请在加入组件之前使用。";
JOptionPane.showMessageDialog(null, msg, "警告",JOptionPane.WARNING_MESSAGE);
}//Endif
}
/**=======================================================================**
* [## public void setTitleHeight(int h) {} ]:
* 参数 :int h 表示按键模板的标题键的高度
* 返回值:无
* 修饰符:public
* 功能 :设置模板标题按键高度(当标题按键有背景图标时才使用本方法)
**=======================================================================**
*/
public void setTitleHeight(int h) {
titleHeight = h;
}
/**=======================================================================**
* [## public void setButtonPanelBackground(Color bg) {} ]:
* 参数 :Color 对象表示按键模板的背景颜色
* 返回值:无
* 修饰符:public
* 功能 :设置按键模板背景颜色(在初始化菜单后加入组件之后使用)
**=======================================================================**
*/
public void setButtonPanelBackground(Color bg) {
if(panelconut > 0) {
for (int i = 0; i < panelconut; i++) {
((JPanel)buttonPanels.get(i)).setBackground(bg);
}//Endfor
}else {
String msg = "setButtonPanelBackground()方法请在加入组件之后使用。";
JOptionPane.showMessageDialog(null, msg, "警告",JOptionPane.WARNING_MESSAGE);
}//Endif
}
/**=======================================================================**
* [## public String getSelectButtonName() {} ]:
* 参数 :无
* 返回值:String 对象表示触发事件的功能按键的名字
* 修饰符:public
* 功能 :获得选中的按键名
**=======================================================================**
*/
public String getSelectButtonName() {
return selectButtonName;
}
/**=======================================================================**
* [## private void slither(int index) {} ]:
* 参数 :无
* 返回值:无
* 修饰符:private
* 功能 :处理菜单滑动效果
**=======================================================================**
*/
private void slither(int index) {
//获得其它标题的高度总和
int sp_h = slitherMenuBar_Height - titleHeight * (panelconut - 1);
if(index == selectPanelNumber) { //如果是当前面板,则不处理
return;
}else if(index > selectPanelNumber) { //菜单上移动作
int sp_y = titleHeight * (selectPanelNumber + 1);
for (int i = sp_h; i >= titleHeight; i --) {
//当前展开面板缩起
((JPanel)template.get(selectPanelNumber)).setSize(slitherMenuBar_Width, i);
//处理当前展开面板与将要展开面板之间的标题
for (int j = selectPanelNumber + 1; j < index; j++) {
int other_Y = ((JPanel)template.get(j)).getY() - 1;
((JPanel)template.get(j)).setLocation(sm_X, other_Y);
}//Endfor
//新面板展开
int index_Y = ((JPanel)template.get(index)).getY() - 1;
int index_H = ((JPanel)template.get(index)).getHeight() + 1;
((JPanel)template.get(index)).setBounds(sm_X, index_Y, slitherMenuBar_Width, index_H);
}//Endfor
}else if(index < selectPanelNumber) { //下移动作
int sp_y = titleHeight * (selectPanelNumber - 2);
for (int i = sp_h; i >= titleHeight; i --) {
//当前展开面板缩起
int spy = ((JPanel)template.get(selectPanelNumber)).getY() + 1;
((JPanel)template.get(selectPanelNumber)).setBounds(sm_X, spy, slitherMenuBar_Width, i);
//处理当前展开面板与将要展开面板之间的标题
for (int j = selectPanelNumber - 1; j > index; j--) {
int other_Y = ((JPanel)template.get(j)).getY() + 1;
((JPanel)template.get(j)).setLocation(sm_X, other_Y);
}//Endfor
//新面板展开
int index_H = ((JPanel)template.get(index)).getHeight() + 1;
((JPanel)template.get(index)).setSize(slitherMenuBar_Width, index_H);
}//Endfor
}//Endif
this.validate(); //确定当前面板变化
}
/**=======================================================================**
* ActionListener 监听
**=======================================================================**
*/
public void actionPerformed ( ActionEvent ae ) {
//获得触发事件的按键Name
selectButtonName = ((JButton)ae.getSource()).getName();
if(selectButtonName != null) { //不为空则选择的就是标题按键
//获得被选中模板的序号
selectPanelNumberNew = Integer.parseInt(selectButtonName);
//处理菜单滑动效果
slither(selectPanelNumberNew);
selectPanelNumber = selectPanelNumberNew;
}
else {
//获得功能按键的名字
selectButtonName = ((JButton)ae.getSource()).getText();
}//Endif
}
}
TestSlitherMenu.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class TestSlitherMenu
extends JFrame
implements ActionListener, MouseListener {
JTextField tf;
JButton bt;
SlitherMenu sm1, sm2, sm3;
JPanel panelMain, panelMenu;
public TestSlitherMenu() {
tf = new JTextField("这里是防QQ的滑动菜单的演示程序");
bt = new JButton("顾俊在这里祝鲜强将来成为:yue han ka ma ke *^_^* ");
panelMain = new JPanel(new BorderLayout(20, 20));
panelMenu = new JPanel(new GridLayout(1, 3));
sm1 = new SlitherMenu();
sm2 = new SlitherMenu();
sm3 = new SlitherMenu();
//第一个菜单////////////////////////////////
sm1.setMenuLocation(30,10); //设置坐标
sm1.setMenuDimension(160, 400); //设置大小
sm1.addPanel("I第一个按键模板", "", 0 , 5);
sm1.addButton("pic/s01.gif", "第1-1个功能键", "第一个提示", 0);
sm1.addButton("pic/s02.gif", "第1-2个功能键", "第二个提示", 0);
sm1.addButton("pic/s03.gif", "第1-3个功能键", "第三个提示", 0);
sm1.addButton("pic/s04.gif", "第1-4个功能键", "第四个提示", 0);
sm1.addButton("pic/s05.gif", "第1-5个功能键", "第五个提示", 0);
sm1.addPanel("I第二个按键模板", "", 1 , 4);
sm1.addButton("pic/s06.gif", "第2-1个功能键", "第2-1个提示", 1);
sm1.addButton("pic/s07.gif", "第2-2个功能键", "第2-2个提示", 1);
sm1.addPanel("I第三个按键模板", "", 2 , 5);
sm1.addButton("pic/s08.gif", "第3-1个功能键", "第3-1个提示", 2);
sm1.addButton("pic/s09.gif", "第3-2个功能键", "第3-2个提示", 2);
sm1.addButton("pic/s10.gif", "第3-3个功能键", "第3-3个提示", 2);
sm1.addPanel("I第五个按键模板", "", 3 , 5);
sm1.addButton("pic/s11.gif", "第4-1个功能键", "第4-1个提示", 3);
sm1.addPanel("I没有第四个模板", "", 4 , 5);
sm1.addButton("pic/s12.gif", "第5-1个功能键", "第5-1个提示", 4);
sm1.addButton("pic/s13.gif", "第5-2个功能键", "第5-2个提示", 4);
sm1.addButton("pic/s14.gif", "第5-3个功能键", "第5-3个提示", 4);
sm1.addButton("pic/s15.gif", "第5-4个功能键", "第5-4个提示", 4);
sm1.addPanel("I哈哈", "", 5 , 5);
sm1.addButton("pic/s16.gif", "什么也没有", "指我干嘛?", 5);
sm1.setButtonPanelBackground(new Color(184, 207, 229));
//第二个菜单////////////////////////////////
sm2.setMenuLocation(40,10); //设置坐标
sm2.setMenuDimension(128, 400); //设置大小
sm2.setTitleHeight(35);
sm2.addPanel("II第一个按键模板", "pic/titlebar021.gif", 0 , 5);
sm2.addButton("pic/s01.gif", "第A-1个功能键", "第一个提示", 0);
sm2.addButton("pic/s02.gif", "第A-2个功能键", "第二个提示", 0);
sm2.addButton("pic/s03.gif", "第A-3个功能键", "第三个提示", 0);
sm2.addPanel("II第二个按键模板", "pic/titlebar021.gif", 1 , 4);
sm2.addButton("pic/s04.gif", "第B-1个功能键", "第2-1个提示", 1);
sm2.addButton("pic/s05.gif", "第B-2个功能键", "第2-2个提示", 1);
sm2.addButton("pic/s06.gif", "第B-3个功能键", "第2-3个提示", 1);
sm2.addButton("pic/s07.gif", "第B-4个功能键", "第2-4个提示", 1);
sm2.addPanel("II第三个按键模板", "pic/titlebar021.gif", 2 , 5);
sm2.addButton("pic/s08.gif", "第C-1个功能键", "第3-1个提示", 2);
sm2.addButton("pic/s09.gif", "第C-2个功能键", "第3-2个提示", 2);
sm2.addButton("pic/s10.gif", "第C-3个功能键", "第3-3个提示", 2);
sm2.addPanel("II哈哈", "pic/titlebar021.gif", 3 , 6);
sm2.addButton("pic/s11.gif", "第D-1个功能键", "第4-1个提示", 3);
sm2.addButton("pic/s12.gif", "第D-1个功能键", "第5-1个提示", 3);
sm2.addButton("pic/s13.gif", "第D-2个功能键", "第5-2个提示", 3);
sm2.addButton("pic/s14.gif", "第D-3个功能键", "第5-3个提示", 3);
sm2.addButton("pic/s15.gif", "第D-4个功能键", "第5-4个提示", 3);
sm2.addButton("pic/s16.gif", "D什么也没有", "指我干嘛?", 3);
sm2.setButtonPanelBackground(new Color(222, 210, 252));
//第三个菜单////////////////////////////////
sm3.setMenuLocation(30,10); //设置坐标
sm3.setMenuDimension(123, 400); //设置大小
sm3.setTitleHeight(32);
sm3.addPanel("III第一个按键模板", "pic/title.gif", 0 , 5);
sm3.addButton("pic/s01.gif", "第A-1个功能键", "第一个提示", 0);
sm3.addButton("pic/s02.gif", "第A-2个功能键", "第二个提示", 0);
sm3.addButton("pic/s03.gif", "第A-3个功能键", "第三个提示", 0);
sm3.addPanel("III第二个按键模板", "pic/title.gif", 1 , 4);
sm3.addButton("pic/s04.gif", "第B-1个功能键", "第2-1个提示", 1);
sm3.addButton("pic/s05.gif", "第B-2个功能键", "第2-2个提示", 1);
sm3.addButton("pic/s06.gif", "第B-3个功能键", "第2-3个提示", 1);
sm3.addButton("pic/s07.gif", "第B-4个功能键", "第2-4个提示", 1);
sm3.addPanel("III第三个按键模板", "pic/title.gif", 2 , 5);
sm3.addButton("pic/s08.gif", "第C-1个功能键", "第3-1个提示", 2);
sm3.addButton("pic/s09.gif", "第C-2个功能键", "第3-2个提示", 2);
sm3.addButton("pic/s10.gif", "第C-3个功能键", "第3-3个提示", 2);
sm3.addPanel("III第五个按键模板", "pic/title.gif", 3 , 5);
sm3.addButton("pic/s11.gif", "第D-1个功能键", "第4-1个提示", 3);
sm3.addPanel("III没有第四个模板", "pic/title.gif", 4 , 5);
sm3.addButton("pic/s12.gif", "第D-1个功能键", "第5-1个提示", 4);
sm3.addButton("pic/s13.gif", "第D-2个功能键", "第5-2个提示", 4);
sm3.addButton("pic/s14.gif", "第D-3个功能键", "第5-3个提示", 4);
sm3.addButton("pic/s15.gif", "第D-4个功能键", "第5-4个提示", 4);
sm3.addPanel("III哈哈", "pic/title.gif", 5 , 5);
sm3.addButton("pic/s16.gif", "E什么也没有", "指我干嘛?", 5);
sm3.setButtonPanelBackground(Color.WHITE);
////////////////////////////////////
sm1.initButtonPanelDimension();
sm2.initButtonPanelDimension();
sm3.initButtonPanelDimension();
sm1.addMouseListener(this);
sm2.addMouseListener(this);
sm3.addMouseListener(this);
bt.addActionListener(this);
panelMenu.add(sm1);
panelMenu.add(sm2);
panelMenu.add(sm3);
panelMain.add("North", tf);
panelMain.add("South", bt);
panelMain.add("Center", panelMenu);
tf.setHorizontalAlignment( JTextField.CENTER );
tf.setEditable(false);
this.setContentPane(panelMain);
this.setBounds(100, 50, 650, 600);
this.setVisible(true);
sm1.setInitMenu();
sm2.setInitMenu();
sm3.setInitMenu();
}
public void actionPerformed (ActionEvent ae) {
System.out.println (":)" + sm1.getSelectButtonName());
}
/**=======================================================================**
* MouseListener 监听
**=======================================================================**
*/
public void mouseClicked (MouseEvent me) {
Object o = me.getSource();
// if(o == sm1) {
System.out.println (sm1.getSelectButtonName());
// }
if(o == sm2) {
System.out.println (sm2.getSelectButtonName());
}
if(o == sm3) {
System.out.println (sm3.getSelectButtonName());
}
}
public void mousePressed (MouseEvent me) {
}
public void mouseReleased(MouseEvent me) {
}
public void mouseEntered (MouseEvent me) {
}
public void mouseExited (MouseEvent me) {
}
public static void main (String sd[]) {
new TestSlitherMenu();
}
}