Java实现 import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel;public class studentmanagefra
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class studentmanageframe extends JPanel {
static final int WIDTH = 400;
static final int HEIGHT = 200;
//JFrame buttonframe;
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);
}
public studentmanageframe(){
JFrame studentframe = new JFrame("学生信息管理系统");
//buttonframe.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.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 sq1 = "select * from studentinfo where class = '一班' and major = '计算机'";
studentinfo info = new studentinfo("计算机一班学生信息系统", sql);
}
});
computertwo.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent Event){
String sq1 = "select * from studentinfo where class = '二班' and major = '计算机'";
studentinfo info = new studentinfo("计算机二班学生信息系统", sql);
}
});
computerthree.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent Event){
String sq1 = "select * from studentinfo where class = '三班' and major = '计算机'";
studentinfo info = new studentinfo("计算机三班学生信息系统", sql);
}
});
bioone.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent Event){
String sq1 = "select * from studentinfo where class = '一班' and major = '生物系'";
studentinfo info = new studentinfo("生物一班学生信息系统", sql);
}
});
mechone.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent Event){
String sq1 = "select * from studentinfo where class = '一班' and major = '机械'";
studentinfo info = new studentinfo("机械一班学生信息系统", sql);
}
});
mechtwo.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent Event){
String sq1 = "select * from studentinfo where class = '二班' and major = '机械'";
studentinfo info = new studentinfo("机械二班学生信息系统", sql);
}
});
mechthree.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent Event){
String sq1 = "select * from studentinfo where class = '三班' and major = '机械'";
studentinfo info = new studentinfo("机械三班学生信息系统", sql);
}
});
}
}
