比上一个基于Mysql数据库的完善了一些细节
WindowIO是窗口界面
package JavaStuIO;
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
//class student
class student implements java.io.Serializable{
String number;
String name;
String sex;
String birthday;
String department;
public student(String number,String name,String sex,String birthday,String department){
this.number = number;
this.name = name;
this.sex = sex;
this.birthday = birthday;
this.department = department;
}
}
public class WindowIO extends JFrame {
//private static final long serialVersionUID = -1928970409928880648L;
public static void main(String[] args){
/
TreeMap<String,student> tm = new TreeMap<String,student>(); //treemap
//
File file =new File("E:\\java用文件","file.txt");
if(!file.exists())
{
FileOutputStream fout = null;
ObjectOutputStream oos = null;
try{
fout = new FileOutputStream(file);
oos = new ObjectOutputStream(fout);
oos.writeObject(tm);
fout.close();
oos.close();
System.out.println("write ok!!!");
}catch (Exception er){
er.printStackTrace();
System.out.println("writeobject go die");
}
}
/
JFrame jframe = new JFrame("学生管理系统") ;
JLabel title = new JLabel("这是一个学生管理系统",JLabel.CENTER);
Font font = new Font("",Font.BOLD+Font.PLAIN,15);
title.setFont(font);
ImageIcon icon = new ImageIcon("E:\\java用图片\\look.jpg");
icon.setImage(icon.getImage().getScaledInstance(150, 150, Image.SCALE_DEFAULT));
JLabel pic = new JLabel(icon);
//pic.setSize(10, 10);
//pic.setSize(50,100);?????
//pic.drawImage(???,100, 100, 50, 50,null);
jframe.setSize(450,300);
jframe.setLocation(250,350);
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jframe.setVisible(true);
JButton button1 = new JButton("添加");
JButton button2 = new JButton("修改");
JButton button3 = new JButton("查询");
JButton button4 = new JButton("删除");
JButton button5 = new JButton("浏览");
FlowLayout flow = new FlowLayout(FlowLayout.LEFT,10,10);
JPanel panel = new JPanel(flow);
panel.add(button1);
panel.add(button2);
panel.add(button3);
panel.add(button4);
panel.add(button5);
panel.add(title);
panel.add(pic);
jframe.add(panel);
try{
file.createNewFile();
System.out.println("creat ok!");
}
catch (IOException e){
System.out.println("creat go die!");
e.printStackTrace();
}
button1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Add add = new Add();
}
});
button2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Change change = new Change();
}
});
button3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Ask ask = new Ask();
}
});
button4.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Delete delete = new Delete();
}
});
button5.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Look look = new Look();
}
});
}
}
Add是添加功能
package JavaStuIO;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.TreeMap;
import java.io.*;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import JavaStuIO.WindowIO;
public class Add extends JFrame{
JLabel jlnumber = new JLabel("学号:");
JLabel jlname = new JLabel("姓名:");
JLabel jlsex = new JLabel("性别:");
JLabel jlbirthday = new JLabel("出生日期:");
JLabel jldepartment = new JLabel("学院:");
JTextField jtnumber = new JTextField("",20);
JTextField jtname = new JTextField("",20);
JTextField jtsex = new JTextField("",20);
JTextField j