2 m0 37350967 m0_37350967 于 2017.01.16 15:42 提问

用Java编写一个简易的英汉词典 大神们可以给我注释一下吗

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

import java.io.*;

import java.util.*;

public class Test extends JFrame{

private JTextField input; 

private JButton search; 

private JTextArea output; 



public EC_Dictionary(){ 

    super("英汉词典"); 



    input = new JTextField(14); 

    search = new JButton("查询"); 

    search.setFont(new Font("宋体", Font.PLAIN, 15)); 

    search.addActionListener(new ActionListener(){ 

        public void actionPerformed(ActionEvent e){ 

            searchWords(); 

        } 

    }); 

    output = new JTextArea(10,18); 

    output.setEditable(false); 

    output.setFont(new Font("宋体", Font.PLAIN, 18)); 

    output.setForeground(Color.RED); 



    setLayout(new FlowLayout(FlowLayout.CENTER, 5, 20)); 

    getContentPane().add(input); 

    getContentPane().add(search); 

    getContentPane().add(output); 



    setSize(300,320); 

    setResizable(false); 

    setLocationRelativeTo(null); 

    setDefaultCloseOperation(3); 

    setVisible(true); 

} 



//查询单词 

public void searchWords(){ 

    try { 

        BufferedReader br = new BufferedReader(new FileReader("dictionary.txt")); 

        String line, inputWord; 

        boolean isFound = false; 



        inputWord = input.getText(); 

        if(inputWord.equals("")){ 

            return; 

        } 



        while((line = br.readLine()) != null){ 

            Scanner in = new Scanner(line); 



            if(in.next().equals(inputWord)){ 

                int offset = inputWord.length(); 

                output.setText("\n\n\n\n"+line.substring(offset)); 

                isFound = true; 

                break; 

            } 

        } 



        if(!isFound){ 

            output.setText("没找到相应项>..<"); 

        } 

    } 

    catch (Exception ex) { 

        ex.printStackTrace(); 

    } 

} 



public static void main (String[] args) { 

    new EC_Dictionary(); 

} 

}

2个回答

strongerzhi
strongerzhi   2017.01.16 15:46

这注释不是很全么,哪里不懂?

m0_37350967
m0_37350967   2017.01.16 16:00

老师让我一条一条的注释 注释不来 我刚用这个 没有C币 你肯回答那真是太谢谢了

strongerzhi
strongerzhi 既然是老师的作业,还是认真对待吧,你可以的!
11 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片