《用Java编写的英汉小词典》是一款基于Java编程语言开发的实用英语学习工具,旨在帮助用户便捷地查询英文单词的中文释义。它不仅提供了丰富的词汇量,还具备简洁友好的界面设计和高效的记忆功能,助力英语学习者提高词汇掌握能力。
package shiyan;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.Statement;
import javax.swing.*;
public class AddWin extends JFrame implements ActionListener {
private static MySqlUtils mySqlUtils = new MySqlUtils();
JTextField 添加英语单词_文本条, 添加汉语解释_文本条;
JButton addbtn, cancelbtn;
Connection Con = null;
Statement Stmt = null;
public AddWin() {
super(添加单词);
this.setBounds(250, 250, 250, 200);
this.setVisible(true);
JPanel p1 = new JPanel();
p1.add(new Label(输入要添加的单词:));
添加英语单词_文本条 = new JTextField(20);
p1.add(添加英语单词_文本条);
p1.add(new Label(输入添加的单词的解释:));
添加汉语解释_文本条 = new JTextField(20);
p1.add(添加汉语解释_文本条);
addbtn = new JButton(提交);
cancelbtn = new JButton(取消);
p1.add(addbtn);
p1.add(cancelbtn);
this.add(p1);
addbtn.addActionListener(this);
cancelbtn.addActionListener(this);
this.validate();
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == addbtn) {
if (添加英语单词_文本条.getText().equals() || 添加汉语解释_文本条.getText().equals()) {
JOptionPane.showMessageDialog(this, 添加的单词或解释不能为空~, 警告, JOptionPane.WARNING_MESSAGE);
} else {
try {
Word word = new Word();
word.setEnglish(添加英语单词_文本条.getText());
word.setChinese(添加汉语解释_文本条.getText());
mySqlUtils.insert(word);
添加英语单词_文本条.setText();
添加汉语解释_文本条.setText();
} catch (Exception ee) {
}
}
} else if (e.getSource() == cancelbtn) {
dispose();
}
}
}