2012年1月11日 星期三

thread-safe singleton(轉載)

http://www.possibility.com/wiki/index.php?title=SingletonPattern

git tag簡記

記下一個tag 'v1.0'
git tag -a v1.0

看tag
git tag
git show v1.0

把tag push 到github(或任何人)
git push --tags

ref:
http://gitref.org/branching/#tag
http://wptheming.com/2011/04/add-remove-github-tags/

2012年1月5日 星期四

Visual Editor的一個小缺點

new元件時的建構子必須是預設,即沒有參數的建構子。
否則VE會顯示不出來,當然,編譯執行依然一切正常,只是在拉GUI時奇摩子不是很好XD

另外,如果排版亂了,可能是重複setLayout造成的。
通常是,我們自己在被加類別內設定自己喜歡的Layout,但VE會在getXXX裡產生一次setLayout,這時只要把這行註解掉即可。

軟工project筆記,實作ActionListener解法一

1. implements ActionListener
2. 實作(override)actionPerformed
3. 給submit加上addActionListener(this),注意是"this"喔!!


package view.doctor;

import java.awt.GridBagLayout;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;

public class SeePatientFoundamentalDataPanel extends JPanel implements ActionListener {

    private static final long serialVersionUID = 1L;
    private JLabel jLabel = null;
    private JTextField id = null;
    private JButton submit = null;

    @Override
    public void actionPerformed(ActionEvent e) {
        if ((JButton)e.getSource() == submit) {
            JButton jb = (JButton)e.getSource();
            DoctorMainTabbedPane pane = (DoctorMainTabbedPane)jb.getParent().getParent();
            if(pane.parent().loginFrame().patients().get(id.getText()) == null) {
                JOptionPane.showMessageDialog(null, "查無此人喔!");
            } else {
                JOptionPane.showMessageDialog(null, "找到:" + pane.parent().loginFrame().patients().get(id.getText()).name());
            }
        }
    }
    
    /**
     * This is the default constructor
     */
    public SeePatientFoundamentalDataPanel() {
        super();
        initialize();
    }

    /**
     * This method initializes this
     * 
     * @return void
     */
    private void initialize() {
        jLabel = new JLabel();
        jLabel.setText("病人ID");
        this.setSize(300, 200);
        this.setLayout(new BorderLayout());
        this.add(jLabel, BorderLayout.WEST);
        this.add(getId(), BorderLayout.CENTER);
        this.add(getSubmit(), BorderLayout.EAST);
    }

    /**
     * This method initializes id   
     *  
     * @return javax.swing.JTextField   
     */
    private JTextField getId() {
        if (id == null) {
            id = new JTextField();
        }
        return id;
    }

    /**
     * This method initializes submit   
     *  
     * @return javax.swing.JButton  
     */
    private JButton getSubmit() {
        if (submit == null) {
            submit = new JButton();
            submit.setText("查詢");
            submit.addActionListener(this);
        }
        return submit;
    }

}

2012年1月2日 星期一

eclipse Visual Editor學習資源

一篇清楚的中文入門教學

安裝搞的我焦頭爛額,筆記成功安裝的要點。
1. 不能online install,請先去這裡,下載最底下的Visual Editor。
2. 下載回ve.tgz,把它解開。
3. 打開eclipse,Help -> Install New Software... -> Add -> Archive... -> ve/downloads/downloads/drops/1.5.0/R201012021328/VE-Update-1.5.0.zip
之後的流程google就有,不贅述囉。

依照官方說明,我用eclipse Helio應該選 ve 1.5版,至於使用其他版本的看倌請自行參照,選擇適合的ve版本囉!


--

另外附上netbean的資料
使用教學
netbean是一套IDE,拉GUI的功能用所生成的code,會到他提供的一系列class。
他提供的Group layout用起來很爽,跟用interface builder滿像,但因為這樣所以綁定IDE了,相容性差。