java编写英汉小词典

时间:2022-04-20 06:57:21
【文件属性】:
文件名称:java编写英汉小词典
文件大小:31KB
文件格式:DOCX
更新时间:2022-04-20 06:57:21
java package shiyan; import java.awt.*; import java.awt.event.*; import java.sql.*; 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().toString()); word.setChinese(添加汉语解释_文本条.getText().toString()); mySqlUtils.insert(word); 添加英语单词_文本条.setText(""); 添加汉语解释_文本条.setText(""); } catch (Exception ee) { } } } else if (e.getSource() == cancelbtn) { dispose(); } } }

网友评论