📄 jzipjar.java
字号:
package org.jr.jzj;
/**
* <p>Copyright: Copyright (c) 2002-2003</p>
* <p>Company: JavaResearch(http://www.javaresearch.org)</p>
* <p>最后更新日期:2003年2月15日
* @author Cherami,Barney,Brain
* @version 0.8
*/
import java.util.*;
import java.util.prefs.*;
import java.awt.event.*;
import javax.swing.*;
import org.jr.swing.util.*;
/**
* 系统的运行类,完成系统的最初的初始化和版本判断。
* <P>由于这个类是整个系统的入口,因此会完成很多初始化工作。
* <p>特别是由于本系统是针对JDK1.4设计的,因此需要对运行环境的JDK或者JRE进行判断。
*/
public class JZipJar {
private static JZJLogger logger;
public static Preferences preference;
private static MainFrame frame;
/**
* 系统入口,完成必须的初始化和JDK版本判断,一切正常的情况下运行系统
* @param args 命令行参数
*/
public static void main(String[] args) {
//判断JDK或者JRE的的版本的兼容性,不兼容时退出
if (!canRun()) {
System.exit(1);
}
//系统初始化
init();
//一切正常,加载主界面
frame = new MainFrame();
frame.setIconImage(new ImageIcon(MainFrame.class.getResource(ImageNames.
img_f_icon)).getImage()); //设置应用程序图标
frame.setSize(preference.getInt("mainframe_width", 640),
preference.getInt("mainframe_height", 480));
frame.setLocation(preference.getInt("mainframe_location_x", 0),
preference.getInt("mainframe_location_y", 0));
frame.show();
if (preference.getBoolean("mainframe_maximize", true)) {
frame.setExtendedState(JFrame.MAXIMIZED_BOTH); //设置为最大化模式
}
//是否自动打开文件打开对话框
if (preference.getBoolean("autoopen", false)) {
frame.open();
}
frame.addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
preference.putInt("mainframe_width", frame.getWidth());
preference.putInt("mainframe_height", frame.getHeight());
preference.putBoolean("mainframe_maximize", SwingUtil.isMaximized(frame));
}
public void componentMoved(ComponentEvent e) {
preference.putInt("mainframe_location_x", frame.getLocationOnScreen().x);
preference.putInt("mainframe_location_y", frame.getLocationOnScreen().y);
}
}
);
}
/**
* 得到系统需要的全局的区域设置
* @return 全局的区域设置
*/
public static Locale getSystemLocale() {
Locale locale = Locale.getDefault();
//Locale locale=Locale.FRANCE;
//Locale locale=Locale.ENGLISH;
if (!locale.equals(Locale.getDefault())) {
Locale.setDefault(locale);
}
return locale;
}
/**
* 判断本程序能否运行。
* <P>现在的条件是JRE的版本必须足够并且没有另一个此程序在运行
* @return 满足所有条件时返回true,否则返回false
*/
private static boolean canRun() {
return isJREVersionCompatible();
}
/**
* 判断本程序能否在用户的JDK或者JRE环境下运行。
* <P>由于本程序是针对JDK1.4设计的,因此只有和JDK1.4兼容的环境下才能运行
* @return 用户的JDK或者JRE版本和JDK1.4兼容时返回true,否则返回false
*/
private static boolean isJREVersionCompatible() {
// 加载测试类
Class testClass = null;
try {
testClass = Class.forName("java.lang.Object");
}
catch (ClassNotFoundException e) {
System.err.println(e);
return false;
}
// 得到包的版本信息并检查兼容性
//由于日志功能也是1.4才推出的,因此在不兼容的时候向标准错误输出而不是日志
Package testPackage = testClass.getPackage();
if (testPackage == null) {
System.err.println("No version information");
System.err.println(
"Pls use JRE compatible with SUN JDK 1.4 or later to run this program");
return false;
}
else if (!testPackage.isCompatibleWith("1.4")) {
System.err.println("JDK Vendor:" + testPackage.getImplementationVendor() +
",JDK version:" + testPackage.getSpecificationVersion());
System.err.println(
"Pls use JRE compatible with SUN JDK 1.4 or later to run this program");
return false;
}
return true;
}
/**
* 判断用户是否已经打开了一个JZJ。
* @return 用户已经打开了一个时返回true,否则返回false
*/
private static boolean noExistedInstance() {
return preference.getBoolean("is_running", false);
}
/**
* 系统的初始化,完成系统所有的基本参数的加载工作。
*/
private static void init() {
preference = Preferences.userRoot().node("jzj");
JZJLogger.init(preference.get("log_file", "JZJlogs.log"),
preference.getInt("log_level", JZJLogger.ERROR),
preference.getBoolean("log_debug", true)); //初始化日志管理器
logger = new JZJLogger(JZipJar.class);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -