<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    march alex's blog
    hello,I am march alex
    posts - 52,comments - 7,trackbacks - 0
    在之前寫過一個TranslateHelper類用于在線翻譯英文單詞。
    我之前寫過一個單詞翻譯大師用于將文件中出現的所有單詞存儲在另一個文件中。存儲的格式如下:
    word: explain
    如:
    apple: 蘋果;蘋果樹;蘋果公司
    banana: 香蕉;芭蕉屬植物;喜劇演員
    我們假設這里獲取單詞的原文件為D:|test_english.txt
    存儲單詞的文件為D:\word_lib.txt

    這次寫的TranslateHelper2類就是在此基礎上編寫的一個英漢詞典的離線版本。
    在此之前我寫了一個WordFinder類用于獲取D:\word_lib.txt下的特定單詞及其解釋(沒有的話返回null)。
    WordFinder.java
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.util.StringTokenizer;


    public class WordFinder {
        public static String find(String word) throws Exception {
            String filename = new String("D:\\word_lib.txt");
            BufferedReader reader = new BufferedReader(new FileReader(filename));  
            String line = "";
            while((line = reader.readLine()) != null) {
                StringTokenizer st = new StringTokenizer(line, ":");
                String key = st.nextToken();
                if(key.equals(word)) {
                    return st.nextToken();
                }
            }
            return null;
        }
        public static void main(String[] args) throws Exception {
            String ans = find("apple");
            System.out.println(ans);
        }
    }

    下面是TranslateHelper2類,其詞庫是基于文件D:\word_lib.txt的,如下:
    新增了一個按鍵可在線更新詞庫,即D:\word_lib.txt里面的內容(在現實點按鍵可更新)。

    TranslateHelper2.java
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.net.HttpURLConnection;
    import java.net.URL;

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


    public class TranslateHelper2 extends JFrame {
         private static final int Width = 500;
         private static final int Height = 220;
         private static JFrame frame = null;
         private static FlowLayout flowLayout = null;
         
         private static JLabel label = null;
         private static JTextField wordText = null;
         private static JTextField explainText = null;
         private static JButton button = null;
         private static JButton new_button = null;

         public TranslateHelper2() {
             frame = new JFrame("Translate Helper");
             flowLayout = new FlowLayout(FlowLayout.CENTER);
             flowLayout.setHgap(20);
             flowLayout.setVgap(30);
            frame.setLayout(flowLayout);
            label = new JLabel("單詞:");
            wordText = new JTextField(10);
            explainText = new JTextField(40);
            button = new JButton("提交");
            new_button = new JButton("在線時點擊可更新");
            
            frame.add(label);
            frame.add(wordText);
            frame.add(button);
            frame.add(explainText);
            frame.add(new_button);
            
            button.addActionListener(new ButtonAction());
            new_button.addActionListener(new ButtonAction());
            
            frame.setVisible(true);
            frame.setSize(Width, Height);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         }
         
         private class ButtonAction implements ActionListener {
                public void actionPerformed(ActionEvent evt) {
                    Object s = evt.getSource();
                    //System.out.println("hello");
                    if(s == button) {
                        String word = wordText.getText();
                    
                        try {
                            String _word = word;
                            String _explain = WordFinder.find(word);
                            wordText.setText(_word);
                            explainText.setText(_explain);
                        
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    } else if(s == new_button) {
                        try {
                            TranslateMaster.translateAllLocal("D:\\test_english.txt", "D:\\word_lib.txt");
                        } catch (Exception e) {
                            return;
                        }
                    }
                }
        }
        public static void main(String[] args) {
            new TranslateHelper2();
        }
    }
    posted on 2015-03-11 13:25 marchalex 閱讀(408) 評論(0)  編輯  收藏 所屬分類: java小程序
    主站蜘蛛池模板: 手机看片国产免费永久| 未满十八私人高清免费影院| 亚洲一区免费观看| 亚洲午夜国产精品无码老牛影视| 日韩成人毛片高清视频免费看| 免费一看一级毛片人| 国产免费网站看v片在线| 国产亚洲精品精品国产亚洲综合| 色吊丝性永久免费看码| 亚洲国产精品人人做人人爱| 亚洲精品韩国美女在线| 免费无码VA一区二区三区| 1区1区3区4区产品亚洲| 男女免费观看在线爽爽爽视频| 国产成人精品亚洲日本在线| 成人au免费视频影院| 色网站在线免费观看| 亚洲香蕉成人AV网站在线观看| 国产在线一区二区综合免费视频| 7777久久亚洲中文字幕蜜桃| 日本黄网站动漫视频免费| 97久久国产亚洲精品超碰热| 四虎永久在线精品免费观看地址 | 亚洲国产成人久久精品99 | 国产亚洲日韩在线a不卡| www.91亚洲| 伊人久久免费视频| 国产精品亚洲片夜色在线| 免费永久看黄在线观看app| 丝袜捆绑调教视频免费区| 亚洲视频手机在线| 国产一卡二卡≡卡四卡免费乱码 | 亚洲狠狠ady亚洲精品大秀| 国产麻豆免费观看91| 成在线人免费无码高潮喷水| 亚洲精品国产福利在线观看| 免费大香伊蕉在人线国产| 最近2019中文免费字幕在线观看| 亚洲免费福利在线视频| 中文亚洲成a人片在线观看| 亚洲免费福利视频|