java英文字典代码 java中的字典是什么( 二 )


差不多就有点象平时我们在算法中提到的HashTable吧 。
我们老师有期末课程设计,关于Java源程序代码的英汉字典的,跪求您的帮忙我只有这么多的财富值,我可充话package zyhz;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import java.io.*;
importcom.sun.media.sound.*;
public class Dictionary {
public Dictionary() {
}
public static void main(String[] args)
{
dicFrame frame = new dicFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class dicFrame extends JFrame
{
public dicFrame()
{
setTitle("Dictionary");
setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
panel = new JPanel();
add(panel);
//菜单栏
JMenu fileMenu = new JMenu("文件");
JMenuItem ECItem = new JMenuItem("英汉字典");
ECItem.addActionListener(new
AbstractAction(){
public void actionPerformed(ActionEvent event)
【java英文字典代码 java中的字典是什么】{
text2.setText("请在上面输入英文?。。。?);
}
});
JMenuItem CEItem = new JMenuItem("汉英字典");
CEItem.addActionListener(new
AbstractAction(){
public void actionPerformed(ActionEvent event)
{
text2.setText("请在上面输入中文?。。。?);
}
});
//备份词库
JMenuItem BackupItem = new JMenuItem("备份词库");
BackupItem.addActionListener(new
AbstractAction(){
public void actionPerformed(ActionEvent event)
{
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException ce) {
System.out.println(ce);
}
url = "jdbc:odbc:test";
String fileName;
chooser = new JFileChooser();
frame = new JFrame();
chooser.setDialogTitle("备份词库为");
try {
flag = chooser.showSaveDialog(frame);
} catch (HeadlessException h) {
System.out.println("Save File Dialog ERROR!");
}
if (flag == JFileChooser.APPROVE_OPTION) {
f = chooser.getSelectedFile();
fileName = chooser.getName(f);
fileName = chooser.getSelectedFile().getPath();
try {
File saveFile = new File(fileName);
FileWriter fw = new FileWriter(saveFile);
try
{
con = DriverManager.getConnection(url);
s = con.createStatement();
rs = s.executeQuery("SELECT * from 字典 ");
while (rs.next()) {
String a = rs.getString("单词");
String b = rs.getString("词语解释");
text2.append(a+b+"\n");
}
rs.close();
} catch (Exception ea) {
text2.setText("查询数据失败");
}
fw.write(text2.getText());
fw.close();
} catch (IOException ec) {
text2.setText(fileName);
}
text2.setText("词库备份成功!");
}
}
});
fileMenu.add(ECItem);
fileMenu.add(CEItem);
fileMenu.add(BackupItem);
fileMenu.addSeparator();
//退出监听器
fileMenu.add(new
AbstractAction("退出")
{
public void actionPerformed(ActionEvent event)
{
System.exit(0);
}
});
JMenu editMenu = new JMenu("编辑");
JMenuItem addItem = new JMenuItem("添加词汇");
addItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A,InputEvent.CTRL_MASK));
//菜单栏增加监听器
addItem.addActionListener(new
AbstractAction(){
public void actionPerformed(ActionEvent event)
{
if(text1.getText().equals(""))
text2.setText("没有输入内容!请重新增加?。。?);
else
{
String s=text1.getText().trim();
String s1=text2.getText().trim();
text2.setText(new add().jadd(text1.getText().trim(),text2.getText().trim()));

推荐阅读