?? studentmanager.java
字號:
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; //聲明一個Hashtable類對象基本信息
File file=null;
CardLayout card=null;
JLabel label=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);
label=new JLabel("歡迎使用學生基本信息管理系統(tǒng)",JLabel.CENTER);
label.setFont(new Font("TimesRoman",Font.BOLD,24));
label.setForeground(Color.red);
基本信息=new Hashtable();//新建一個Hashtable類對象基本信息
錄入.addActionListener(this);
修改.addActionListener(this);
查詢.addActionListener(this);
刪除.addActionListener(this);
card=new CardLayout();
con=getContentPane();
pCenter=new JPanel();
pCenter.setLayout(card);
file=new File("基本信息.txt");//通過File類新建一個記事本文件
//如果該記事本不存在,即往該記事本寫入Hashable類對象基本信息的數(shù)據(jù)
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("歡迎語界面",label);
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();
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -