📄 addstudent.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class AddStudent extends JFrame
implements ActionListener{
private JTextField stu_name=new JTextField(10);
private JTextField stu_num=new JTextField(10);
private JButton jok=new JButton("添加");
private JButton cancle=new JButton("返回");
private String[] classes={"网络工程","计算机技术",
"软件工程","信管","地信","金融","英语","电子商务",
"国际经济与贸易"
};
private JComboBox jcbo=new JComboBox(classes);
public AddStudent(){
JPanel imformation=new JPanel();
JPanel jtestpanel=new JPanel();
JPanel buttonpanel=new JPanel();
imformation.setBackground(Color.pink);
jtestpanel.setBackground(Color.pink);
buttonpanel.setBackground(Color.pink);
jtestpanel.setLayout(new GridLayout(0,1));
jtestpanel.add(new JLabel("学生姓名"));
jtestpanel.add(stu_name);
jtestpanel.add(new JLabel("学生学号"));
jtestpanel.add(stu_num);
jtestpanel.add(new JLabel("请选择学生的专业"));
jtestpanel.add(jcbo);
imformation.add(jtestpanel);
buttonpanel.add(jok);
buttonpanel.add(cancle);
getContentPane().setLayout(new BorderLayout());
getContentPane().add(imformation,BorderLayout.CENTER);
getContentPane().add(new JLabel("添加学生信息",
SwingConstants.CENTER),BorderLayout.NORTH);
getContentPane().add(buttonpanel,BorderLayout.SOUTH);
stu_name.addActionListener(this);
stu_num.addActionListener(this);
jok.addActionListener(this);
jcbo.addActionListener(this);
cancle.addActionListener(this);
}
/*public static void main(String[] args){
AddStudent frame=new AddStudent();
frame.pack();
frame.setSize(400,200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}*/
public void actionPerformed(ActionEvent e){
if(e.getSource()==jok){
access as=new access();
as.insert(stu_name.getText(),stu_num.getText(),
classes[jcbo.getSelectedIndex()],"student");
stu_name.setText("");
stu_num.setText("");
as.close();
JOptionPane.showMessageDialog(null,"添加成功","",
JOptionPane.INFORMATION_MESSAGE);
}
else if(cancle==e.getSource()){
this.dispose();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -