📄 studentadd.java
字号:
package collegems;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import dbcon.*;
public class StudentAdd extends JDialog implements ActionListener{
public String sex;
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
final StudentAdd studentadd=new StudentAdd();
studentadd.setSize(460,330);
studentadd.setVisible(true);
}
public void actionPerformed(ActionEvent e4) {
// TODO 自动生成方法存根
sex=e4.getActionCommand();
}
public StudentAdd() {
super();
setModal(true);
setTitle("学生信息输入");
getContentPane().setLayout(null);
final JLabel label = new JLabel();
label.setText("学号:");
label.setBounds(80, 55, 60, 15);
getContentPane().add(label);
final JTextField Num = new JTextField();
Num.setBounds(126, 53, 95, 20);
getContentPane().add(Num);
final JLabel label_1 = new JLabel();
label_1.setText("出生年月:");
label_1.setBounds(254, 55, 76, 15);
getContentPane().add(label_1);
final JTextField Birthday = new JTextField();
Birthday.setBounds(320, 53, 95, 20);
getContentPane().add(Birthday);
final JLabel label_2 = new JLabel();
label_2.setText("姓名:");
label_2.setBounds(80, 94, 60, 15);
getContentPane().add(label_2);
final JTextField Name = new JTextField();
Name.setBounds(126, 92, 95, 20);
getContentPane().add(Name);
final JLabel label_3 = new JLabel();
label_3.setText(" 奖学金:");
label_3.setBounds(254, 94, 76, 15);
getContentPane().add(label_3);
final JTextField Money = new JTextField();
Money.setBounds(320, 92, 95, 20);
getContentPane().add(Money);
final JLabel label_4 = new JLabel();
label_4.setText("性别:");
label_4.setBounds(80, 162, 50, 15);
getContentPane().add(label_4);
final JRadioButton radioButton = new JRadioButton("男");
radioButton.setText("男");
radioButton.addActionListener(this);
radioButton.setBounds(126, 158, 50, 23);
getContentPane().add(radioButton);
final JRadioButton radioButton_1 = new JRadioButton("女");
radioButton_1.setText("女");
radioButton_1.addActionListener(this);
radioButton_1.setBounds(177, 158, 44, 23);
getContentPane().add(radioButton_1);
final JLabel label_5 = new JLabel();
label_5.setText("简历:");
label_5.setBounds(237, 162, 60, 15);
getContentPane().add(label_5);
final JTextArea Area = new JTextArea();
Area.setRows(6);
Area.setColumns(15);
Area.setBounds(278, 160, 140, 72);
getContentPane().add(Area);
final JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent arg0) {
if(Num.getText()==null)
{
JOptionPane.showMessageDialog(null, "请重新输入!");
//return;
}else{
DbCon db=new DbCon();
String sql="insert into 学生表(学号,姓名,性别,出生年月,简历,奖学金) values('"+Num.getText()+"','"+Name.getText()+"','"+sex+"','"+Birthday.getText()+"','"+Area.getText()+"','"+Money.getText()+"')";
db.DbManage(sql);
System.out.print(sql);
System.out.println("插入成功!");
Num.setText("");
Name.setText("");
Birthday.setText("");
Area.setText("");
Money.setText("");
}
}
});
button.setText("确认");
button.setBounds(94, 247, 82, 23);
getContentPane().add(button);
final JButton button_1 = new JButton();
button_1.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
dispose();
}
});
button_1.setText("取消");
button_1.setBounds(209, 247, 76, 23);
getContentPane().add(button_1);
final JButton button_2 = new JButton();
button_2.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent arg0) {
Num.setText("");
Name.setText("");
Birthday.setText("");
Area.setText("");
Money.setText("");
}
});
button_2.setText("清空");
button_2.setBounds(320, 247, 76, 23);
getContentPane().add(button_2);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -