java learnging

一块探讨JAVA的奥妙吧
posts - 34, comments - 27, trackbacks - 0, articles - 22

2005年8月17日

Version Eclipse 3.1

1.性能

    a. 禁用缓存远程资源
       Window -> Preferences -> Internet -> Cache -> 选择Disable Caching
       这样在打开web.xml等文件时就不会 Loading xmlns 之类的信息了
   
    b. 禁用有效性验证
       Window -> Preferences -> Validation -> 选择Deselect All
       可能有效性验证是个不错的功能,不过有时候需要花的时间太长,有点受不了,基本上也不怎么需要
    c. 禁用启动eclipse时自动构建
       Window -> Preferences -> Launching -> 不选择 Build before launching

2.个人嗜好

    a. 修改Ant Document Url
       Window -> Preferences -> Ant -> Document Url -> 选择Ant Document目录
       这样要比eclipse默认去apache的网站访问快多了
   
    b. 修改快捷键的设定
       Window -> Preferences -> General -> Keys -> 按自己的需要修改
       尤其是Content assist 这么一个好用的功能和我的输入法冲突了,只有改了

    c. 修改java文件的source和output folder
       Window -> Preferences -> Java -> Build Path ->选择 Folders,并设为src和classes
       这样的项目文件目录比较标准,不过和maven的标准不太一样哦

    d. 修改Mark Occerencs
       Window -> Preferences -> Java -> Editor -> Mark Occerencs -> 把Mark Occerencs置为disable
       这样在选择一个单词的时候,与这个单词“具有同样含义”的单词就不会同时加亮了

posted @ 2005-08-17 17:38 bigseal 阅读(1476) | 评论 (0)编辑 收藏

2005年8月15日

Eclipse 3.0/3.1

Subclipse releases for Eclipse 3.x are hosted at our update site. Add http://subclipse.tigris.org/update as an update site in Eclipse's update manager (which you can find in the Help menu).

The update site itself can be downloaded and used as a local update site as well. Simply unzip the site archive, and add the path as a new "Local Site" in the Eclipse update manager. You can also host your own internal Subclipse update site by placing the site on your own HTTP server (be sure to update site.xml appropriately).

We also provide instructions for installing Subclipse in Eclipse 3.x

Eclipse 2.1.3

Subclipse 0.9.3.3 is linked against Subversion 1.1.4. Binaries for Windows are included.

Development for this version of Eclipse is no longer active. There are no new releases planned.

Download the Eclipse 2.x version

Note:如果把文件直接unzip到eclipse的安装目下,在使用的时候会没有授权文件文件之类的错误。

posted @ 2005-08-15 12:38 bigseal 阅读(15272) | 评论 (0)编辑 收藏

2005年7月25日

修改默认字符集(default character set)
在mysql的my.ini配置文件中设置,这样在mysql启动后就会自动加载
例如:把默认字符集设置为UTF-8

default-character-set=utf8

查看变量值:
例如:查看字符集设置

SHOW VARIABLES LIKE 'character_set_%';
SHOW VARIABLES LIKE 
'collation_%'

设置变量值
例如:设置字符集变量
 set  character_set_server  = utf8;
 
set  character_set_system  = utf8;
 
set  character_set_database  = utf8;
 
set  character_set_client  = utf8;
 
set   character_set_connection  = utf8;
 
set  character_set_results = utf8;
 
 
set collation_connection = utf8_general_ci;
 
set collation_database = utf8_general_ci;
 
set  collation_server = utf8_general_ci;

posted @ 2005-07-25 17:38 bigseal 阅读(1425) | 评论 (0)编辑 收藏

2005年7月22日

java.util.*

java.util.StringTokenizer
作用: 根据标记分割字符串
例子:

StringTokenizer st = new StringTokenizer("this is a test");
     
while (st.hasMoreTokens()) {
         System.
out.println(st.nextToken());
     }
结果为:
     this
     is
     a
     test

但是该类已经不推荐使用了,如果要实现该功能可以通过String类的split方法或 java.util.regex package来代替。
     String[] result = "this is a test".split("\\s");
     
for (int x=0; x<result.length; x++)
         System.
out.println(result[x]);
结果为:
     this
     is
     a
     test

posted @ 2005-07-22 18:00 bigseal 阅读(1284) | 评论 (0)编辑 收藏

Container默认布局管理

Container       null
Panel             FlowLayout
Window        BorderLayout
Dialog           BorderLayout 
Frame           BorderLayout

有几个用于布局管理的类
BorderLayout
CardLayout
FlowLayout
GridLayout
GridBaglayout

BorderLayout水平扩展南北构件,使这些构件的宽度达到所在容器的宽度,但根据构件的首先高度调整它们的高度。东西构件被垂直扩展,并根据它们的首先宽度调整她们的宽度,中间构件布满剩下的空间。

在使用GridBaglayout管理布局时,需要通过GridBagConstraints来指定各构件的约束条件,下面是GridBagConstraints的一些设置
GridBagConstraints.anchor 构件在显示区中的位置
GridBagConstraints.fill         构件填充显示区的方式
GridBagConstraints.gridx/gridy  构件左上角的网格单元
GridBagConstraints.gridwidth/gridheigth 构件显示区的大小
GridBagConstraints.weighx/weighy 构件显示区可以消耗多少额外的空间
GridBagConstraints.insets 构件的空白区
GridBagConstraints.ipadx/ipady 构件的内部填充

posted @ 2005-07-22 17:50 bigseal 阅读(1606) | 评论 (0)编辑 收藏

2005年7月15日

The UML2 project is an EMF-based implementation of the UML 2.0 metamodel for the Eclipse platform designed to support the development of modeling tools. Further objectives of the UML2 project are to provide a common XMI schema to facilitate interchange of semantic models, test cases as a means of validating the specification, and validation rules as a means of defining and enforcing levels of compliance. For more details see Getting Started with UML2

