⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sms.java

📁 java课程设计——学生信息管理系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class SMS implements ActionListener{
	public static StringBuffer [][]student = new StringBuffer[100][8];
	public static StringBuffer temp = new StringBuffer("");
	public static int i = -1;
	public static int k = 0;
	public static int m = 0;
	public static int g = 0;
	JFrame fmain;
	JPanel pmain;
	JButton btnadd,btndelete,btnchange,btnsearch,btntaxis;
	JLabel lb;
	public static void main(String []args){
		SMS mainframe = new SMS();
		mainframe.go();
	}
	void go(){
		Color c = new Color(0,111,232);
		Font h = new Font("幼圆",Font.BOLD,18);
		fmain = new JFrame("学生基本信息管理系统");
		pmain = new JPanel();
		pmain.setLayout(null);
		lb = new JLabel(new ImageIcon("1.jpg"));
		btnadd = new JButton("添 加");
		btndelete = new JButton("删 除");
		btnchange = new JButton("修 改");
		btnsearch = new JButton("查 询");
		btntaxis = new JButton("排 序");
		btnadd.setFont(h);
		btndelete.setFont(h);
		btnchange.setFont(h);
		btnsearch.setFont(h);
		btntaxis.setFont(h);
		btnadd.setForeground(Color.yellow);
		btndelete.setForeground(Color.yellow);
		btnchange.setForeground(Color.yellow);
		btnsearch.setForeground(Color.yellow);
		btntaxis.setForeground(Color.yellow);
		pmain.add(btnadd);
		pmain.add(btndelete);
		pmain.add(btnchange);
		pmain.add(btnsearch);
		pmain.add(btntaxis);
		pmain.add(lb);
		fmain.add(pmain,"Center");
		lb.setBounds(0,0,350,300);
		btnadd.setBounds(20,224,90,30);
		btndelete.setBounds(122,224,90,30);
		btnchange.setBounds(225,224,90,30);
		btnsearch.setBounds(71,260,90,30);
		btntaxis.setBounds(175,260,90,30);
		btnadd.setBackground(c);
		btndelete.setBackground(c);
		btnchange.setBackground(c);
		btnsearch.setBackground(c);
		btntaxis.setBackground(c);
		btnadd.addActionListener(this);
		btndelete.addActionListener(this);
		btnchange.addActionListener(this);
		btnsearch.addActionListener(this);
		btntaxis.addActionListener(this);
		fmain.setLocation(500,300);
		fmain.setSize(350,335);
		fmain.setVisible(true);
		fmain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	public void actionPerformed(ActionEvent e)
	{
		if((String)e.getActionCommand()=="添 加"){
			AddFrame addframe = new AddFrame();
			addframe.go();
		}
		if((String)e.getActionCommand()=="删 除"){
			DeleteFrame deleteframe = new DeleteFrame();
			deleteframe.go();
		}
		if((String)e.getActionCommand()=="修 改"){
			ChangeSearchFrame changesearchframe = new ChangeSearchFrame();
			changesearchframe.go();
		}
		if((String)e.getActionCommand()=="查 询"){
			SearchFrame searchframe = new SearchFrame();
			searchframe.go();
		}
		if((String)e.getActionCommand()=="排 序"){
			TaxisChoiceFrame taxischoiceframe = new TaxisChoiceFrame();
			taxischoiceframe.go();
		}
	}	
}

class AddFrame implements ActionListener{
	JFrame fadd;
	JPanel padd;
	JLabel lb;
	JLabel lbnumber,lbname,lbsex,lbage,lbresult,lbchinese,lbmaths,lbenglish;
	JTextField tfnumber,tfname,tfsex,tfage,tfchinese,tfmaths,tfenglish;
	JButton btsure;
	void go(){
		Font h = new Font("楷体", Font.BOLD, 18);
		Font q = new Font("楷体", Font.BOLD, 22);
		fadd = new JFrame("添加");
		padd = new JPanel();
		padd.setLayout(null);
		lb = new JLabel(new ImageIcon("2.jpg"));
		lbnumber = new JLabel("学号");
		lbname = new JLabel("姓名");
		lbsex = new JLabel("性别");
		lbage = new JLabel("年龄");
		lbresult = new JLabel("成 绩");
		lbchinese = new JLabel("语文");
		lbmaths = new JLabel("数学");
		lbenglish = new JLabel("英语");
		lbnumber.setFont(h);
		lbname.setFont(h);
		lbsex.setFont(h);
		lbage.setFont(h);
		lbresult.setFont(q);
		lbchinese.setFont(h);
		lbmaths.setFont(h);
		lbenglish.setFont(h);
		lbnumber.setForeground(Color.blue);
		lbname.setForeground(Color.blue);
		lbsex.setForeground(Color.blue);
		lbage.setForeground(Color.blue);
		lbresult.setForeground(Color.red);
		lbchinese.setForeground(Color.red);
		lbmaths.setForeground(Color.red);
		lbenglish.setForeground(Color.red);
		tfnumber = new JTextField();
		tfname = new JTextField();
		tfsex = new JTextField();
		tfage = new JTextField();
		tfchinese = new JTextField();
		tfmaths = new JTextField();
		tfenglish = new JTextField();
		btsure = new JButton("确 定");
		btsure.setFont(h);
		btsure.setForeground(Color.blue);
		padd.add(lbnumber);
		padd.add(lbname);
		padd.add(lbsex);
		padd.add(lbage);
		padd.add(lbresult);
		padd.add(lbchinese);
		padd.add(lbmaths);
		padd.add(lbenglish);
		padd.add(tfnumber);
		padd.add(tfname);
		padd.add(tfsex);
		padd.add(tfage);
		padd.add(tfchinese);
		padd.add(tfmaths);
		padd.add(tfenglish);
		padd.add(btsure);
		padd.add(lb);
		fadd.add(padd,"Center");
		lb.setBounds(0,0,500,320);
		lbnumber.setBounds(15,30,40,25);
		lbname.setBounds(15,85,40,25);
		lbsex.setBounds(15,140,40,25);
		lbage.setBounds(15,195,40,25);
		lbresult.setBounds(330,30,80,25);
		lbchinese.setBounds(250,85,40,25);
		lbmaths.setBounds(250,140,40,25);
		lbenglish.setBounds(250,195,40,25);
		tfnumber.setBounds(70,30,150,25);
		tfname.setBounds(70,85,150,25);
		tfsex.setBounds(70,140,150,25);
		tfage.setBounds(70,195,150,25);
		tfchinese.setBounds(300,85,150,25);
		tfmaths.setBounds(300,140,150,25);
		tfenglish.setBounds(300,195,150,25);
		btsure.setBounds(340,240,100,30);
		fadd.setLocation(500,300);
		fadd.setSize(500,320);
		fadd.setVisible(true);
		fadd.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		btsure.addActionListener(this);
	}
	public void actionPerformed(ActionEvent e){
		if((String)e.getActionCommand()=="确 定"){
			if(tfnumber.getText().equals(""))
			{
				fadd.dispose();
				AddError adderror = new AddError();
				adderror.go();
				return;
			}
			for(int j=0;j<=SMS.i;j++){
				if(SMS.student[j][0].toString().equals(tfnumber.getText())){
					fadd.dispose();
					AddNo addno = new AddNo();
					addno.go();
					return;
				}
			}
			SMS.i ++;
			StringBuffer temp;
			temp = new StringBuffer(tfnumber.getText());
			SMS.student[SMS.i][0] = temp;
			temp = new StringBuffer(tfname.getText());
			SMS.student[SMS.i][1] = temp;
			temp = new StringBuffer(tfsex.getText());
			SMS.student[SMS.i][2] = temp;
			temp = new StringBuffer(tfage.getText());
			SMS.student[SMS.i][3] = temp;
			if(tfchinese.getText().equals("")){
				SMS.student[SMS.i][4] = new StringBuffer("0");
			}
			else{
				temp = new StringBuffer(tfchinese.getText());
				SMS.student[SMS.i][4] = temp;
			}
			if(tfmaths.getText().equals("")){
				SMS.student[SMS.i][5] = new StringBuffer("0");
			}
			else{
				temp = new StringBuffer(tfmaths.getText());
				SMS.student[SMS.i][5] = temp;
			}
			if(tfenglish.getText().equals("")){
				SMS.student[SMS.i][6] = new StringBuffer("0");
			}
			else{
				temp = new StringBuffer(tfenglish.getText());
				SMS.student[SMS.i][6] = temp;
			}
			/*temp = new StringBuffer(tfmaths.getText());
			SMS.student[SMS.i][5] = temp;
			temp = new StringBuffer(tfenglish.getText());
			SMS.student[SMS.i][6] = temp;*/
			SMS.student[SMS.i][7] = null;
			fadd.dispose(); 
			AddFrame_True addframe_true = new AddFrame_True();
			addframe_true.go();
		}
	}
}

class AddError implements ActionListener{
	JFrame faddError;
	JPanel paddError;
	JLabel laddError,lb;
	JButton btsure;
	void go(){
		Font h = new Font("楷体", Font.BOLD, 18);
		lb = new JLabel(new ImageIcon("2.jpg"));
		faddError = new JFrame("添加出错");
		paddError = new JPanel();
		paddError.setLayout(null);
		laddError = new JLabel("必须输入学号!");
		btsure = new JButton("确 定");
		laddError.setFont(h);
		btsure.setFont(h);
		laddError.setForeground(Color.red);
		btsure.setForeground(Color.blue);
		paddError.add(laddError);
		paddError.add(btsure);
		paddError.add(lb);
		faddError.add(paddError,"Center");
		laddError.setBounds(80,25,150,30);
		btsure.setBounds(180,60,90,30);
		lb.setBounds(0,0,300,140);
		btsure.addActionListener(this);
		faddError.setLocation(530,400);
		faddError.setSize(300,140);
		faddError.setVisible(true);
		faddError.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	}
	public void actionPerformed(ActionEvent e){
		if((String)e.getActionCommand()=="确 定"){
			faddError.dispose(); 
		}
	}
}

class AddNo implements ActionListener{
	JFrame faddno;
	JPanel paddno;
	JLabel laddno,lb;
	JButton btsure;
	void go(){
		Font h = new Font("楷体", Font.BOLD, 18);
		lb = new JLabel(new ImageIcon("2.jpg"));
		faddno = new JFrame("添加不成功");
		paddno = new JPanel();
		paddno.setLayout(null);
		laddno = new JLabel("该学号已存在!");
		btsure = new JButton("确 定");
		laddno.setFont(h);
		btsure.setFont(h);
		laddno.setForeground(Color.red);
		btsure.setForeground(Color.blue);
		paddno.add(laddno);
		paddno.add(btsure);
		paddno.add(lb);
		faddno.add(paddno,"Center");
		laddno.setBounds(80,25,150,30);
		btsure.setBounds(180,60,90,30);
		lb.setBounds(0,0,300,140);
		btsure.addActionListener(this);
		faddno.setLocation(530,400);
		faddno.setSize(300,140);
		faddno.setVisible(true);
		faddno.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	}
	public void actionPerformed(ActionEvent e){
		if((String)e.getActionCommand()=="确 定"){
			faddno.dispose(); 
		}
	}
}


class AddFrame_True implements ActionListener{
	JFrame faddtrue;
	JPanel paddtrue;
	JLabel laddtrue,lb;
	JButton btsure;
	void go(){
		Font h = new Font("楷体", Font.BOLD, 18);
		lb = new JLabel(new ImageIcon("2.jpg"));
		faddtrue = new JFrame("添加结果");
		paddtrue = new JPanel();
		paddtrue.setLayout(null);
		laddtrue = new JLabel("添加成功!");
		btsure = new JButton("确 定");
		laddtrue.setFont(h);
		btsure.setFont(h);
		laddtrue.setForeground(Color.red);
		btsure.setForeground(Color.blue);
		paddtrue.add(laddtrue);
		paddtrue.add(btsure);
		paddtrue.add(lb);
		faddtrue.add(paddtrue,"Center");
		laddtrue.setBounds(100,25,120,30);
		btsure.setBounds(180,60,90,30);
		lb.setBounds(0,0,300,140);
		btsure.addActionListener(this);
		faddtrue.setLocation(530,400);
		faddtrue.setSize(300,140);
		faddtrue.setVisible(true);
		faddtrue.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	}
	public void actionPerformed(ActionEvent e){
		if((String)e.getActionCommand()=="确 定"){
			faddtrue.dispose(); 
		}
	}
}

class DeleteFrame implements ActionListener{
	Font h = new Font("楷体", Font.BOLD, 18);
	JFrame fdelete;
	JPanel pdelete;
	JLabel lbnumber,lb;
	JTextField tfnumber;
	JButton btsure;
	void go(){
		lb = new JLabel(new ImageIcon("3.jpg"));
		fdelete = new JFrame("删除");
		pdelete = new JPanel();
		pdelete.setLayout(null);
		lbnumber = new JLabel("学号");
		tfnumber = new JTextField();
		btsure = new JButton("确 定");
		lbnumber.setFont(h);
		btsure.setFont(h);
		lbnumber.setForeground(Color.yellow);
		btsure.setForeground(Color.blue);
		pdelete.add(lbnumber);
		pdelete.add(tfnumber);
		pdelete.add(btsure);
		pdelete.add(lb);
		fdelete.add(pdelete,"Center");
		lbnumber.setBounds(50,30,40,30);
		tfnumber.setBounds(100,30,180,30);
		btsure.setBounds(200,80,100,30);
		lb.setBounds(0,0,350,160);
		fdelete.setLocation(500,300);
		fdelete.setSize(350,160);
		fdelete.setVisible(true);
		fdelete.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		btsure.addActionListener(this);
	}
	public void actionPerformed(ActionEvent e){
		if((String)e.getActionCommand()=="确 定"){
			if(tfnumber.getText().equals(""))
			{
				fdelete.dispose();
				DeleteError deleteerror = new DeleteError();
				deleteerror.go();
				return;
			}
			int o=0;
			for(int j=0;j<=SMS.i;j++){
				if(SMS.student[j][0].toString().equals(tfnumber.getText())){
					o++;
					SMS.student[j][0] = SMS.temp ;
					break;
				}
			}
			if(o==0){
				fdelete.dispose();
				DeleteNo deleteno = new DeleteNo();
				deleteno.go();
				return;
			}
			fdelete.dispose(); 
			DeleteFrame_True deleteframe_true = new DeleteFrame_True();
			deleteframe_true.go();
		}
	}
}

class DeleteError implements ActionListener{
	JFrame fdeleteError;
	JPanel pdeleteError;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -