JAVA学生管理系统 第4页

JAVA学生管理系统 第4页
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;

/**
 * 课程信息综合管理类
 * 提供主界面,供其他类继承
 */
public class CourseInfo extends JFrame implements ActionListener{
 Container contentPane;
 JPanel centerPanel = new JPanel();
 JPanel upPanel = new JPanel();
 JPanel downPanel = new JPanel();

 //框架的大小
 Dimension faceSize = new Dimension(800, 500);

 JLabel jLabel1 = new JLabel();
 JLabel jLabel2 = new JLabel();
 JLabel jLabel3 = new JLabel();
 JLabel jLabel4 = new JLabel();
 JLabel jLabel5 = new JLabel();
 JLabel jLabel6 = new JLabel();

 JTextField cNum = new JTextField(15);
 JTextField cName = new JTextField(15);
 JTextField cTeacher = new JTextField(15);
 JTextField cType = new JTextField(15);
 JTextField cTime = new JTextField(15);
 JTextField cPlace = new JTextField(15);

 JButton searchInfo = new JButton();
 JButton addInfo = new JButton();
 JButton modifyInfo = new JButton();
 JButton deleteInfo = new JButton();
 JButton clearInfo = new JButton();
 JButton saveInfo = new JButton();
 JButton eixtInfo = new JButton();

 GridBagLayout girdBag = new GridBagLayout();
 GridBagConstraints girdBagCon;
 public CourseInfo() {this.setSize(faceSize);
  //设置标题
  this.setTitle("课程综合信息管理");
  this.setResizable(false);
  //设置程序图标
  this.setIconImage(getImage("icon.gif"));
  try {
   Init();
  }
  catch(Exception e) {
   e.printStackTrace();
  }
 }

 public void Init() throws Exception {
  contentPane = this.getContentPane();
  contentPane.setLayout(new BorderLayout());

  //中部面板的布局
  centerPanel.setLayout(girdBag);

  jLabel1.setText("课程编码:");
  jLabel1.setFont(new Font("Dialog",0,12));
  girdBagCon = new GridBagConstraints();
  girdBagCon.gridx = 0;
  girdBagCon.gridy = 0;
  girdBagCon.insets = new Insets(10,10,10,1);
  girdBag.setConstraints(jLabel1,girdBagCon);
  centerPanel.add(jLabel1);

  girdBagCon = new GridBagConstraints();
  girdBagCon.gridx = 1;
  girdBagCon.gridy = 0;
  girdBagCon.insets = new Insets(10,1,10,15);
  girdBag.setConstraints(cNum,girdBagCon);
  centerPanel.add(cNum);

  jLabel2.setText("课程名称:");
  jLabel2.setFont(new Font("Dialog",0,12));
  girdBagCon = new GridBagConstraints();
  girdBagCon.gridx = 2;
  girdBagCon.gridy = 0;
  girdBagCon.insets = new Insets(10,15,10,1);
  girdBag.setConstraints(jLabel2,girdBagCon);
  centerPanel.add(jLabel2);

  girdBagCon = new GridBagConstraints();
  girdBagCon.gridx = 3;
  girdBagCon.gridy = 0;
  girdBagCon.insets = new Insets(10,1,10,10);
  girdBag.setConstraints(cName,girdBagCon);
  centerPanel.add(cName);

  jLabel3.setText("授课老师:");
  jLabel3.setFont(new Font("Dialog",0,12));
  girdBagCon = new GridBagConstraints();
  girdBagCon.gridx = 0;
  girdBagCon.gridy = 1;
  girdBagCon.insets = new Insets(10,10,10,1);
  girdBag.setConstraints(jLabel3,girdBagCon);
  centerPanel.add(jLabel3);

  girdBagCon = new GridBagConstraints();
  girdBagCon.gridx = 1;
  girdBagCon.gridy = 1;
  girdBagCon.insets = new Insets(10,1,10,15);
  girdBag.setConstraints(cTeacher,girdBagCon);
  centerPanel.add(cTeacher);

  jLabel4.setText("课程类别:");
  jLabel4.setFont(new Font("Dialog",0,12));
  girdBagCon = new GridBagConstraints();
  girdBagCon.gridx = 2;
  girdBagCon.gridy = 1;
  girdBagCon.insets = new Insets(10,15,10,1);
  girdBag.setConstraints(jLabel4,girdBagCon);
  centerPanel.add(jLabel4);

  girdBagCon = new GridBagConstraints();
  girdBagCon.gridx = 3;
  girdBagCon.gridy = 1;
  girdBagCon.insets = new Insets(10,1,10,10);
  girdBag.setConstraints(cType,girdBagCon);
  centerPanel.add(cType);

  jLabel5.setText("上课时间:");
  jLabel5.setFont(new Font("Dialog",0,12));
  girdBagCon = new GridBagConstraints();
  girdBagCon.gridx = 0;
  girdBagCon.gridy = 2;
  girdBagCon.insets = new Insets(10,10,10,1);
  girdBag.setConstraints(jLabel5,girdBagCon);
  centerPanel.add(jLabel5);

  girdBagCon = new GridBagConstraints();
  girdBagCon.gridx = 1;
  girdBagCon.gridy = 2;
  girdBagCon.insets = new Insets(10,1,10,15);
  girdBag.setConstraints(cTime,girdBagCon);
  centerPanel.add(cTime);

  jLabel6.setText("上课地点:");
  jLabel6.setFont(new Font("Dialog",0,12));
  girdBagCon = new GridBagConstraints();
  girdBagCon.gridx = 2;
  girdBagCon.gridy = 2;
  girdBagCon.insets = new Insets(10,15,10,1);
  girdBag.setConstraints(jLabel6,girdBagCon);
  centerPanel.add(jLabel6);

  girdBagCon = new GridBagConstraints();
  girdBagCon.gridx = 3;
  girdBagCon.insets = new Insets(10,1,10,10);
  girdBag.setConstraints(cPlace,girdBagCon);
  centerPanel.add(cPlace);

  contentPane.add(centerPanel,BorderLayout.CENTER);
 }

 /**
  * 下部面板的布局
  */
 public void downInit(){
  searchInfo.setText("查询");
  searchInfo.setFont(new Font("Dialog",0,12));
  downPanel.add(searchInfo);
  addInfo.setText("增加");
  addInfo.setFont(new Font("Dialog",0,12));
  downPanel.add(addInfo);
  modifyInfo.setText("修改");
  modifyInfo.setFont(new Font("Dialog",0,12));
  downPanel.add(modifyInfo);
  deleteInfo.setText("删除");
  deleteInfo.setFont(new Font("Dialog",0,12));
  downPanel.add(deleteInfo);
  saveInfo.setText("保存");
  saveInfo.setFont(new Font("Dialog",0,12));
  downPanel.add(saveInfo);
  clearInfo.setText("清空");
  clearInfo.setFont(new Font("Dialog",0,12));
  downPanel.add(clearInfo);
  eixtInfo.setText("退出");
  eixtInfo.setFont(new Font("Dialog",0,12));
  downPanel.add(eixtInfo);

  contentPane.add(downPanel,BorderLayout.SOUTH);

  //添加事件侦听
  searchInfo.addActionListener(this);
  addInfo.addActionListener(this);
  modifyInfo.addActionListener(this);
  deleteInfo.addActionListener(this);
  saveInfo.addActionListener(this);
  clearInfo.addActionListener(this);
  eixtInfo.addActionListener(this);
 }

 /**
  * 事件处理
  */
 public void actionPerformed(ActionEvent e) {
  Object obj = e.getSource();
  if (obj == searchInfo) { //查询
  }
  else if (obj == addInfo) { //增加
  }
  else if (obj == modifyInfo) { //修改
  }
  else if (obj == deleteInfo) { //删除
  }
  else if (obj == saveInfo) { //保存 
  }
www.751com.cn
  cName.setText(null);
  cTeacher.setText(null);
  cType.setText(null);
  cTime.setText(null);
  cPlace.setText(null);
 }

 /**
  * 通过给定的文件名获得图像
  */
 Image getImage(String filename) {
  URLClassLoader urlLoader = (URLClassLoader)this.getClass().
   getClassLoader();
  URL url = null;
  Image image = null;
  url = urlLoader.findResource(filename);
  image = Toolkit.getDefaultToolkit().getImage(url);
  MediaTracker mediatracker = new MediaTracker(this);
  try {
   mediatracker.addImage(image, 0);
   mediatracker.waitForID(0);
  }
  catch (InterruptedException _ex) {
   image = null;
  }
  if (mediatracker.isErrorID(0)) {
   image = null;
  }
  return image;
 }
}

上一页  [1] [2] [3] [4] [5] [6] [7] [8] 下一页

  • 上一篇文章:
  • 下一篇文章:
  • Copyright © 2007-2012 www.chuibin.com 六维论文网 版权所有