显示标签为“java”的博文。显示所有博文
显示标签为“java”的博文。显示所有博文

2006年12月26日星期二

java6的启动界面

Splash screens are a standard part of any modern graphical user interface (GUI) application. Their primary purpose is to let the user know that the application is starting up. An application that displays a polished and professional-looking splash screen can occupy the user's attention and gain the user's confidence that the application is starting. In addition, splash screens may provide marketing information. And they are sometimes required for legal reasons: to present copyright information, third-party logos, and so forth.

You can use Java Foundation Classes/Swing (JFC/Swing) or AWT to create splash screens in Java technology applications. However, because the main purpose of a splash screen is to provide the user with feedback about the application's startup, the delay between the application's startup and the moment when the splash screen pops up should be minimal. Before the splash screen can pop up, the application has to load and initialize the JVM*, AWT, usually Swing, and perhaps some application-dependent libraries. The resulting delay of several seconds has made use of a Java technology-based splash screen less than desirable. Until now.

Java Platform, Standard Edition (Java SE, formerly known as J2SE) version 6, provides a solution that allows the application to show the splash screen much earlier, even before the virtual machine starts. Now, a Java application launcher is able to decode an image and display it in a simple nondecorated window (see Figure 1).

Note: To run the code in this article, you must download and install Java SE 6.

Use of an option in the manifest file can allow a JAR-packaged application to display a splash screen. Other types of applications can use a command-line option. You can use a desktop shortcut or a script to provide the command-line option to the Java application launcher. The splash screen can display any GIF, PNG, or JPEG image, with transparency, translucency, and animation.

There are two ways to show the native splash screen:

  • If your application is run from the command line or from a shortcut, use the -splash: Java application launcher option to show a splash screen:

      java -splash:filename.gif SplashTest

  • If your application is packaged in a JAR file, you can use the SplashScreen-Image option in a manifest file to show a splash screen. Place the image in the JAR archive and specify the path in the option. For example, use this code in the manifest.mf file:

         Manifest-Version: 1.0
    Main-Class: SplashTest
    SplashScreen-Image: filename.gif

    The command-line interface has precedence over the manifest setting.

The feature is extremely easy to use. In most cases, all you need to do is provide the image and use a launcher option. The splash screen will close automatically when the first AWT or Swing window is displayed.

In certain cases, you might want to provide some additional dynamic information in the splash screen. The SplashScreen class may be used to close the splash screen, change the splash-screen image, get the image position or size, and paint in the splash screen. The class cannot be used to create the splash screen. You should use the command-line or manifest-file option for that.

In addition, this class cannot be instantiated. Only a single instance of this class can exist, and it may be obtained using the getSplashScreen() static method. If the application has not created the splash screen at startup through the command-line or manifest-file option, the getSplashScreen method returns null.

Typically, you want to keep the splash-screen image on the screen and display something over the image, such as a progress indicator. The splash-screen window has an overlay surface with an alpha channel, and you can access this surface with a traditional Graphics or Graphics2D interface.

The following code sample demonstrates how you first obtain the SplashScreen object, then obtain a graphic handle with the getGraphics() method. Next, obtain the size of the splash screen, and clear the image if you already have drawn anything there. Set an AlphaComposite.Clear composite mode, and paint a rectangle over the whole splash screen. Restore the painting mode and paint whatever you want. Lastly, call the update() method to display what you have drawn.

SplashScreen splash = SplashScreen.getSplashScreen();
Graphics2D g = (Graphics2D)splash.getGraphics();
Dimension size = splash.getDimension();
g.setComposite(AlphaComposite.Clear);
g.fillRect(0, 0, size.width, size.height);
g.setPaintMode();

Also, you might want to replace the splash screen with an AWT or Swing window:

SplashScreen splash = SplashScreen.getSplashScreen();
// Obtain the splash-screen bounds.
Rectangle splashBounds = splash.getBounds();

Now show your new hand-coded splash-screen window at exactly the same location as specified in splashBounds. The original splash screen closes automatically.

You may change the image in the splash screen with the setImageURL method. If the user wants to close the splash screen before the first AWT or Swing window is displayed (or in the rare case that AWT or Swing is not used for the application GUI), this may be done with the SplashScreen.close method.

The following application is an example of how the new splash screen works.

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

public class SplashTest extends Frame implements ActionListener {
static void renderSplashFrame(Graphics2D g, int frame) {
final String[] comps = {"foo", "bar", "baz"};
g.setComposite(AlphaComposite.Clear);
g.fillRect(130,250,280,40);
g.setPaintMode();
g.setColor(Color.BLACK);
g.drawString("Loading "+comps[(frame/5)%3]+"...", 130, 260);
g.fillRect(130,270,(frame*10)%280,20);
}
public SplashTest() {
super("SplashScreen demo");
setSize(500, 300);
setLayout(new BorderLayout());
Menu m1 = new Menu("File");
MenuItem mi1 = new MenuItem("Exit");
m1.add(mi1);
mi1.addActionListener(this);

MenuBar mb = new MenuBar();
setMenuBar(mb);
mb.add(m1);
final SplashScreen splash = SplashScreen.getSplashScreen();
if (splash == null) {
System.out.println("SplashScreen.getSplashScreen() returned null");
return;
}
Graphics2D g = (Graphics2D)splash.getGraphics();
if (g == null) {
System.out.println("g is null");
return;
}
for(int i=0; i<100; i++) {
renderSplashFrame(g, i);
splash.update();
try {
Thread.sleep(200);
}
catch(InterruptedException e) {
}
}
splash.close();
setVisible(true);
toFront();
}
public void actionPerformed(ActionEvent ae) {
System.exit(0);
}
public static void main (String args[]) {
SplashTest test = new SplashTest();
}
}

Note that getGraphics creates a graphics context (as a Graphics object) for the splash-screen overlay image, which allows you to draw over the splash screen. Rather than drawing on the main image, you draw instead on the image that is displayed over the main image, using alpha blending. Also note that drawing on the overlay image does not necessarily update the contents of the splash-screen window. You should call update() on the SplashScreen when you want the splash screen to be updated immediately.

2006年12月10日星期日

实现某个程序只可以打开一个的思路

反正使用任何一个特定的系统共有资源;
  • 往一个固定的位置写一个文件;
  • 打开一个固定的port;
  • 又或者每一次程序启动都必须给你发条短信,你回答Y才可以启动.
但只是思路,想一想,其实是第一个方法是最好的,derby也是这样实现的,如果用derby的emdeb模式,每次打开derby数据库,它都在数据库的目录下生成一个*.loc的文件.这样就是表示数据库已经被打开了.
第二种方法,打开一个固定的port,是比较容易实现,可是比较容易出问题,如果固定的port被占用了呢?
第三种,可能会比较烦一点.

2006年12月9日星期六

[转帖]如何才算掌握Java(J2SE篇)

时常看到一些人说掌握了Java,但是让他们用Java做一个实际的项目可能又困难重重,在这里,笔者根据自己的一点理解斗胆提出自己的一些对掌握Java这个说法的标准,当然对于新手,也可以提供一个需要学习哪些内容的参考。另外这个标准仅限于J2SE部分,J2EE部分的内容有时间再另说。

1、语法:必须比较熟悉,在写代码的时候IDE的编辑器对某一行报错应该能够根据报错信息知道是什么样的语法错误并且知道任何修正。

2、命令:必须熟悉JDK带的一些常用命令及其常用选项,命令至少需要熟悉:appletviewer、HtmlConverter、jar、java、javac、javadoc、javap、javaw、native2ascii、serialver,如果这些命令你没有全部使用过,那么你对java实际上还很不了解。

3、工具:必须至少熟练使用一种IDE的开发工具,例如Eclipse、Netbeans、JBuilder、Jdeveloper、IDEA、JCreator或者Workshop,包括进行工程管理、常用选项的设置、插件的安装配置以及进行调试。

4、API:Java的核心API是非常庞大的,但是有一些内容笔者认为是必须熟悉的,否则不可能熟练的运用Java,包括:

1)、java.lang包下的80%以上的类的功能的灵活运用。

2)、java.util包下的80%以上的类的灵活运用,特别是集合类体系、规则表达式、zip、以及时间、随机数、属性、资源和Timer。

3)、java.io包下的60%以上的类的使用,理解IO体系的基于管道模型的设计思路以及常用IO类的特性和使用场合。

4)、java.math包下的100%的内容。

5)、java.net包下的60%以上的内容,对各个类的功能比较熟悉。

6)、java.text包下的60%以上的内容,特别是各种格式化类。

7)、熟练运用JDBC。

8)、java.security包下40%以上的内容,如果对于安全没有接触的话根本就不可能掌握java。

9)、AWT的基本内容,包括各种组件事件、监听器、布局管理器、常用组件、打印。

10)、Swing的基本内容,和AWT的要求类似。

11)、XML处理,熟悉SAX、DOM以及JDOM的优缺点并且能够使用其中的一种完成XML的解析及内容处理。

5、测试:必须熟悉使用junit编写测试用例完成代码的自动测试。

6、管理:必须熟悉使用ant完成工程管理的常用任务,例如工程编译、生成javadoc、生成jar、版本控制、自动测试。

7、排错:应该可以根据异常信息比较快速的定位问题的原因和大致位置。

8、思想:必须掌握OOP的主要要求,这样使用Java开发的系统才能是真正的Java系统。

9、规范:编写的代码必须符合流行的编码规范,例如类名首字母大写,成员和方法名首字母小写,方法名的第一个单词一般是动词,包名全部小写等,这样程序的可读性才比较好。

2006年11月27日星期一

wonuy猪猪基本完成

呼.bogger又可以上了,不过不知道哪天又会撞墙.在那段bogger撞墙的日子,真的不知道去哪儿写blog好. 昨天,写给女朋友的开支管理swing版终于基本上完成功能了,不过还要继续完善,不过已经不想化太多时间搞了,毕竟要考试了. ok,现在把wonuly开支管理的架构mark下来先: 用到的包:
jdk1.6RC






2006年10月24日星期二

JFrame窗口风格跟win一样

在JFrame下,要想JFrame的风格跟用户当前的win主题一样,可以通过以下代码实现,在构造函数里插入

try {
UIManager.setLookAndFeel ("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
javax.swing.SwingUtilities.updateComponentTreeUI(this);
} catch(Exception e) {
e.printStackTrace();
}

2006年10月8日星期日

不禁又迷茫起来

真的,最近老不知道怎么搞的,会很容易就迷茫起来.大概大三了,想的事也会多起来吧.

昨天跟胡老师聊,聊到迷茫.他说,怕什么,你看师兄们,出路都不错吧,你可以跟他们比的.-_-希望老师说的是真的吧.

最近的一个项目,用jsp做一个租车系统,居然指定一个垃圾网站做模板,郁闷,真想不明白这个客户的审美,而且还要指定国庆前搞定,啊~~,大哥我还要上课啊...

大概是时候回去洗澡了.

一个有趣的项目,可以把TC2.0的代码移到gcc上

note:这个开源的程序叫TurboC,borland公司的叫Turbo C

把 Borland Turbo c 的源代码移植到GNU gcc

内容
      TurboC 的大概内容
      TurboC为何而生??
      其他方法(Alternate Approaches, 不知道是不是这样翻译)
      TurboC的特点与不足
      下载和安装TurboC 
      未来的计划
      为什么要用这么可爱的logo呢?

TurboC的大概内容

TurboC是一个可连接的库同时也是一大堆C语言的头文件,是为了更容易地在GNU gcc,也就是在类Unix系统上,编译那些用原来在Turbo C编译器编译的MS-DOS系统的C语言的源文件,概括如下:
         通过Turbo C的conio.x里的ncurses的实现
         通过Turbo C的graphics.h里的Xlib的实现
         一些其他的函数和为了方便的节省时间的特征
        一种克服了Turbo C和GUN gcc的整型数据类型差异的方法
但不管怎么说,这也不是一个完美的解决方案,但是你会发现它还是有用的.你可以在它相关的早期的发展阶段找到graphics.h的帮助.
TurboC遵于GNU的LGPL协议(Lesser General Public License).

TurboC为何而生??

我写过很多基于MS-DOS的用Borland公司的Turbo C 2.0编译器编译的程序.当由于爱好的原因,我想把其中一些代码以自由软件的形式存在,我便想到了把这些代码发布在GPL下,是MS-DOS的代码,慢慢的把它们转换成类Unix系统的代码.很明显,预先直接的去转换(MS-DOS--> *nix)是一件很耗时的工作.而且渐渐的,我遇到了困难,因为发布一个别人无法理解其源代码的的软件并不是一件好事.而我最喜欢的发布开源的频道fleshmeat不"吃"MS-DOS,因此它很文雅的拒绝了我的MS-DOS项目.
很显然,现在的需要是更底层的,然后我就想到了我可以提供合适兼容的Turbo C的库和头文件,这样,把Turbo C的源码引到类Unix系统就会简单得多.也就是说,提供旧版本的MS-DOS的类Unix版本是一件相对容易很多的事情.但究竟这个容易去到哪儿,跟你要引进的程序的很多东西都有关.

其他方法(Alternate Approaches, 不知道是不是这样翻译)

对于conio.h的功能,你可以考虑使用pablo Vidal的UConio的库来代替.但是我没有使用过,所以无法说出其好长与不足,不过它肯定提供比TurboC提供一个少得多的Conio的功能的子集.而且它也会要求你更大范围的修改你的源代码.
Borland公司已经有了(或许会提供)一个Linux版本的C++编译器,这样的话,它的nature,价格和这个编译器的目标工作平台将是一个谜.一种假设(象Kylix)就是它将基于wine的,所以它只可以工作在x86的系统上面.但是,如果它包括了在TurboC上实现的库,那样,老实说,他提供了一种更简单的的方法来把你Turbo C的源代码引入到Linux上,但如果这样的话,它将会是非常庞大的.对我自己来说,尽管已经是一个很久的borland公司的用户了,但我还是非常希望用GNU gcc来编译我的程序.
对于graphics.h的功能,有一个Csaba Biegl, Michael Goffioul, and Hartmut Schirmer的GRX库.直到graphics.h的功能还有一点还没写完的时候,我才发现了这个库,因此我还没来得及很充分的测试它.它的目标是要成为一个多平台的2D图像库.它的官网没有宣传(甚至没有提到)与Turbo C的兼容性.然而,它只包括了非常少量的与Turbo C同名(当然还有相同功能)的功能.
当然,如果你只是感兴趣在类Unix系统上运行你的程序,同时也反对把其他程序引到类Unix系统上,那你也可以在linux版本的DOS emulators 下运行你已经存在的程序.DOS emulation使用了 dosemu 和 freedos ,在x86系统上工作得非常好,同时 bochs 和 freedos在非x86类Unix系统上工作的也不错(但可能有点慢).

TurboC的特点与不足

特点
   TurboC 提供了Turbo C的conio.h头文件控制台的大部分功能,与相关的ncurses的功能一一对应.(当然,除了scanf之外的conio.h的功能都有提供)
   TurboC提供了Turbo C的graphics.h头文件"BGI"的大部分功能.到目前为止(2002 06 08),除了临时缺乏stroked-font的支持,这些特点的实现已经完成的很彻底了.
   TurboC提供了这些丢失的功能诸如strupr和strlwr的功能的很少的东西,
   请确认可提供的方法的完整列表:

不足
   请参考bugs和issues的完整列表.到目前为止,这个库文件只是我在特定的我写的Turbo C的程序所需要的那么完整,随着我引入的我以前的程序到类Unix               系统的多起来,TurboC的库大概才会愈来愈完整.到目前为止,本质上conio.h的支持已经完整了,除了显示文本外,graphics.h的支持也本质上完整了.
   在已经引进的程序里,除非你使用了xterm,要不然文本控制台的窗口指挥逻辑上自动调好尺寸,并不会physically地去调整.如果你用了诸如KDE控制台之类的其他控制台,用户必须人为地去调整了.
   Borland的Turbo C是16位的编译器,但是我目标的GNU gcc编译器是32位的,结果产生了整型的数据类型的差异.TurboC用宏的方法处理了(但愿)更普遍的情况.没有处理的情况会在编译的时候报错,用户必须手动去修改.在用户的页面会被详细介绍.
   用基于诸如 getcha, cprintf或其他的控制台来混合基于流的功能(如 getchar, printf,其他),很可能会不工作.你也可以浏览usage page.

下载并安装TurboC
    下载源代码
      *Most-current development code (20040218) TurboC-dev.tar.gz
      20020602 snapshot TurboC-20020602.tar.gz
      20020419 snapshot TurboC-20020419.tar.gz
      20020418 snapshot TurboC-20020418.tar.gz
      20020323 snapshot TurboC-20020323.tar.gz
      20020317 snapshot TurboC-20020317.tar.gz
      20020312 snapshot TurboC-20020312.tar.gz

tarball里包括了一个教TurboC-source的文件夹,你可以简单的在这个目录下用make来编译库.但必须是GNU gcc或者用gmake(例如在FreeBSD或Mac下)来编译(提示,在FreeGSD下,你要编辑makefile和注释/反注释开头的若干行,你会很容易看到的),我已经检验了最近释出的snapshot(不是开发者的snapshot)并在以下系统测试了程序:
  Linux Intel 'x86 (SuSE 8.0)
  Linux PowerPC (SuSE 7.3)
  FreeBSD (4.5)
(早期的TurboC的库好像在FreeBSD上工作的效果不怎么好,请升级到20020420的版本,并且在运行引入的程序的时候按照下面的步骤).最近释出的snapshot只在SuSE8.2上测试过.
把这个库(libTurboC.a and libTurboCu.a)放在你系统放库的地方--通常在 /usr/lib.把所有的头文件放到它应该放的地方--通常是 /usr/include.又或者,你也可以添加它们的链接到这些目录.又或者,把它们放到你喜欢的地方,然后在gcc里用参数 -L和-I来连接它们.
在我的系统,我是这么做的.
  cd ~
  tar -xzvf TurboC-dev.tar.gz
  cd TurboC-source
  ... 编辑FreeBSD的makefile ...
  make (or gmake)
  su
  ln -s *.h /usr/include
  ln -s libTurboC.a /usr/lib
  exit
你会发现(例如,在FreeBSD)如果你在你引入的程序力#include了TurboC的头文件,你的编译器会报错:标识符链接太深(symbolic links being "too deep").如果是这样的话,你可以把上边的ln命令的参数"-s"去掉.
另外,编译Makefile当然会假定X-window系统的头文件和库;如果这个假定是错的话,你就要你的编译器加上参数"-L"和/或者"-I"来调整.X-window系统必须编译全部的库,或者你要运行你的程序,如果你要用到graphics.h的功能.如果你不打算使用这些功能,你可以通过编辑Makefile和去掉编译器参数的"-DWITH_X"在没有X的系统上引入和编译你的程序.

未来的计划

嗯,很明显这种项目是没什么前途的,它的计划只不过是从一个古老的编译器里引入它的代码.然而,我还是会在我这个项目里根据需要增加一些特性的.我不会浪费精力去写一些没有在我Turbo C程序力出现过的功能的,但如果你自己已经写了而又告诉了我,我是很乐意加进去的(把荣辱加给你).
当然,很希望你能把TurboC的bug返回给我,(当然在这之前,去看看Buglist有没有这个问题),我会尽力去改正它们的.

为什么要用这么可爱的logo呢?

这是一幅姐妹在谈话的图片,画家Lynn Rothan的杰作.我试图表达的意思是,它表现了很相似的c编译器 Borland Turbo C和GUN gcc的关系.当然拉,lynn有他自己的意思.请参考他的网站.

一个java打包工具JET的介绍

   Exceclsior JET for windows
    v4.5     
* 大致浏览

 -JET 优化
 -JET 运行
 -安装工具包
*系统需求

*快速开始

*界面工具

 -Excelsior JET Launcher
 -JET 控制面板
 -jetPackII
 -JET 安装
 -开发者资源

*大概
  Excelsior JET 是一套完全为了优化运行的工具包,是用java编程语言写的可配置和可运行的程序.
  Excelsior JET 产品包括了 JET优化程序,是一个完全的 java SE 5.0 的运行和安装程序工具包.
  JET 优化程序能够将你的 class格式或者jar格式的文件转化成 开发者的x86(IA-32)的机器码.这样,
您就能够得到windows或者Linux的运行效果极好的原生代码.
  另外,产生的原生代码具有高度的反编译和反修改能力.
  JET运行程序包括了sun公司的java2 API的许可并同时提供了所有java的特性,例如垃圾回收机制(garbage colletion).
  JET 优化程序和运行程序保证在java标准版本5.0(j2sdk 5.0)下正常运行.
  如果你想要把你的应用程序分发给一定数量的用户,你可以使用安装工具包来准备一个包括已经优化过的程序和一个JET Excelsior的运行引擎.您的客户就可以简单地安装这个包就可以开始使用您的程序.一些多余的软件的安装,例如JRE,不是最终客户的系统的必须.

  JET 优化程序
  ------------
  JET优化程序会在程序开始运行之前把java的.class文件和.jar文件转换成开发者系统的高效的本地代码,直接运行在硬件上.
  优化程序使用了很多很普遍使用在传统C/C++和FORTRAN编译器里的优化技巧.为了解决java的执行效率问题,JET优化程序是注入使用了内嵌虚拟方法,安全可移除普遍存在的同步和栈里分配对象的优雅的(state-of-the art)优化来做出来的.

  你可以在JET的控制面板上来用优化程序,一个图形界面的向导的,为了你更快地建立您的项目文件和转换你的程序为高效的可执行程序(请参考下面"图形界面工具"的环节)

  JET运行时间(runtime不知道是不是这样翻译)
  --------------------------------------
  JET运行环境是一个彻底的java虚拟机.但有一点特别,它包括了一个即时编译器(JIT)来装载和运行标准的java字节码文件.和其他虚拟机的关键的分别是JET运行环境可以同时工作在java的字节码文件和JET优化程序产生的原生文件.例如,一个JET编译的程序(.exe)可以装载以.jar形式的文件为java插件程序.

  如果你使用的程序是使用插件的,装载它们回耗费一些时间.为了减少这些时间,你可以在JET运行时间里打开你的JIT缓存.这样一来,用JIT编译器产生的原生代码就会保留在JIT的缓存力并会在后来的程序启动时重新使用.欲知详情,请参考JET用户指南的"混合编译模块"("mixed compilation model").

  包装程序包
  ---------

  为了提供快速的包装程序,Excelsior JET包括了包装程序(JetPackII),也是一个图形向导.通过它,你可以准备一个包括你的优化的java程序和一个JET的运行时间.

  基本的部署程序都是尽量简单的.这个产生的包,例如,一个本身包括了目录,能复制到目标系统.一个在没有解压环境都能点击就运行的系统.你可以简单的整合这些包为任何一个安装程序(NSIS和InstallShield或其他).

  包装程序能直接产生一个自解压的安装程序.也就是说,用它产生的安装程序,既可以是无人值的安装,也可以是GUI界面的安装.

  在GUI模式下,安装程序会通过安装过程处理允许用户来指定诸如目文件夹,快捷键,开始菜单等等的安装设置.你也可以把安装界面设置成一个飞出的窗口,用户协议和把安装程序显示为英语,德语,法语,俄罗斯语或者日本语,看你的喜好和系统的当地设置.欲知详情,请参考JET用户指南的"开发自动设置"("Deployment automation" ).

  请把你的回执提交到java@excelsior-usa.com.

系统要求
    操作系统:
        windows版本的Excelsior JET 4.5已经在以下系统通过了JCK(Java SE compliance)的测试:
                     Windows 2000 Professional,
                     Windows 2000 Server,
                     Windows 2003 Server,
                     Windows XP Professional

    CPU:             Intel Pentium III或800MHZ同等级或更高

    内存:            384或以上

    硬盘空间:        420MB以上

------------------------------------------------------------------------------------------
详细清单在以下网址:

http://www.excelsior-usa.com/jetsysreq.html

www.myjavaserver.com的注册

免费的jsp空间,www.myjavaserver.com的觉得不错,但注册的时候,有个小测试,难度倒不大,不过是E文的,原文如下:

As the principal engineer of an HTTP web server, you are responsible for implementing the request processing subsystem of the server. An incoming request for a specific resource, identified by an URI, must be dispatched to the appropriate handler according to the server configuration which maps URIs to request handlers. 'HandlerFactory.getHandler' must be implemented: public class HandlerFactory { public String getHandler(String[] config, String requestUri) { } } The string array 'config' contains URI patterns and handler names. Two consecutive values form a key-value pair comprised of URI pattern and handler. 'requestUri' represents an incoming request, the URI to match against the configured handlers. 'getHandler' must return the correct handler for a given URI as a string value. An URI pattern never contains wildcards and represents the start of an URI string, a prefix. Matching must be implemented accordingly. The handler with the longest matching URI pattern wins if more than one pattern matches. If no handler can be found, "264wK8R" must be returned. Example input: String[] config: { "/", "MainServlet", "/nav", "NavigationServlet" } String requestUri: "/nav/test" Correct result: "NavigationServlet" In this example, the configuration contains a mapping of "/" to "MainServlet" and "/nav" to "NavigationServlet". In the case of an incoming URI "/nav/test.nav", "NavigationServlet" is the correct choice because its pattern is longer than that of "MainServlet".

具体实现如下:

public String getHandler(String[] config, String requestUri) {
       String ret = "Ey1Der6" ;
       boolean found = false ;
       for (int i = 0 ; i < config.length ; i += 2){
      if (requestUri.indexOf(config[i]) == 0){
        if (!found){
       ret = config[i+1] ;
      found = true ;
     } else {
     if (ret.length() < config[i+1].length())
     ret = config[i+1] ;
}
}
}
return ret ;
}

哀掉的netbeans

一气之下,把netbeans删掉了.

sun网站上,说使用netbeans可以有机会被抽一个ipod,n久前就下了个netbeans,终于上一个项目,是用netbeans做的application, 但感觉不爽.缘由如下:

1.启动速度慢,经过对比,netbeans5.0确实比jb2006/jb2005/eclipse3.1 在win32下慢,而且在 ubuntu下也比 eclipse 慢.

2.生成的GUI代码不可修改?!!!!妈的,@#$%^&*,我用netbeans拖个JTable,行数不可动态修改..... 用jb不会,用eclipse也不会..

3.居然不集成打包工具,最后还是要投向jb或者eclipse打包.天啊,那我用netbeans干嘛啊?.

4.字体不可修改.在我的机器上,字体显示正常,不过在师兄的机器上,字体丑的不得了,他在他同学那儿,效果一样,最可恶的是修改不了??郁闷ing,傻愣着看着难以入目的字体,做了一个项目(哈哈,不是我,我还好)..

5.反应慢,我在想,是不是netbeans采用swing,而eclipse采用swt的缘故呢?譬如,我在netbeans了输入一行代码,开始提示我缺了分号,嗯...似乎很好,可是我明明打了个分号下去了嘛,妈的@#$%^&*,偌大的红色波浪线还有那个偌大的红色叹号,还在那儿!!!!!!看着很不爽呢.谁愿意看着红色的叹号还按编译呢??

6...想到再说吧...反正这些理由已经可以支撑我删掉netbeans了

java读写配置文件

写程序的时候,发现程序编好后,怎么改里面的参数呢?只有靠配置文件了,听说过java里面有专门读写.property的类的,找了找资料,发现资料也少,不如换个形式吧。

随便找个文件,按照自己的格式,写上参数,然后在那个文件后加上.ini的后缀,哈哈,欺世盗名啊,哈哈,如此也做到了配置文件的作用啦~,读的时候,一行一行的读,就OK了..

不过既然sun写个.property的类,也就不要浪费,应该研究一下.

I COME BACK

嗯,终于回来了.

大二也快结束了.

想不到我可以帮大四的师兄做毕业设计....自己也郁闷起来.

刚才老师来说让我下个下个星期去动员师弟近研发中心,居然让我去,真想不懂,老师是不是觉得我吹水比较厉害呢?可能是吧,不管它了.去就去吧,威风啊,哈哈.

应该要写写blog了. backing.