📄 studentmanager.java~5~
字号:
/////////////主类///////////////package student;import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;import java.util.Hashtable;public class StudentManager extends JFrame implements ActionListener{ StudentSituation 基本信息录入=null; //创建基本信息录入界面 ModifySituation 基本信息修改=null; //创建基本信息修改界面 Inquest 课本信息查询=null; Delete 基本信息删除=null; JMenuBar bar; JMenu fileMenu; JMenuItem 录入,修改 ,查询,删除; Container con=null; Hashtable 基本信息=null;//存放基本信息的散列表 File file=null;//存放散列表的文件 CardLayout card=null;//卡片式布局 JLabel lable=null;//欢迎语标签 JPanel pCenter; public StudentManager() { 录入=new JMenuItem("录入学生基本信息"); 修改=new JMenuItem("修改学生基本信息"); 查询=new JMenuItem("查询学生基本信息"); 删除=new JMenuItem("删除学生基本信息"); bar=new JMenuBar(); fileMenu=new JMenu("菜单选项"); fileMenu.add(录入); fileMenu.add(修改); fileMenu.add(查询); fileMenu.add(删除); bar.add(fileMenu); setJMenuBar(bar); lable=new JLabel("欢迎使用学生基本信息管理系统",JLabel.CENTER); lable.setFont(new Font("TimesRoman",Font.BOLD,24)); lable.setForeground(Color.red); 基本信息=new Hashtable(); 录入.addActionListener(this); 修改.addActionListener(this); 查询.addActionListener(this); 删除.addActionListener(this); card=new CardLayout(); con=getContentPane(); 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 StudentSituation(file); 基本信息修改=new ModifySituation(file); 基本信息查询=new Inquest(this.file); 基本信息删除=new Delete(file); pCenter.add("欢迎语界面",lable); pCenter.add("录入界面",基本信息录入); pCenter.add("修改界面",基本信息修改); pCenter.add("删除界面",基本信息删除); con.add(pCenter,BorderLayout.CENTER); con.validate(); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);} }); setVisible(true); setBounds(100,50,420,380); validate(); } public void actionPerformed(ActionEvent e) { if(e.getSource()==界面) { card.show(pCenter,"录入界面"); } else if(e.getSource()==修改) { card.show(pCenter,"修改界面"); } else if(e.getSource()==查询) {//“基本信息查询”窗口设置为独立窗口,以便于用户进行查询。 基本信息查询.setVisible(true); } else if(e.getSource()==删除) { card.show(pCenter,"删除界面"); } } public static void main(String args[]) { new StudentManager(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -