数据库应用-java+sqlserver(十一)StuPanel
StuPanel:
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class StuPanel extends JPanel implements ActionListener
{
JButton b1,b2,b3;
StuInfo stuinfo;
CourseList courselist;
ChooseList chooselist;
JPanel p1=new JPanel(),
p2=new JPanel(),
p3=new JPanel();
static JPanel pCenter=new JPanel();
static CardLayout card=new CardLayout();
StuPanel(MyFrame f)
{
setLayout(new BorderLayout());
p3.setLayout(new BorderLayout());
pCenter.setLayout(card);
JLabel label=new JLabel("学生选课系统");
label.setFont(new Font("TimesRoman",Font.BOLD,24));
p1.add(label);
b1=new JButton(" 个 人 信 息 ");
b2=new JButton(" 课 程 列 表 ");
b3=new JButton(" 已 选 课 程 ");
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
p2.add(b1);
p2.add(b2);
p2.add(b3);
stuinfo=new StuInfo(f);
courselist=new CourseList();
chooselist=new ChooseList();
pCenter.add("个人信息",stuinfo);
pCenter.add("课程列表",courselist);
pCenter.add("已选课程",chooselist);
p3.add(p2,BorderLayout.NORTH);
p3.add(pCenter,BorderLayout.CENTER);
add(p1,BorderLayout.NORTH);
add(p3,BorderLayout.CENTER);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
card.show(pCenter, "个人信息");
if(e.getSource()==b2)
card.show(pCenter, "课程列表");
if(e.getSource()==b3)
{
ChooseList.updateTable();
card.show(pCenter, "已选课程");
}
}
}