求大神幫我做個明片或者教程也可以謝謝了用word2007或者2003也可以謝謝了急事?
lz 你好
代碼還是比較簡單 就是需要一個做好的txt英漢詞典文檔
以下是一個簡單的例子:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
public class EC_Dictionary 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();
}
}
運行效果:
ps:
本程序要用附件中dictionary.txt文檔 lz要把源程序和這個文檔放在同目錄下 才能正常運行
希望能幫助你哈
dictionary.txt大?。?93.68K
已經過百度安全檢測,放心下載
點擊下載