posted @ 2005-07-15 14:06 bigseal 阅读(1471) | 评论 (0)编辑 收藏

2005年7月13日

    有两种方法要用到对Graphi的引用,这两种就是传递一个对Graphi的引用,或返回对Graphics的引用。

   1 .传递一个对Graphi的引用是诸如 void paint(Graphics g)的方法,通过override该方法来达到目的。

import java.awt.*;

public class SubPanel extends Panel{

    
public void paint(Graphics g){
        g.setColor(Color.RED);
        g.drawString(
"subPanel",5,5);
    }

}


2.返回对Graphics的引用是诸如 Graphiics getGraphics() 的方法,直接引用返回的Grapchics。

import java.awt.*;


import java.awt.
*;

public class SubPanel extends Panel {

    
public void test() {
        Graphics g 
= getGraphics();
        
if (g != null{
            g.setColor(Color.RED);
            g.drawString(
"subPanel"55);
        }

    }

}


其中,如果如果组件当前未显示getGraphics()方法返回null。

posted @ 2005-07-13 14:07 bigseal 阅读(1415) | 评论 (0)编辑 收藏

    AWT是JFC(Java基本类)的核心,为JFC的构成提供了以下的基本结构:

  • 代理事件模型
  • 轻量构件
  • 剪贴板和数据传输
  • 打印和无鼠标操作

    Java抽象窗口工具集有四个主要的类,即:构件类(Component)、容器类(Container)、图形类(Graphics)、和布局管理类(LayoutManager和LayoutMangager2)。容器包含构件,布局管理器确定容器内构件的位置和形状。图形(Graphics)类提供在构件中显示文本框和图形的方法。

1.强制一个容器布置它的构件

    在任何时间给定的构件都是有效(valid)或无效(invalid)的。无效的构件需要被布置,而有效的构件不需要。访问一个 无效容器(它的同位体已经产生)的validate()引起对容器layout()方法的调用。使构件无效的过程不仅使构件自己变得无效,而且也会使构件所在的容器变的无效。
使构件无效的Component和Container方法:
void Component.addNotify()
void Component.show() (invalidates parent container)
void Component.hide() (invalidates parent container)
void Component.reshap(int x,int y,int width,int height)
void Component.setSize(int width,int height)
void Component.setBounds(int x,int y,int width,int height)
void Component.setLayout(LayoutManager)
void Container.add(Component)
void Container.remove(Component)
void Container.removeAll(Component)
void Container.setLayout(LayoutManager)
因此我们可以把希望重新布置的构件设置为无效,然后调用该构件父容器的validate()方法即可。

posted @ 2005-07-13 14:04 bigseal 阅读(1342) | 评论 (0)编辑 收藏

Timer是一个线程用来调度在后台线程中运行的计划任务的使用工具。任务可能计划只运行一次,或者以一定的时间间隔重复运行。
下面是一个定时的小程序:

    /**
     * 弹出菜单显示3秒钟后自动隐藏
     * 
     
*/

    
private void timerToHidden() {
        Timer timer 
= new Timer();

        timer.schedule(
new TimerTask() {
            
public void run() {
                msgWindow.setVisible(
false);
            }

        }
3000);
    }

posted @ 2005-07-13 13:57 bigseal 阅读(1527) | 评论 (0)编辑 收藏

2005年7月8日

使用JDIC (Jdesktop Integration Components)类库做开发。
开发过程中遇到的问题:
  1. 主窗体最小化后隐藏
    当发生窗体最小化事件时把窗体隐藏就可以了
             /*
                 * 最小化窗体时把窗体给隐藏了 (非 Javadoc)
                 * @see java.awt.event.WindowListener#windowIconified(java.awt.event.WindowEvent)
                 
    */

                
    public void windowIconified(WindowEvent e){
                    e.getWindow().setVisible(
    false);
                }

  2. 单击系统托盘,显示程序主窗体
    单击系统托盘但时,把窗体置为可见,并把窗体从任务栏恢复
               // 单击系统托盘,显示程序主窗体
            tray_icon.addActionListener(new ActionListener() {
                
    public void actionPerformed(ActionEvent e) {
                    buddyFrame.setVisible(
    true);
                    buddyFrame.setState(JFrame.NORMAL);
                }

            }
    );

  3. 当有消息时在系统托盘图标旁显示一个消息提示
    (这是一个类似与MSN那种,而不是把鼠标放到托盘上显示的 ToolTip)
    当消息到来时在系统托盘图标旁显示一个弹出菜单即可
     
    public void promptMsg(String msg, String ticket, String url, String para,
                String userID) 
    {
            
    // 设置消息内容
            mViewMsg.setText(msg);

            
    // 设置url(点击 mViewMsg 菜单选项事件的监听程序)
            mViewMsg.addActionListener(new msgMenuActionListener(msgMenu, url + "?"
                    
    + para));

            
    // 设置菜单的大小和位置
            setMsgMenuSize();

            msgMenu.setVisible(
    true);
        }


        
    /**
         * 
         * 设置菜单的大小和位置
         
    */

        
    private void setMsgMenuSize() {
            Dimension menuSize 
    = new Dimension(200,150);
            msgMenu.setPopupSize(menuSize);
            
    int xMenu = tray_icon.getLocationOnScreen().x - menuSize.width + 50;
            
    int yMenu = tray_icon.getLocationOnScreen().y - menuSize.height;
            Point menuPoint 
    = new Point(xMenu, yMenu);
            msgMenu.setLocation(menuPoint);
            
        }

posted @ 2005-07-08 11:20 bigseal 阅读(2943) | 评论 (2)编辑 收藏