zoukankan      html  css  js  c++  java
  • 英语翻译java

      1 import java.awt.event.ActionEvent;
      2 import java.awt.event.ActionListener;
      3 import java.awt.BorderLayout;
      4 import java.awt.EventQueue;
      5 import java.awt.event.ActionEvent;
      6 import java.io.File;
      7 import java.io.FileNotFoundException;
      8 import java.util.HashMap;
      9 import java.util.Scanner;
     10 
     11 import javax.swing.JFrame;
     12 import javax.swing.JPanel;
     13 import javax.swing.border.EmptyBorder;
     14 import javax.swing.JLabel;
     15 import javax.swing.JTextField;
     16 import javax.swing.JButton;
     17 
     18 public class Mydictionary extends JFrame {
     19     HashMap<String,String> map;
     20     private JPanel contentPane;
     21     private JTextField txtword;
     22     private JLabel lbtranslation;
     23 
     24     /**
     25      * Launch the application.
     26      */
     27     public static void main(String[] args) {
     28         EventQueue.invokeLater(new Runnable() {
     29             public void run() {
     30                 try {
     31                     Mydictionary frame = new Mydictionary();
     32                     frame.setVisible(true);
     33                 } catch (Exception e) {
     34                     e.printStackTrace();
     35                 }
     36             }
     37         });
     38     }
     39 
     40     /**
     41      * Create the frame.
     42      * @throws FileNotFoundException 
     43      */
     44     public Mydictionary() throws FileNotFoundException {
     45         
     46         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     47         setBounds(100, 100, 450, 300);
     48         contentPane = new JPanel();
     49         contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
     50         setContentPane(contentPane);
     51         contentPane.setLayout(null);
     52         
     53         JLabel lblmessage = new JLabel("放入单词");
     54         lblmessage.setBounds(41, 45, 72, 18);
     55         contentPane.add(lblmessage);
     56         
     57         txtword = new JTextField();
     58         txtword.setBounds(140, 42, 86, 24);
     59         contentPane.add(txtword);
     60         txtword.setColumns(10);
     61         
     62         JButton btnseek = new JButton("翻译");
     63         btnseek.setBounds(258, 41, 113, 27);
     64         contentPane.add(btnseek);
     65         
     66         btnseek.addActionListener(new Actionlistener() {
     67             @Override
     68             public void actionPerformed(ActionEvent e){
     69                 String word = txtword.getText().trim().toLowerCase();
     70                 String result = map.get(word);
     71                 lbtranslation.setText(result);
     72             }
     73         });
     74         
     75         lbtranslation = new JLabel("");
     76         lbtranslation.setBounds(72, 96, 279, 58);
     77         contentPane.add(lbtranslation);
     78         
     79         createdict();
     80     }
     81     
     82     public void createdict() throws FileNotFoundException
     83     {
     84         map=new HashMap<String,String>();        
     85         Scanner scanner=new Scanner(new File("cet46.txt"));    
     86         
     87         //BufferedReader br=new BufferedReader(new FileReader("cet46.txt"));
     88         //System.out.println(br.readLine());
     89         //System.out.println();
     90         
     91         while(scanner.hasNextLine()){
     92             String s=scanner.nextLine();
     93             String []ss=s.split("   ");
     94             
     95             try {
     96                 map.put(ss[0],ss[1]);
     97             } catch (ArrayIndexOutOfBoundsException e) {                
     98             }    
     99             
    100         }
    101     }
    102     public class Actionlistener implements ActionListener {
    103 
    104         @Override
    105         public void actionPerformed(ActionEvent e) {
    106             // TODO Auto-generated method stub
    107 
    108         }
    109 
    110     }
    111 
    112 }
    View Code
  • 相关阅读:
    练习课(二)
    html5,实例开发代码
    html,移动端代码
    html5,导航
    html5,表格与框架综合布局
    html5,表格
    HTML5,添加图片
    HTML5,超级链接
    access链接最原始代码,两种
    显示刚刚添加的最后一条数据,access,选择语句,select
  • 原文地址:https://www.cnblogs.com/WINDZLY/p/9945251.html
Copyright © 2011-2022 走看看