上传者: xiaoxaioyaya 
                                    |
                                    上传时间: 2021-12-07 20:14:38
                                    |
                                    文件大小: 31KB
                                    |
                                    文件类型: -
                                
                            
                                
                            
                                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();
  }
 }
 
}