春風(fēng)博客

          春天里,百花香...

          導(dǎo)航

          <2025年8月>
          272829303112
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          統(tǒng)計(jì)

          公告

          MAIL: junglesong@gmail.com
          MSN: junglesong_5@hotmail.com

          Locations of visitors to this page

          常用鏈接

          留言簿(11)

          隨筆分類(lèi)(224)

          隨筆檔案(126)

          個(gè)人軟件下載

          我的其它博客

          我的鄰居們

          最新隨筆

          搜索

          積分與排名

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          #

          買(mǎi)書(shū)與讀書(shū)

          書(shū)分專(zhuān)業(yè)書(shū)與閑書(shū).專(zhuān)業(yè)書(shū)是安身立命之本,建功立業(yè)之基,只要對(duì)自己有益的,在經(jīng)濟(jì)能力能承受的基礎(chǔ)上應(yīng)該多買(mǎi)多看.閑書(shū)基本只起業(yè)余調(diào)劑作用,可看可不看,切勿拿小菜當(dāng)正餐,過(guò)分閱讀只有迷惑心智,分散精力的后果.切不可沉迷于其中,所謂玩物喪志是也.

          無(wú)論錢(qián)多寡,買(mǎi)書(shū)都應(yīng)該精挑細(xì)選,確實(shí)是好書(shū)才買(mǎi),買(mǎi)了壞書(shū)或一般書(shū)除了浪費(fèi)錢(qián)財(cái),耽誤時(shí)間,還喪失了讀好書(shū)的時(shí)間和機(jī)會(huì),要知道在現(xiàn)在煩雜的社會(huì)生活中偷得浮生半日閑也是不容易的,何況以后看見(jiàn)還添堵,與其如此還不如鍛煉出鑒別良莠的眼光.

          專(zhuān)業(yè)書(shū)分精品與平裝.精品是指那種老外寫(xiě)的,大部頭的,全面詳細(xì)的書(shū),這種書(shū)雖貴,但讀來(lái)收益很大,有微言大義,能常讀常新,不像那些國(guó)內(nèi)翻譯,改寫(xiě)的,只抄個(gè)皮毛,買(mǎi)來(lái)如同雞肋,還不如不買(mǎi).

          看書(shū)一定要?jiǎng)庸P記點(diǎn)寫(xiě)點(diǎn)什么,所謂"不動(dòng)筆墨不讀書(shū)",道理說(shuō)不上來(lái),但確實(shí)有效,寫(xiě)在筆記本或博客都行.閑書(shū)可寫(xiě)讀后感,鍛煉以下文筆也不錯(cuò).當(dāng)然看書(shū)能把所讀熟記于心最好,不要依賴筆記.依賴筆記會(huì)養(yǎng)成怠惰的習(xí)慣,真要用時(shí)一不能立即提出對(duì)策,二不一定能找到筆記在那干著急.筆記是用來(lái)總結(jié)回味的,不是隨用隨查的電子書(shū)籍.

          書(shū)只能教你知識(shí),不要期待書(shū)本或者人能指明你現(xiàn)在該自己干什么,他們只能大致指出一個(gè)方向,道還要靠自己去追尋.

          posted @ 2007-06-17 22:46 sitinspring 閱讀(506) | 評(píng)論 (0)編輯 收藏

          逛技術(shù)論壇有嘛用?

               摘要: 1.論壇和電視非常相象.
          2.論壇的最大作用是開(kāi)闊眼界,但開(kāi)闊的程度取決于你自己.它猶如一個(gè)垃圾堆,找到件寶貝需要花費(fèi)大量時(shí)間.
          3.論壇的積分,精華,良好數(shù)都是虛幻的,應(yīng)當(dāng)視如草芥.
          4.最好只在無(wú)聊時(shí)需要消遣時(shí)逛逛論壇,這樣你花的時(shí)間和逛論壇所得在價(jià)值上才對(duì)等.
          5.拿你自己的時(shí)間生命投資現(xiàn)實(shí)比投資虛幻要來(lái)得實(shí)在.  閱讀全文

          posted @ 2007-06-15 12:47 sitinspring 閱讀(504) | 評(píng)論 (4)編輯 收藏

          對(duì)程序員來(lái)說(shuō),幾種想法最要不得

               摘要: 1.急于出名賺錢(qián)的想法.
          2.從眾的想法.
          3.破罐子破摔的想法.
          4.早有蜻蜓立上頭的想法.  閱讀全文

          posted @ 2007-06-14 07:07 sitinspring 閱讀(817) | 評(píng)論 (6)編輯 收藏

          在JTable上點(diǎn)擊右鍵并彈出菜單的實(shí)現(xiàn)

          本人在做一個(gè)在JTable上點(diǎn)擊右鍵彈出菜單的程序時(shí),遇到了這樣的問(wèn)題--菜單首項(xiàng)需要根據(jù)點(diǎn)擊的表格行的"表名列"改變,這需要我們做一點(diǎn)小小的工作,其實(shí)就是根據(jù)點(diǎn)擊的位置推算所在行,好了,廢話少說(shuō),看代碼吧.

          1.表格的建立過(guò)程

              String[] headers = {  "No", "Table Name"  };
              Object[][] cellData = null;

              DefaultTableModel model = new DefaultTableModel(cellData, headers) {
                public boolean isCellEditable(int row, int column) {
                  // 第N列可以編輯
                  /*
                   * if (column == N) { return false; }
                   */

                  // 整個(gè)表都不能編輯
                  return false;
                }
              };

              table = new JTable(model);

          2.菜單的建立
              popupMenu=new JPopupMenu();
             
              tableNameItem=new JMenuItem("");
              selectItem=new JMenuItem("Select SQL");
              insertItem=new JMenuItem("Insert SQL");
              deleteItem=new JMenuItem("Delete SQL");
              updateItem=new JMenuItem("Update SQL");
              hbmItem=new JMenuItem("hbm xml");
              hbmPojoItem=new JMenuItem("Pojo Class");
             
              popupMenu.add(tableNameItem);
              popupMenu.addSeparator();
              popupMenu.add(selectItem);
              popupMenu.add(insertItem);
              popupMenu.add(deleteItem);
              popupMenu.add(updateItem);
              popupMenu.addSeparator();
              popupMenu.add(hbmItem);
              popupMenu.add(hbmPojoItem);

          3.菜單的彈出處理
              
                table.addMouseListener(new MouseAdapter() {
                    public void mousePressed(MouseEvent evt) {
                        if (evt.isPopupTrigger()) { 
                          //
          取得右鍵點(diǎn)擊所在行
                       
          int row=evt.getY()/table.getRowHeight();
                       
                        /**
                         * 取得是表名的那一列
                         */
                        int tableNameColumn=-1;
                       
                        for(int i=0;i<table.getColumnModel().getColumnCount();i++){
                          TableColumn selColumn = table.getColumnModel().getColumn(i);
                          String columnHeader=(String)selColumn.getHeaderValue();
                         
                          if(columnHeader.equals("Table Name")){
                            tableNameColumn=i;
                            break;
                          }
                        }
                       
                        /**
                         * 取得表名并彈出菜單
                         */
                        if(tableNameColumn!=-1){
                          /**
                           * 修改菜單首條的名稱(chēng)
                           */
                          String tableName=(String)table.getValueAt(row,tableNameColumn);
                          tableNameItem.setText(tableName);
                         
                          // 彈出菜單
                          popupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
                        }
                        }
                    }
                }

                  
          4.實(shí)現(xiàn)的效果如下:

          posted @ 2007-06-12 22:23 sitinspring 閱讀(8165) | 評(píng)論 (1)編輯 收藏

          封裝完畢,能顯示當(dāng)前時(shí)間并改變風(fēng)格的菜單類(lèi)

           1 import java.awt.event.ActionEvent;
           2 import java.awt.event.ActionListener;
           3 import java.text.SimpleDateFormat;
           4 import java.util.Calendar;
           5 import javax.swing.ButtonGroup;
           6 import javax.swing.JMenu;
           7 import javax.swing.JRadioButtonMenuItem;
           8 import javax.swing.Timer;
           9 
          10 public class TimeMenu extends JMenu{
          11     private static final long serialVersionUID = 1L;    
          12     private final static int ONE_SECOND=1000;
          13     private String timeStyle="";
          14     
          15     public TimeMenu(String text){
          16         super(text);
          17         timeStyle="yyyy-MM-dd HH:mm:ss";
          18         timer.start();
          19         addSubMenuItems();
          20     }
          21 
          22     Timer timer=new Timer(ONE_SECOND,new ActionListener(){
          23         public void actionPerformed(ActionEvent evt){
          24             setCurrTimeToText();
          25         }
          26     });    
          27     
          28     private void addSubMenuItems(){
          29         String[] items=new String[]{"yyyy-MM-dd HH:mm:ss","HH:mm:ss","yyyy-MM-dd"};
          30         
          31         ButtonGroup buttongroup = new ButtonGroup();
          32         
          33         for (int i = 0; i < items.length; i++) {
          34             JRadioButtonMenuItem timeMitem = new JRadioButtonMenuItem(
          35                     items[i], i == 0);
          36             
          37             final String timeStyleTmp = items[i];
          38             timeMitem.addActionListener(new ActionListener() {
          39                 public void actionPerformed(ActionEvent e) {
          40                     try {
          41                         timeStyle=timeStyleTmp;
          42                     } catch (Exception ex) {
          43                         System.out.println("Can't Change Time Style to "
          44                                 + timeStyleTmp);
          45                     }
          46                 }
          47             });
          48             buttongroup.add(timeMitem);
          49             this.add(timeMitem);
          50         }
          51     }
          52     
          53     private void setCurrTimeToText(){
          54         this.setText(getCurrTime(timeStyle));
          55     }
          56     
          57     private String getCurrTime(String timeStyle){
          58         Calendar cal= Calendar.getInstance();
          59         SimpleDateFormat fromatter=new SimpleDateFormat(timeStyle);
          60         String strCurrTime=fromatter.format(cal.getTime());
          61         
          62         return strCurrTime;
          63     }
          64 }

          用法如下:
          1     JMenuBar menubar = new JMenuBar();
          2     mainFrame.setJMenuBar(menubar);
          3 
          4     
          5 
          6     TimeMenu timeMenu = new TimeMenu("Time");
          7     menubar.add(timeMenu);
          8 
          9 

           

          posted @ 2007-06-08 01:00 sitinspring 閱讀(1948) | 評(píng)論 (0)編輯 收藏

          自己模擬一個(gè)Spring的IoC處理

          看spring的ioc,感覺(jué)很點(diǎn)意思,于是自己寫(xiě)了一個(gè)Spring之FileSystemXmlApplicationContext的模擬類(lèi),貼出來(lái)請(qǐng)大家斧正.

          1.功能說(shuō)明:關(guān)于訂單,折扣,價(jià)格
          訂單是貨物的訂單,主要貨物有計(jì)算機(jī),文具,紙張三類(lèi),還有其它一些物件.每種貨物都有不同的折扣比例,從單價(jià)中扣除折扣比例后就是進(jìn)貨時(shí)的真實(shí)價(jià)格.

          2.Spring之Ioc實(shí)現(xiàn)

          這里就不贅述了,詳情請(qǐng)見(jiàn)帖子
          http://www.aygfsteel.com/sitinspring/archive/2007/06/06/122326.html

          3.模擬實(shí)現(xiàn)

          // 折扣接口

          public interface Discount{   
           public float getDiscount();   
           public void  setDiscount(float discount);   
          }  

          // 計(jì)算機(jī)折扣類(lèi)
          public class ComputerDiscount implements Discount{   
           private float discount=0.0f;   
              
           public float getDiscount(){   
            return discount;   
           }   
              
           public void setDiscount(float discount){   
            this.discount=discount;   
           }   
          }  

          // 文具折扣類(lèi)
          public class StationaryDiscount implements Discount{   
           private float discount=0.0f;   
              
           public float getDiscount(){   
            return discount;   
           }   
              
           public void setDiscount(float discount){   
            this.discount=discount;   
           }   
          }  
          // 紙張折扣類(lèi)

          public class PaperDiscount implements Discount{   
           private float discount=0.0f;   
              
           public float getDiscount(){   
            return discount;   
           }   
              
           public void setDiscount(float discount){   
            this.discount=discount;   
           }   
          }  
          // 其它折扣類(lèi)

          public class OtherDiscount implements Discount{   
           private float discount=0.0f;   
              
           public float getDiscount(){   
            return discount;   
           }   
              
           public void setDiscount(float discount){   
            this.discount=discount;   
           }   
          }   

          // 訂單類(lèi)
          public class Order{   
           public static final String Type_Computer="Computer";   
           public static final String Type_Stationary="Stationary";   
           public static final String Type_Paper="Paper";    
           private String type;   
              
           private float price;    
              
           public Order(float price,String type){   
            this.price=price;   
            this.type=type;   
           }   
              
           public Order(){   
            this(100.0f,"Other");   
           }   
            
            
           // 調(diào)用模擬類(lèi)的地方,看看調(diào)用過(guò)程和Spring很相似吧 
           public float getPrice() {   
            MockContext ctx = new MockContext("bean.xml");   
            Discount discount = null;   
            discount = (Discount) ctx.getBean(this.type);   
            
            return price * (1.0f - discount.getDiscount());   
           }   
          }   
           // Spring之FileSystemXmlApplicationContext的模擬類(lèi)

          /**  
           * Spring之FileSystemXmlApplicationContext的模擬類(lèi)  
           *   
           * @author junglesong  
           *  
           */  
          public class MockContext {   
           Document doc = null;// 用于解析Bean配置文件的Xml Document   
           Element root = null;// Bean文件的根節(jié)點(diǎn)   
            
           /**  
            * 構(gòu)造函數(shù),用于初始化doc和root  
            * @param beanFileName  
            */  
           public MockContext(String beanFileName) {   
            SAXBuilder buider = new SAXBuilder();   
            try {   
             doc = buider.build(new File(beanFileName));   
             root = doc.getRootElement();   
            
            } catch (Exception ex) {   
             ex.printStackTrace();   
            }   
           }   
            
           /**  
            * 根據(jù)beanId創(chuàng)建類(lèi)并調(diào)用規(guī)定的方法  
            *   
            * @param beanId  
            * @return  
            */  
           public Object getBean(String beanId) {   
            Object obj=null;   
               
            try {   
             Element beanElm =getSubElm(root,"id",beanId);   
                
             if(beanElm!=null){   
              String className=beanElm.getAttribute("class").getValue();   
              Class cls=Class.forName(className);    
              // 由類(lèi)得到類(lèi)實(shí)例   
              obj=cls.newInstance();   
                 
              List ls=beanElm.getChildren();       
              for(Iterator it=ls.iterator();it.hasNext();){   
               Element elm=(Element)it.next();   
                  
               String methodName=elm.getAttributeValue("name");   
               String methodValue=(String)elm.getChildText("value");    
                  
               // 取得類(lèi)方法   
               Method method = cls.getMethod(getSetterMethod(methodName), new Class[] {getClassByValue(methodValue)});   
                  
               // 建立數(shù)組   
                              Object params[]=getParamsByValue(methodValue);   
                                                     
                              // 調(diào)用類(lèi)方法   
               method.invoke(obj,params);   
              }       
             }      
            } catch (Exception ex) {   
             ex.printStackTrace();   
            }   
            
            return obj;   
           }   
              
           /**  
            * 由參數(shù)的值得到參數(shù)的類(lèi)型,目前可處理浮點(diǎn)數(shù)和字符串兩種情況  
            *   
            * @param value  
            * @return  
            */  
           private Class getClassByValue(String value){   
            Class cls=String.class;   
               
            try{   
             Float.parseFloat(value);   
             cls=float.class;   
            }   
            catch(Exception ex){   
             ex.printStackTrace();   
            }     
               
            return cls;   
           }   
              
           /**  
            * 由參數(shù)的值得到包含參數(shù)的數(shù)組,目前可處理浮點(diǎn)數(shù)和字符串兩種情況  
            *   
            * @param value  
            * @return  
            */  
           private Object[] getParamsByValue(String value){   
            Object[] params=new Object[1];   
               
            try{   
             Float.parseFloat(value);   
             params[0]=new Float(Float.parseFloat(value));   
            }   
            catch(Exception ex){   
             ex.printStackTrace();   
             params[0]=new String(value);   
            }    
               
            return params;   
           }   
              
           /**  
            * 取得root下屬性為subElmAttr,值等于subElmValue的節(jié)點(diǎn)  
            *   
            * @param root  
            * @param subElmAttr  
            * @param subElmValue  
            * @return  
            */  
           private Element getSubElm(Element root,String subElmAttr,String subElmValue){   
            Element rtv=null;   
               
            List ls=root.getChildren();   
               
            for(Iterator it=ls.iterator();it.hasNext();){   
             Element elm=(Element)it.next();   
                
             if(elm.getAttribute(subElmAttr).getValue().equals(subElmValue)){   
              rtv=elm;   
              break;   
             }   
            }   
               
            return rtv;   
           }   
              
           /**  
            * 取得setter方法  
            *   
            * @param methodName  
            * @return  
            */  
           private String getSetterMethod(String methodName){   
            return "set"+methodName.substring(0,1).toUpperCase()+methodName.substring(1,methodName.length());   
           }   
          }   
            
           調(diào)用的代碼如下:

          java 代碼
          Order computerOrder=new Order(100.0f,Order.Type_Computer);   
          System.out.println("computerOrder's price is \t"+computerOrder.getPrice());   
            
          Order stationaryOrder=new Order(100.0f,Order.Type_Stationary);   
          System.out.println("stationaryOrder's price is \t"+stationaryOrder.getPrice());   
            
          Order paperOrder=new Order(100.0f,Order.Type_Paper);   
          System.out.println("paperOrder's price is \t\t"+paperOrder.getPrice());   
            
          Order otherOrder=new Order();   
          System.out.println("otherOrder's price is \t\t"+otherOrder.getPrice());  
          輸出效果和使用Spring是一樣的,速度慢了些,但可以優(yōu)化:

          java 代碼
          computerOrder's price is  70.0  
          stationaryOrder's price is  80.0  
          paperOrder's price is   90.0  
          otherOrder's price is   95.0   

          感悟:自己做過(guò)一遍后,覺(jué)得很多框架并非想像中那樣神秘高深,只要肯動(dòng)腦筋,愿意動(dòng)手,我們有機(jī)會(huì)站在時(shí)代的風(fēng)口浪尖上,: ).

           

          posted @ 2007-06-07 15:06 sitinspring 閱讀(531) | 評(píng)論 (1)編輯 收藏

          僅列出標(biāo)題
          共13頁(yè): First 上一頁(yè) 5 6 7 8 9 10 11 12 13 
          sitinspring(http://www.aygfsteel.com)原創(chuàng),轉(zhuǎn)載請(qǐng)注明出處.
          主站蜘蛛池模板: 三原县| 陇南市| 三台县| 永城市| 长沙市| 临清市| 绥中县| 双鸭山市| 邛崃市| 辽阳市| 东方市| 原平市| 怀宁县| 云龙县| 甘孜| 华蓥市| 尚义县| 凤阳县| 阳信县| 当雄县| 紫阳县| 新晃| 原平市| 滦平县| 迁西县| 库车县| 中西区| 金湖县| 大石桥市| 治多县| 子长县| 周口市| 内丘县| 四川省| 克山县| 高雄市| 云龙县| 沁水县| 灵川县| 青龙| 宁安市|