zoukankan      html  css  js  c++  java
  • 一个英汉字典例,某书课后题

    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.*;
    
    
    public class DictDemo {
        public static void main(String[] args) {
            new DictFrame();
        }
    
    }
    class DictFrame extends JFrame implements ActionListener{
        JTextField text1,text2;
        JButton bt;
        DictFrame(){
            setTitle("Dict");
            setSize(300,300);
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            bt = new JButton("翻 译");
            bt.addActionListener(this);
            text1 = new JTextField(10);
            text2 = new JTextField(10);
            text2.setEditable(false);
            
            add(text1,BorderLayout.WEST);
            add(text2,BorderLayout.EAST);
            add(bt,BorderLayout.SOUTH);
            
            pack();
            this.setLocationRelativeTo(null);
            this.setVisible(true);
            
        }
        @Override
        public void actionPerformed(ActionEvent e) {
            text2.setText(Dicts.getMean(text1.getText().trim().toLowerCase()));
            
        }
    }
    class Dicts {
        static int id ;
        static String[][] dict ;
        static {
            dict = new String[100][2];
            id = 0;
            insertWord("china","中国");
            insertWord("jpanese","日本");
            insertWord("你好","hello");
        }
        private Dicts(){
            
        }
        public static void insertWord(String str1,String str2){
            dict[id][0] = str1.toLowerCase();
            dict[id][1] = str2.toLowerCase();
            id++;
        }
        public static String getMean(String  str){
            for(int i=0;i<id;i++) {
                if (dict[i][0].equals(str)) return dict[i][1];
                if (dict[i][1].equals(str)) return dict[i][0];
            }
            return "查无此字";
        }
    }
  • 相关阅读:
    GetSystemMetrics SM_** 系统消息
    Direct3D中的HLSL
    Delphi TStream 详细介绍
    VI命令详解(大全)
    Delphi中messagedlg
    Windows中的消息详细列表
    SharePoint2007深入浅出——开发环境配置
    深入浅出InfoPath——预备式
    SharePoint术语对照表
    深入浅出Nintex——判断当前用户的角色
  • 原文地址:https://www.cnblogs.com/qqjue/p/2620494.html
Copyright © 2011-2022 走看看