march alex's blog
          hello,I am march alex
          posts - 52,comments - 7,trackbacks - 0
          上次寫了一個基于iciba的英漢翻譯,這次在原來的基礎上加了一個窗口,實現了TranslateHelper類。
          效果如下:


          代碼如下:
          import java.awt.FlowLayout;
          import java.awt.event.ActionEvent;
          import java.awt.event.ActionListener;

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


          public class TranslateHelper extends JFrame {
               private static final int Width = 500;
               private static final int Height = 200;
               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;
               
               public TranslateHelper() {
                   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("提交");
                  
                  frame.add(label);
                  frame.add(wordText);
                  frame.add(button);
                  frame.add(explainText);
                  
                  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");
                          String word = wordText.getText();
                          
                          try {
                              String _word = EnglishChineseTranslater.getWordName(word);
                              String _explain = EnglishChineseTranslater.getTranslation(word);
                              wordText.setText(_word);
                              explainText.setText(_explain);
                              
                          } catch (Exception e) {
                              e.printStackTrace();
                          }
                      }
              }
              public static void main(String[] args) {
                  new TranslateHelper();
              }
          }
          posted on 2015-03-08 18:47 marchalex 閱讀(210) 評論(0)  編輯  收藏 所屬分類: java小程序
          主站蜘蛛池模板: 阿瓦提县| 叙永县| 色达县| 长沙市| 日照市| 天台县| 株洲市| 盐亭县| 石屏县| 关岭| 温州市| 株洲县| 上思县| 潍坊市| 将乐县| 沛县| 晋中市| 买车| 镇康县| 胶州市| 金坛市| 若羌县| 剑河县| 岳阳市| 庄河市| 定兴县| 凤翔县| 固始县| 玛沁县| 汶上县| 天台县| 敦煌市| 太白县| 庆安县| 禄丰县| 镇原县| 娱乐| 曲周县| 广德县| 安义县| 芜湖市|