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小程序
          主站蜘蛛池模板: 巩义市| 会同县| 登封市| 尚志市| 乌鲁木齐市| 堆龙德庆县| 中西区| 新建县| 儋州市| 宝丰县| 镇雄县| 射洪县| 桂东县| 姜堰市| 永定县| 安西县| 静乐县| 山阳县| 宜川县| 滨海县| 出国| 易门县| 滨州市| 通道| 西华县| 白河县| 资中县| 麟游县| 青岛市| 商城县| 汉沽区| 东乌珠穆沁旗| 甘肃省| 历史| 新疆| 岳阳县| 南通市| 舞阳县| 宝丰县| 周口市| 逊克县|