纯干货,直接展示。
界面展示:
Java源码:
package 暑假作业1;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Addframe extends JFrame {
private JPanel contentPane;
private JTextField textField;
private JTextField textField_1;
/**
* Launch the application.
*/
// public static void main(String[] args) {
// EventQueue.invokeLater(new Runnable() {
// public void run() {
// try {
// Addframe frame = new Addframe();
// frame.setVisible(true);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// });
// }
/**
* Create the frame.
*/
public Addframe() {
setTitle("\u529E\u516C\u7528\u54C1\u7C7B\u522B");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblNewLabel = new JLabel("\u7C7B\u522B\u7F16\u7801");
lblNewLabel.setBounds(104, 61, 54, 26);
contentPane.add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("\u7C7B\u522B\u540D\u79F0");
lblNewLabel_1.setBounds(104, 110, 54, 26);
contentPane.add(lblNewLabel_1);
textField = new JTextField();
textField.setBounds(171, 60, 155, 29);
contentPane.add(textField);
textField.setColumns(10);
textField_1 = new JTextField();
textField_1.setBounds(171, 109, 155, 29);
contentPane.add(textField_1);
textField_1.setColumns(10);
JButton btnNewButton = new JButton("\u4FDD\u5B58");// 保存
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String st1 = textField.getText();
String st2 = textField_1.getText();
if(st1.equals("")||st2.equals("")) {
JOptionPane.showConfirmDialog(null, "插入为空!", "提示", JOptionPane.PLAIN_MESSAGE);
}else {
Dao dao = new Dao();
int result = dao.Add(st1, st2);
if (result > 0) {
JOptionPane.showConfirmDialog(null, "插入成功!", "提示", JOptionPane.PLAIN_MESSAGE);
Mainframe mainframe=new Mainframe();
mainframe.setVisible(true);
Addframe.this.dispose();
} else {
JOptionPane.showConfirmDialog(null, "插入失败!", "提示", JOptionPane.PLAIN_MESSAGE);
}
}
textField.setText("");
te