📄 studentmanageframe.java
字号:
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.util.Vector;
import javax.swing.*;
///这是一个学生信息系统的入口框架类。
///studentframe是顶层窗口框架。
///通过七个按钮控件来分别可以进入到不同班级、不同系的学生信息系统中。
///七个按钮控件分别产生七个不同的动作事件简史事件,分别进入不同的信息系统。
///在布局方面有两个布局管理器,一个是lay即网格组布局。一个是jp是GridLayout布局。
///通过不同的SQL语句进入不同的班级和系的管理系统。
class studentmanageframe extends JPanel
{
private static final long serialVersionUID = 1L;
static final int WIDTH=400;
static final int HEIGHT=200;
JFrame studentframe;
public studentmanageframe()
{
studentframe=new JFrame();
studentframe.setTitle("学生信息管理系统");
studentframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
studentframe.setSize(WIDTH,HEIGHT);
Toolkit kit=Toolkit.getDefaultToolkit();
Dimension screenSize=kit.getScreenSize();
int width=screenSize.width;
int height=screenSize.height;
int x=(width-WIDTH)/2;
int y=(height-HEIGHT)/2;
studentframe.setLocation(x,y);
studentframe.setVisible(true);
studentframe.setResizable(false);
studentframe.add(this, BorderLayout.CENTER);
JButton computerone=new JButton("计算机系一班学生信息系统");
JButton computertwo=new JButton("计算机系二班学生信息系统");
JButton computerthree=new JButton("计算机系三班学生信息系统");
JButton bioone=new JButton("生 物 系一班学生信息系统");
JButton mechone=new JButton("机械系一班学生信息系统");
JButton mechtwo=new JButton("机械系二班学生信息系统");
JButton mechthree=new JButton("机械系三班学生信息系统");
JLabel title=new JLabel("学生信息系统主界面");
JLabel banket1=new JLabel();
JLabel banket2=new JLabel();
GridBagLayout lay=new GridBagLayout();
setLayout(lay);
GridBagConstraints constraints=new GridBagConstraints();
constraints.fill=GridBagConstraints.NONE;
constraints.anchor=GridBagConstraints.EAST;
constraints.weightx=2;
constraints.weighty=5;
JPanel jp=new JPanel();
jp.setLayout(new GridLayout(1,3));
jp.add(banket1);
jp.add(title);
jp.add(banket2);
studentframe.add(jp,BorderLayout.NORTH);
add(computerone,constraints,0,1,1,1); //使用网格组布局添加控件
add(computertwo,constraints,0,2,1,1);
add(computerthree,constraints,0,3,1,1);
add(bioone,constraints,0,4,1,1);
add(mechone,constraints,1,1,1,1);
add(mechtwo,constraints,1,2,1,1);
add(mechthree,constraints,1,3,1,1);
///单击这个按钮,进入到计算机系一班学生信息系统
computerone.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent Event)
{
String sql="select * from studentinfo where class='一班'and major='计算机系'";
studentinfo info=new studentinfo("计算机系一班学生信息系统",sql);
}
});
///单击这个按钮,进入到计算机系二班学生信息系统
computertwo.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent Event)
{
String sql="select * from studentinfo where class2='二班'and major='计算机系'";
studentinfo studentinformation=new studentinfo("计算机系二班学生信息系统",sql);
}
});
///单击这个按钮,进入到计算机系三班学生信息系统
computerthree.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent Event)
{
String sql="select * from studentinfo where class2='三班'and major='计算机系'";
studentinfo studentinformation=new studentinfo("计算机系三班学生信息系统",sql);
}
});
///单击这个按钮,进入到生物系一班学生信息系统
bioone.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent Event)
{
String sql="select * from studentinfo where class2='一班'and major='生物系'";
studentinfo studentinformation=new studentinfo("生物系一班学生信息系统",sql);
}
});
///单击这个按钮,进入到机械机系一班学生信息系统
mechone.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent Event)
{
String sql="select * from studentinfo where class2='一班'and major='机械系'";
studentinfo studentinformation=new studentinfo("机械系一班学生信息系统",sql);
}
});
///单击这个按钮,进入到机械系二班学生信息系统
mechtwo.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent Event)
{
String sql="select * from studentinfo where class2='二班'and major='机械系'";
studentinfo studentinformation=new studentinfo("机械系二班学生信息系统",sql);
}
});
///单击这个按钮,进入到机械系三班学生信息系统
mechthree.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent Event)
{
String sql="select * from studentinfo where class2='三班'and major='机械系'";
studentinfo studentinformation=new studentinfo("机械系三班学生信息系统",sql);
}
});
}
public void add(Component c,GridBagConstraints constraints,int x,int y,int w,int h)
{
constraints.gridx=x;
constraints.gridy=y;
constraints.gridwidth=w;
constraints.gridheight=h;
add(c,constraints);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -