《程序语言综合课程设计》实验报告 - 图文(9)

2019-08-01 23:36

计算机2011级 程序语言综合课程设计

A.2 题目二关键源码

(1) ManagerWindow类的ManagerWindow方法 import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; import java.util.HashMap;

public class ManagerWindow extends JFrame implements ActionListener{ InputStudent 基本信息录入;

ModifySituation 基本信息修改; Inquest 基本信息查询; Delete 基本信息删除; JMenuBar bar; JMenu fileMenu;

JMenuItem 录入,修改,查询,删除,欢迎界面;

HashMap 基本信息=null; File file=null; CardLayout card=null; JLabel label=null; JPanel pCenter;

public ManagerWindow(){

setTitle(\学生管理系统\

录入=new JMenuItem(\录入学生基本信息\ 修改=new JMenuItem(\修改学生基本信息\ 查询=new JMenuItem(\查询学生基本信息\ 删除=new JMenuItem(\删除学生基本信息\ 欢迎界面=new JMenuItem(\欢迎界面\ bar=new JMenuBar();

fileMenu=new JMenu(\菜单选项\ fileMenu.add(录入); fileMenu.add(修改);

38

计算机2011级 程序语言综合课程设计

fileMenu.add(查询); fileMenu.add(删除); fileMenu.add(欢迎界面); bar.add(fileMenu); setJMenuBar(bar);

label=new JLabel(\学籍管理系统\ label.setIcon(new ImageIcon(\ label.setFont(new Font(\隶书\

label.setHorizontalTextPosition(SwingConstants.CENTER); label.setForeground(Color.red);

基本信息=new HashMap(); 录入.addActionListener(this); 修改.addActionListener(this); 查询.addActionListener(this); 删除.addActionListener(this); 欢迎界面.addActionListener(this); card=new CardLayout(); pCenter=new JPanel(); pCenter.setLayout(card); //file=new File(\基本信息.txt\ /*if(!file.exists()){ try{

FileOutputStream out=new FileOutputStream(file);

ObjectOutputStream objectOut=new ObjectOutputStream(out); objectOut.writeObject(基本信息); objectOut.close(); out.close(); }

catch(IOException e){} }*/

基本信息录入=new InputStudent(file); 基本信息修改=new ModifySituation(file); 基本信息查询=new Inquest(file); 基本信息删除=new Delete(file);

39

计算机2011级 程序语言综合课程设计

pCenter.add(\欢迎界面\

pCenter.add(\录入界面\基本信息录入); pCenter.add(\修改界面\基本信息修改); pCenter.add(\删除界面\基本信息删除); add(pCenter,BorderLayout.CENTER); validate(); setVisible(true);

setBounds(100,50,660,580);

setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter(){

public void windowClosing(WindowEvent e){

int n=JOptionPane.showConfirmDialog(null,\确认退出吗?\确认对话框\

JOptionPane.YES_NO_OPTION );

if(n==JOptionPane.YES_OPTION) System.exit(0); }}); validate(); }

public void actionPerformed(ActionEvent e){ if(e.getSource()==录入){

card.show(pCenter,\录入界面\ }

else if(e.getSource()==修改){ 基本信息修改.clearMess(); card.show(pCenter,\修改界面\ }

else if(e.getSource()==查询){ 基本信息查询.clearMess(); 基

询.setLocation(getBounds().x+getBounds().width,getBounds().y); 基本信息查询.setVisible(true); }

40

计算机2011级 程序语言综合课程设计

else if(e.getSource()==删除) card.show(pCenter,\删除界面\ else if(e.getSource()==欢迎界面) card.show(pCenter,\欢迎界面\ }

public static void main(String args[]){ new ManagerWindow(); } }

(2) inquest类的query()方法

public void query() throws SQLException {

String Sno,Sname,Ssex,Sspec,Sgrade,Sborn;

Con=DriverManager.getConnection(\); ResultSet rs=Stmt.executeQuery(\); while (rs.next()) {

Sno=rs.getString(\); Sname=rs.getString(\); Ssex=rs.getString(\); Sspec=rs.getString(\); Sgrade=rs.getString(\); Sborn=rs.getString(\);

if(Sno.trim().equals(学号.getText().trim())) {

姓名.setText(Sname); 性别.setText(Ssex); 专业.setText(Sspec); 年级.setText(Sgrade); 出生.setText(Sborn); search_record=1; break; }

}

41

计算机2011级 程序语言综合课程设计

if(search_record==0) {

姓名.setText(\没有该学生\); } }

42


《程序语言综合课程设计》实验报告 - 图文(9).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:“坚守”作文讲评打印版

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: