java learnging

          一塊探討JAVA的奧妙吧
          posts - 34, comments - 27, trackbacks - 0, articles - 22

          2005年7月8日

          Version Eclipse 3.1

          1.性能

              a. 禁用緩存遠(yuǎn)程資源
                 Window -> Preferences -> Internet -> Cache -> 選擇Disable Caching
                 這樣在打開(kāi)web.xml等文件時(shí)就不會(huì) Loading xmlns 之類的信息了
             
              b. 禁用有效性驗(yàn)證
                 Window -> Preferences -> Validation -> 選擇Deselect All
                 可能有效性驗(yàn)證是個(gè)不錯(cuò)的功能,不過(guò)有時(shí)候需要花的時(shí)間太長(zhǎng),有點(diǎn)受不了,基本上也不怎么需要
              c. 禁用啟動(dòng)eclipse時(shí)自動(dòng)構(gòu)建
                 Window -> Preferences -> Launching -> 不選擇 Build before launching

          2.個(gè)人嗜好

              a. 修改Ant Document Url
                 Window -> Preferences -> Ant -> Document Url -> 選擇Ant Document目錄
                 這樣要比eclipse默認(rèn)去apache的網(wǎng)站訪問(wèn)快多了
             
              b. 修改快捷鍵的設(shè)定
                 Window -> Preferences -> General -> Keys -> 按自己的需要修改
                 尤其是Content assist 這么一個(gè)好用的功能和我的輸入法沖突了,只有改了

              c. 修改java文件的source和output folder
                 Window -> Preferences -> Java -> Build Path ->選擇 Folders,并設(shè)為src和classes
                 這樣的項(xiàng)目文件目錄比較標(biāo)準(zhǔn),不過(guò)和maven的標(biāo)準(zhǔn)不太一樣哦

              d. 修改Mark Occerencs
                 Window -> Preferences -> Java -> Editor -> Mark Occerencs -> 把Mark Occerencs置為disable
                 這樣在選擇一個(gè)單詞的時(shí)候,與這個(gè)單詞“具有同樣含義”的單詞就不會(huì)同時(shí)加亮了

          posted @ 2005-08-17 17:38 bigseal 閱讀(1489) | 評(píng)論 (0)編輯 收藏

          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的安裝目下,在使用的時(shí)候會(huì)沒(méi)有授權(quán)文件文件之類的錯(cuò)誤。

          posted @ 2005-08-15 12:38 bigseal 閱讀(15296) | 評(píng)論 (0)編輯 收藏

          修改默認(rèn)字符集(default character set)
          在mysql的my.ini配置文件中設(shè)置,這樣在mysql啟動(dòng)后就會(huì)自動(dòng)加載
          例如:把默認(rèn)字符集設(shè)置為UTF-8

          default-character-set=utf8

          查看變量值:
          例如:查看字符集設(shè)置

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

          設(shè)置變量值
          例如:設(shè)置字符集變量
           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 閱讀(1436) | 評(píng)論 (0)編輯 收藏

          java.util.*

          java.util.StringTokenizer
          作用: 根據(jù)標(biāo)記分割字符串
          例子:

          StringTokenizer st = new StringTokenizer("this is a test");
               
          while (st.hasMoreTokens()) {
                   System.
          out.println(st.nextToken());
               }
          結(jié)果為:
               this
               is
               a
               test

          但是該類已經(jīng)不推薦使用了,如果要實(shí)現(xiàn)該功能可以通過(guò)String類的split方法或 java.util.regex package來(lái)代替。
               String[] result = "this is a test".split("\\s");
               
          for (int x=0; x<result.length; x++)
                   System.
          out.println(result[x]);
          結(jié)果為:
               this
               is
               a
               test

          posted @ 2005-07-22 18:00 bigseal 閱讀(1295) | 評(píng)論 (0)編輯 收藏

          Container默認(rèn)布局管理

          Container       null
          Panel             FlowLayout
          Window        BorderLayout
          Dialog           BorderLayout 
          Frame           BorderLayout

          有幾個(gè)用于布局管理的類
          BorderLayout
          CardLayout
          FlowLayout
          GridLayout
          GridBaglayout

          BorderLayout水平擴(kuò)展南北構(gòu)件,使這些構(gòu)件的寬度達(dá)到所在容器的寬度,但根據(jù)構(gòu)件的首先高度調(diào)整它們的高度。東西構(gòu)件被垂直擴(kuò)展,并根據(jù)它們的首先寬度調(diào)整她們的寬度,中間構(gòu)件布滿剩下的空間。

          在使用GridBaglayout管理布局時(shí),需要通過(guò)GridBagConstraints來(lái)指定各構(gòu)件的約束條件,下面是GridBagConstraints的一些設(shè)置
          GridBagConstraints.anchor 構(gòu)件在顯示區(qū)中的位置
          GridBagConstraints.fill         構(gòu)件填充顯示區(qū)的方式
          GridBagConstraints.gridx/gridy  構(gòu)件左上角的網(wǎng)格單元
          GridBagConstraints.gridwidth/gridheigth 構(gòu)件顯示區(qū)的大小
          GridBagConstraints.weighx/weighy 構(gòu)件顯示區(qū)可以消耗多少額外的空間
          GridBagConstraints.insets 構(gòu)件的空白區(qū)
          GridBagConstraints.ipadx/ipady 構(gòu)件的內(nèi)部填充

          posted @ 2005-07-22 17:50 bigseal 閱讀(1624) | 評(píng)論 (0)編輯 收藏

          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 閱讀(1484) | 評(píng)論 (0)編輯 收藏

              有兩種方法要用到對(duì)Graphi的引用,這兩種就是傳遞一個(gè)對(duì)Graphi的引用,或返回對(duì)Graphics的引用。

             1 .傳遞一個(gè)對(duì)Graphi的引用是諸如 void paint(Graphics g)的方法,通過(guò)override該方法來(lái)達(dá)到目的。

          import java.awt.*;

          public class SubPanel extends Panel{

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

          }


          2.返回對(duì)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);
                  }

              }

          }


          其中,如果如果組件當(dāng)前未顯示getGraphics()方法返回null。

          posted @ 2005-07-13 14:07 bigseal 閱讀(1430) | 評(píng)論 (0)編輯 收藏

              AWT是JFC(Java基本類)的核心,為JFC的構(gòu)成提供了以下的基本結(jié)構(gòu):

          • 代理事件模型
          • 輕量構(gòu)件
          • 剪貼板和數(shù)據(jù)傳輸
          • 打印和無(wú)鼠標(biāo)操作

              Java抽象窗口工具集有四個(gè)主要的類,即:構(gòu)件類(Component)、容器類(Container)、圖形類(Graphics)、和布局管理類(LayoutManager和LayoutMangager2)。容器包含構(gòu)件,布局管理器確定容器內(nèi)構(gòu)件的位置和形狀。圖形(Graphics)類提供在構(gòu)件中顯示文本框和圖形的方法。

          1.強(qiáng)制一個(gè)容器布置它的構(gòu)件

              在任何時(shí)間給定的構(gòu)件都是有效(valid)或無(wú)效(invalid)的。無(wú)效的構(gòu)件需要被布置,而有效的構(gòu)件不需要。訪問(wèn)一個(gè) 無(wú)效容器(它的同位體已經(jīng)產(chǎn)生)的validate()引起對(duì)容器layout()方法的調(diào)用。使構(gòu)件無(wú)效的過(guò)程不僅使構(gòu)件自己變得無(wú)效,而且也會(huì)使構(gòu)件所在的容器變的無(wú)效。
          使構(gòu)件無(wú)效的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)
          因此我們可以把希望重新布置的構(gòu)件設(shè)置為無(wú)效,然后調(diào)用該構(gòu)件父容器的validate()方法即可。

          posted @ 2005-07-13 14:04 bigseal 閱讀(1357) | 評(píng)論 (0)編輯 收藏

          Timer是一個(gè)線程用來(lái)調(diào)度在后臺(tái)線程中運(yùn)行的計(jì)劃任務(wù)的使用工具。任務(wù)可能計(jì)劃只運(yùn)行一次,或者以一定的時(shí)間間隔重復(fù)運(yùn)行。
          下面是一個(gè)定時(shí)的小程序:

              /**
               * 彈出菜單顯示3秒鐘后自動(dòng)隱藏
               * 
               
          */

              
          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 閱讀(1545) | 評(píng)論 (0)編輯 收藏

          使用JDIC (Jdesktop Integration Components)類庫(kù)做開(kāi)發(fā)。
          開(kāi)發(fā)過(guò)程中遇到的問(wèn)題:
          1. 主窗體最小化后隱藏
            當(dāng)發(fā)生窗體最小化事件時(shí)把窗體隱藏就可以了
                     /*
                         * 最小化窗體時(shí)把窗體給隱藏了 (非 Javadoc)
                         * @see java.awt.event.WindowListener#windowIconified(java.awt.event.WindowEvent)
                         
            */

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

          2. 單擊系統(tǒng)托盤(pán),顯示程序主窗體
            單擊系統(tǒng)托盤(pán)但時(shí),把窗體置為可見(jiàn),并把窗體從任務(wù)欄恢復(fù)
                       // 單擊系統(tǒng)托盤(pán),顯示程序主窗體
                    tray_icon.addActionListener(new ActionListener() {
                        
            public void actionPerformed(ActionEvent e) {
                            buddyFrame.setVisible(
            true);
                            buddyFrame.setState(JFrame.NORMAL);
                        }

                    }
            );

          3. 當(dāng)有消息時(shí)在系統(tǒng)托盤(pán)圖標(biāo)旁顯示一個(gè)消息提示
            (這是一個(gè)類似與MSN那種,而不是把鼠標(biāo)放到托盤(pán)上顯示的 ToolTip)
            當(dāng)消息到來(lái)時(shí)在系統(tǒng)托盤(pán)圖標(biāo)旁顯示一個(gè)彈出菜單即可
             
            public void promptMsg(String msg, String ticket, String url, String para,
                        String userID) 
            {
                    
            // 設(shè)置消息內(nèi)容
                    mViewMsg.setText(msg);

                    
            // 設(shè)置url(點(diǎn)擊 mViewMsg 菜單選項(xiàng)事件的監(jiān)聽(tīng)程序)
                    mViewMsg.addActionListener(new msgMenuActionListener(msgMenu, url + "?"
                            
            + para));

                    
            // 設(shè)置菜單的大小和位置
                    setMsgMenuSize();

                    msgMenu.setVisible(
            true);
                }


                
            /**
                 * 
                 * 設(shè)置菜單的大小和位置
                 
            */

                
            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 閱讀(2957) | 評(píng)論 (2)編輯 收藏

          主站蜘蛛池模板: 嘉荫县| 盐山县| 阿图什市| 包头市| 定州市| 资中县| 连山| 峨边| 海淀区| 三河市| 拜泉县| 黑龙江省| 邹平县| 开封市| 许昌市| 威信县| 衡东县| 三亚市| 宁城县| 瑞丽市| 莱芜市| 神农架林区| 平邑县| 米泉市| 峡江县| 手游| 淮安市| 沙湾县| 讷河市| 遂昌县| 米林县| 尚义县| 龙川县| 聂拉木县| 襄垣县| 湾仔区| 白城市| 正蓝旗| 敦化市| 景宁| 扬中市|