📄 jdbc.java~5~
字号:
package student;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import java.util.*;
import java.text.SimpleDateFormat;
public class Jdbc
{
public static void main(String args[])
{
myframe mf=new myframe();
}
}
class myframe extends JFrame implements ActionListener
{
MenuBar mb;
Menu m1,m2,m3;
Label lb1=new Label("学籍管理系统",Label.CENTER);
Label lb2=new Label("---Version 1.0",Label.CENTER);
Label lb3=new Label("06431班朱新军 张佳制作",Label.CENTER);
Label lb4=new Label("--指导教师:赵建超",Label.CENTER);
MenuItem mi1,mi2,mi3,mi4,mi5,mi6,mi7;
myframe()
{
setTitle("*****学籍管理系统--制作:网络专业06431班朱新军 张佳*****");
mb=new MenuBar();
m1=new Menu("学生管理");
m2=new Menu("课程管理");
m3=new Menu("系统");
mb.add(m1);
mb.add(m2);
mb.add(m3);
mi1=new MenuItem("学生查询");
mi2=new MenuItem("学生录入");
mi3=new MenuItem("退出系统");
mi4=new MenuItem("课程查询");
mi5=new MenuItem("课程修改");
mi6=new MenuItem("课程添加");
mi7=new MenuItem("分数录入");
m1.add(mi1);
m1.add(mi2);
m3.add(mi3);
m1.add(mi7);
Container con=this.getContentPane();
con.add(lb1);con.add(lb2);
con.add(lb3);con.add(lb4);
con.setLayout(new GridLayout(4,1,1,1));
lb1.setFont(new Font("黑体",Font.BOLD,20));
lb1.setForeground(Color.blue);
lb2.setFont(new Font("黑体",Font.BOLD,20));
lb2.setForeground(Color.red);
lb3.setFont(new Font("黑体",Font.BOLD,20));
lb3.setForeground(Color.cyan);
lb4.setFont(new Font("黑体",Font.BOLD,20));
lb4.setForeground(Color.black);
mi1.addActionListener(this);
mi2.addActionListener(this);
mi3.addActionListener(this);
mi4.addActionListener(this);
mi5.addActionListener(this);
mi6.addActionListener(this);
mi7.addActionListener(this);
m2.add(mi4);
m2.add(mi5);
m2.add(mi6);
this.setMenuBar(mb);
setBounds(300,300,460,300);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==mi1)
{
xscx xs=new xscx();
xs.setBounds(400,350,300,300);
xs.setVisible(true);
}
else if(e.getSource()==mi2)
{
xstj xs=new xstj();
xs.setBounds(430,350,220,300);
xs.setVisible(true);
}
else if(e.getSource()==mi3)
{
dispose();
System.exit(0);
}
else if(e.getSource()==mi4)
{
kccx kc=new kccx();
kc.setBounds(400,350,300,300);
kc.setVisible(true);
}
else if(e.getSource()==mi5)
{
kcxg xg=new kcxg();
xg.setBounds(400,350,300,300);
xg.setVisible(true);
}
else if(e.getSource()==mi7)
{
fslr fs=new fslr();
fs.setBounds(400,350,300,300);
fs.setVisible(true);
}
else
{
kctj k1=new kctj();
k1.setBounds(430,350,220,240);
k1.setVisible(true);
}
}
}
//学生信息添加
class xstj extends JFrame implements ActionListener
{
JLabel lb1,lb2,lb3;
JTextField tf1,tf2,tf3;
JButton bt1,bt2;
xstj()
{
setTitle("学生信息添加");
this.getContentPane().setLayout(null);
lb1=new JLabel("学号");
tf1=new JTextField(10);
lb2=new JLabel("姓名");
tf2=new JTextField(10);
lb3=new JLabel("生日");
tf3=new JTextField(10);
bt1=new JButton("插入");
bt2=new JButton("取消");
lb1.setBackground(Color.cyan);
lb1.setFont(new Font("宋体",Font.BOLD,12));
lb2.setBackground(Color.cyan);
lb2.setFont(new Font("宋体",Font.BOLD,12));
lb3.setBackground(Color.cyan);
lb3.setFont(new Font("宋体",Font.BOLD,12));
tf1.setBackground(Color.pink);
tf1.setFont(new Font("宋体",Font.BOLD,12));
tf2.setBackground(Color.pink);
tf2.setFont(new Font("宋体",Font.BOLD,12));
tf3.setBackground(Color.pink);
tf3.setFont(new Font("宋体",Font.BOLD,12));
bt1.setBackground(Color.green);
bt1.setFont(new Font("楷书",Font.BOLD,12));
bt2.setBackground(Color.green);
bt2.setFont(new Font("楷书",Font.BOLD,12));
lb1.setBounds(0,40,100,30);tf1.setBounds(100,40,100,30);
lb2.setBounds(0,70,100,30);tf2.setBounds(100,70,100,30);
lb3.setBounds(0,100,100,30);tf3.setBounds(100,100,100,30);
bt1.setBounds(30,220,80,30);bt2.setBounds(120,220,80,30);
Container con=this.getContentPane();
con.add(lb1);con.add(tf1);
con.add(lb2);con.add(tf2);
con.add(lb3);con.add(tf3);
con.add(bt1);con.add(bt2);
bt1.addActionListener(this);
bt2.addActionListener(this);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
Database DB=new Database();
if(e.getSource()==bt1)
{
try
{
if(tf1.getText().length()!=0 && tf2.getText().length()!=0 && tf3.getText().length()!=0)
{
String s=new String();
String sql="insert into chengjibiao values("+Integer.parseInt(tf1.getText())+
",'"+tf2.getText()+"','"+tf3.getText()+"')";
DB.OpenConn();
DB.executeUpdate(sql);
JOptionPane.showMessageDialog(this,"学生信息添加成功!!","学生信息添加对话框",JOptionPane.INFORMATION_MESSAGE);
tf1.setText(null);tf2.setText(null);tf3.setText(null);
}
else
JOptionPane.showMessageDialog(this,"输入基本信息错误!!","学生信息添加对话框",JOptionPane.INFORMATION_MESSAGE);
}
catch(Exception ex)
{
System.out.println(e);
JOptionPane.showMessageDialog(this,"未找到该学生的信息","课程查找对话框",JOptionPane.INFORMATION_MESSAGE);
}
finally
{
DB.closeStmt();
DB.closeConn();
}
}
if(e.getSource()==bt2)
setVisible(false);
}
}
//学生查询
class xscx extends JFrame implements ActionListener
{
JLabel lb1;
JTextField tf1;
JButton bt1,bt2;
xscx()
{
setTitle("学生信息查询");
lb1=new JLabel("请输入学生的学号:");
tf1=new JTextField(7);
bt1=new JButton("查询");
bt2=new JButton("取消");
Container con=this.getContentPane();
con.setLayout(null);
lb1.setBackground(Color.cyan);
lb1.setFont(new Font("宋体",Font.BOLD,12));
tf1.setBackground(Color.orange);
tf1.setFont(new Font("宋体",Font.BOLD,12));
bt1.setBackground(Color.pink);
bt1.setFont(new Font("宋体",Font.BOLD,12));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -