⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 yh.java

📁 简单的英汉词典大家可以小秒
💻 JAVA
字号:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Yh
{
  public static void main(String args[]){
   JFrame f=new JFrame();
   Container c=f.getContentPane();
   c.setLayout(new BorderLayout());
   JLabel lab=new JLabel("请输入");
   final JTextField txt=new JTextField(10);
   JPanel north=new JPanel();
   north.add(lab);
   north.add(txt);
   JButton btn1=new JButton("英译汉");
   JButton btn2=new JButton("汉译英");
   JPanel center=new JPanel();
   center.add(btn1);
   center.add(btn2);
   final JTextArea ta=new JTextArea(5,20);
   c.add(north,BorderLayout.NORTH);
   c.add(center,BorderLayout.CENTER);
   c.add(ta,BorderLayout.SOUTH);
   f.setSize(300,200);
   f.show();
   
   final Yhciku yhck=new Yhciku();
   btn1.addActionListener(new ActionListener()
   {
   public void actionPerformed(ActionEvent e)
      {
        String inputstr=txt.getText();
        boolean check=false;
        int i;
        for(i=0;i<yhck.english.length;i++){
          check=yhck.english[i].equalsIgnoreCase(inputstr);
          if(check){
            ta.setText(yhck.chinese[i]);
            break;}
        }
        if(i==yhck.english.length)
          ta.setText("无法翻译成中文!");
     }
   });
   btn2.addActionListener(new ActionListener()
   {
   public void actionPerformed(ActionEvent e)
      {
        String inputstr=txt.getText();
        boolean check=false;
        int i;
        for(i=0;i<yhck.english.length;i++){
          check=yhck.chinese[i].equalsIgnoreCase(inputstr);
          if(check){
            ta.setText(yhck.english[i]);
            break;}
        }
        if(i==yhck.chinese.length)
          ta.setText("无法翻译成英文!");
     }
   });
}}

   

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -