1. 首页
  2. JAVA

学生信息管理系统,简单界面化

package jiemian;

public class STxinxi {
	private int student_age;
	private String student_type;
	private String student_number;
	private String student_name;
	public STxinxi(String student_number,String student_name,String student_type,int student_age) {
		super();
		this.student_age= student_age;
		this.student_type = student_type;
		this.student_number = student_number;
		this.student_name = student_name;
	}
	public STxinxi() {
		super();
	}
	public int getStudent_age() {
		return student_age;
	}
	public void setStudent_age(int student_grade) {
		this.student_age = student_grade;
	}
	public String getStudent_type() {
		return student_type;
	}
	public void setStudent_type(String student_type) {
		this.student_type = student_type;
	}
	public String getStudent_number() {
		return student_number;
	}
	public void setStudent_number(String student_number) {
		this.student_number = student_number;
	}
	public String getStudent_name() {
		return student_name;
	}
	public void setStudent_name(String student_name) {
		this.student_name = student_name;
	}
	public String showAll() {
		return (getStudent_number()+" "+getStudent_name()+" "+getStudent_type()+" "+getStudent_age());
	}
	public String getAll() {
		return (getStudent_number()+" "+getStudent_name()+" "+getStudent_type()+" "+getStudent_age()+"\r\n");
	}
}
package jiemian;

import java.util.*;
import java.io.*;

public class Student {
	Scanner cin = new Scanner(System.in);
	List<STxinxi> sc = new ArrayList<STxinxi>();

	public void read() throws IOException {
		File fileNew = new File("D:\\student\\student.txt");
		File rootFile = fileNew.getParentFile();
		if (!fileNew.exists()) {
			try {
				rootFile.mkdirs();
				fileNew.createNewFile();
			} catch (IOException e) {

				System.out.println(fileNew + "文件创建失败");
			}
		}
		BufferedReader read = new BufferedReader(new FileReader("D:\\student\\student.txt"));
		String stu = read.readLine();
		while (null != stu) {
			String[] stu1 = stu.split(" ");
			STxinxi sc1 = new STxinxi();
			sc1.setStudent_number(stu1[0]);
			sc1.setStudent_name(stu1[1]);
			sc1.setStudent_type(stu1[2]);
			sc1.setStudent_age(Integer.parseInt(stu1[3]));
			sc.add(sc1);
			stu = read.readLine();
		}
		read.close();
	}

	public void add() {
		System.out.println("请输入学号,姓名,年龄,专业");
		String student_id = cin.next();
		String student_name = cin.next();
		int student_age = cin.nextInt();
		String student_type = cin.next();
		STxinxi sc1 = new STxinxi();
		sc1.setStudent_age(student_age);
		sc1.setStudent_name(student_name);
		sc1.setStudent_number(student_id);
		sc1.setStudent_type(student_type);
		sc.add(sc1);
	}

	public void add(String student_id, String student_name, String student_type, int student_age) {
		STxinxi sc1 = new STxinxi();
		sc1.setStudent_age(student_age);
		sc1.setStudent_name(student_name);
		sc1.setStudent_number(student_id);
		sc1.setStudent_type(student_type);
		sc.add(sc1);
	}

	public List getlist() {
		return sc;
	}

	public void show() {
		for (STxinxi sc1 : sc) {
			System.out.println(sc1.showAll());
		}
	}

	public void writer() throws IOException {
		FileOutputStream out = new FileOutputStream("D:\\student\\student.txt");
		for (STxinxi sc1 : sc) {
			out.write(sc1.getAll().getBytes());
		}
		out.close();
	}
}
package jiemian;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class Mydialog extends JDialog {
	private JButton button1,button2;
	private JLabel label1,label2;
	private String s1;
	public Mydialog(JFrame parent) {
		super(parent,"警告",true);
		this.setLocation(600, 400);
		this.setSize(200, 160);
		this.setLayout(new GridLayout(2,2));
		button1=new JButton("确定");
		button2=new JButton("取消");
		label1=new JLabel("确定添加信息");
		label2=new JLabel();
		button1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				s1="确定";
				dispose();
			}
		});
		button2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				s1="取消";
				dispose();
			}
		});
		this.add(label1);
		this.add(label2);
		this.add(button1);
		this.add(button2);
	}
	public String getorder() {
		return s1;
	}
}
package jiemian;

import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;

import jiemian.STxinxi;
import jiemian.Student;

public class Jm extends JFrame implements ActionListener {
	private JButton button1,button2,button3,button4,button5,button6;
	private JTextField text1,text2,text3,text4;
	private JTextField text5,text6;
	private JLabel label1,label2,label3,label4,label5;
	private Mydialog dialog=new Mydialog(this);
	List<STxinxi>sc=new ArrayList<STxinxi>();
	public Jm() throws IOException {
		this.setBounds(100, 100, 800, 800);
		this.setLayout(null);
		button1=new JButton("添加信息");
		button1.setBounds(400,350, 100, 40);
		button2=new JButton("修改信息");
		button2.setBounds(600,350, 100, 40);
		button3=new JButton("查询信息");
		button3.setBounds(600, 520, 100, 40);
		Font f = new Font("黑体", Font.BOLD, 40);
		label1=new JLabel("学号:");label1.setBounds(400, 10, 70, 60);
		label2=new JLabel("姓名:");label2.setBounds(400, 70, 70, 60);
		label3=new JLabel("专业:");label3.setBounds(400, 130, 70, 60);
		label4=new JLabel("年龄:");label4.setBounds(400, 190, 70, 60);
		label5=new JLabel("请输入查询学号:");label5.setBounds(10, 520, 140, 60);
		text1=new JTextField();text1.setBounds(470, 10, 200, 60);
		text2=new JTextField();text2.setBounds(470, 70, 200, 60);
		text3=new JTextField();text3.setBounds(470, 130, 200, 60);
		text4=new JTextField();text4.setBounds(470, 190, 200, 60);
		text5=new JTextField();text5.setBounds(150, 520, 300, 60);
		text6=new JTextField();text6.setBounds(10, 600, 500, 60);
		Student a=new Student();
		a.read();
		sc=a.getlist();
		int t=sc.size();
		String[] tabelValues= {"学号","姓名","专业","年龄"};
		String[][] columnName=new String[t+1][4];
		for (int i=0;i<sc.size();i++) {
			columnName[i][0]=sc.get(i).getStudent_number();
			columnName[i][1]=sc.get(i).getStudent_name();
			columnName[i][2]=sc.get(i).getStudent_type();
			columnName[i][3]=sc.get(i).getStudent_age()+"";
		}
		JTable tabel=new JTable(columnName,tabelValues);
		JScrollPane scrotable=new JScrollPane(tabel);
		scrotable.setBounds(0, 0, 400, 500);
		this.add(button1);
		this.add(button2);
		this.add(button3);
		this.add(label1);
		this.add(label2);
		this.add(label3);
		this.add(label4);
		this.add(label5);
		this.add(text1);
		this.add(text2);
		this.add(text3);
		this.add(text4);
		this.add(text5);
		this.add(text6);
		this.add(scrotable);
		button1.addActionListener(this);
		button3.addActionListener(this);
		
		this.setVisible(true);
	}
	public void actionPerformed(ActionEvent arg0) {
		String ss=null;
		String button=arg0.getActionCommand();
		if (button.equals("添加信息")) {
			button5=new JButton("确定");
			button6=new JButton("取消");
			String id=text1.getText();
			String name=text2.getText();
			String type=text3.getText();
			int age=Integer.parseInt(text4.getText());
			Student a=new Student();
			try {
				a.read();
			} catch (IOException e1) {
				// TODO 自动生成的 catch 块
				e1.printStackTrace();
			}
			dialog.setVisible(true);
			if(dialog.getorder().equals("确定"))
			{    a.add(id, name,type, age);
			try {
				a.writer();
			} catch (IOException e) {
				// TODO 自动生成的 catch 块
				e.printStackTrace();
			}
			text1.setText("");
			text2.setText("");
			text3.setText("");
			text4.setText("");
			}
			if(dialog.getorder().equals("取消")) {
				text1.setText("");
				text2.setText("");
				text3.setText("");
				text4.setText("");
			}
		}
		if (button.equals("查询信息")) {
			Student a=new Student();
			boolean bool=false;
			try {
				a.read();
			} catch (IOException e1) {
				// TODO 自动生成的 catch 块
				e1.printStackTrace();
			}
			sc=a.getlist();
			for (int i=0;i<sc.size();i++) {
				if (sc.get(i).getStudent_number().equals(text5.getText()))
					{
					ss="学号:"+sc.get(i).getStudent_number()+"     姓名:"+sc.get(i).getStudent_name()+"     专业:"+sc.get(i).getStudent_type()+"     年龄:"+sc.get(i).getStudent_age();	
					bool=true;
					}
				
			}
			if (bool) {
			text6.setText(ss);}
			else {
				JDialog dg=new JDialog();
				JLabel lb=new JLabel("查无此学生");
				dg.setLayout(new GridLayout(1,0));
				dg.setTitle("警告");
				dg.setLocation(600, 580);
				dg.setSize(200, 100);
				dg.add(lb);
				dg.setVisible(true);
			}
			try {
				a.writer();
			} catch (IOException e) {
				// TODO 自动生成的 catch 块
				e.printStackTrace();
			}
			
		}

	}

}
package jiemian;

import java.io.IOException;

public class Main {
	public static void main(String[] args) throws IOException {
		Jm a=new Jm();
	}
}

 

原创文章,作者:程序员凯小白,如若转载,请注明出处:http://www.kaixiaobai.com/archives/100

发表评论

登录后才能评论

联系我们

qq

在线咨询:点击这里给我发消息

邮件:1298646637@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息