📄 add.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class Add implements ActionListener{
JFrame fAdd;
JButton commit;
JButton clear;
Container addPane;
Container addPaneMS;
Container addPaneUp;
Container addPaneDown;
JLabel ms;
JLabel workDate;
JLabel regDate;
JLabel content;
JLabel other;
JTextField workDateT, regDateT, contentT, otherT;
ConnectAccess CA2 = new ConnectAccess();
public Add() {
fAdd= new JFrame("Add Frame");
commit = new JButton("添加");
clear = new JButton("重置");
addPane = new JPanel();
addPaneMS = new JPanel();
addPaneUp = new JPanel();
addPaneDown = new JPanel();
ms = new JLabel("添加记录");
regDate = new JLabel("登记日期 : ");
regDateT = new JTextField("");
workDate = new JLabel("应办日期 : ");
workDateT = new JTextField("");
content = new JLabel("日程内容 : ");
contentT = new JTextField("");
other = new JLabel("备注 : ");
otherT = new JTextField("");
fAdd.add(addPane);
addPane.setLayout(new BorderLayout());
addPane.add("North", addPaneMS);
addPane.add("Center", addPaneUp);
addPane.add("South", addPaneDown);
addPaneUp.setLayout(new GridLayout(5, 2));
addPaneDown.setLayout(new GridLayout(1, 2));
addPaneMS.setLayout(new GridLayout(1, 1));
addPaneMS.add(ms, SwingConstants.CENTER);
ms.setForeground(Color.red);
ms.setFont(new Font("TRUE", Font.TRUETYPE_FONT, 20));
addPaneUp.add(regDate);
//addPaneUp.add(new JLabel("登记日期"), SwingConstants.CENTER);
addPaneUp.add(regDateT);
addPaneUp.add(workDate);
addPaneUp.add(workDateT);
addPaneUp.add(content);
addPaneUp.add(contentT);
addPaneUp.add(other);
addPaneUp.add(otherT);
addPaneDown.add(commit);
addPaneDown.add(clear);
commit.addActionListener(this);
clear.addActionListener(this);
CA2.createConn_Direct();
fAdd.setSize(400, 300);
fAdd.show();
}
public void addCommit() {
RecordType rt= new RecordType();
if (workDateT.getText().length()==0 || contentT.getText().length()==0)
JOptionPane.showMessageDialog(null, "请将信息填写完整!");
else {
rt.setRegDate(regDateT.getText());
rt.setWorkDate(workDateT.getText());
rt.setContent(contentT.getText());
rt.setOther(otherT.getText());
CA2.addData(rt);
JOptionPane.showMessageDialog(null, "添加成功!");
}
}
public void addClear() {
regDateT.setText("");
workDateT.setText("");
contentT.setText("");
otherT.setText("");
}
public void actionPerformed(ActionEvent e){
if (e.getSource() == commit)
addCommit();
else if (e.getSource() == clear)
addClear();
}
public static void main(String[] args) {
Add Add1 = new Add();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -