简单实现Java版学生管理系统
程序员文章站
2024-03-12 10:08:38
本文实例为大家分享了java实现学生管理系统的具体代码,供大家参考,具体内容如下
package bookdemo_1;
import javax.sw...
本文实例为大家分享了java实现学生管理系统的具体代码,供大家参考,具体内容如下
package bookdemo_1; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class test { public static void main(string[] args) { studentsys stusys=new studentsys("学生管理系统"); stusys.initwin(); } } class studentsys extends jframe{ private jpanel p1,p2,p3,combop; private jtabbedpane tab; private container container; private jbutton b1,b2; private listener listener; private label namelabel; private label gradelabel; private label showlabel; private jtextfield textname; private jtextfield textgrade; private textarea showgradearea; /* * 查找 * */ private label searchlabel; private jtextfield searchtext; private jbutton sbut; private jtextfield resulttext; private string[] name; private string[] grade; /* * 排序 * */ private textarea showtextarea; private jbutton sortbut; private int countnum=0; private jbutton clearbut; public studentsys(string str){ super(str); this.name=new string[100]; this.grade=new string[100]; listener = new listener(); tab = new jtabbedpane(jtabbedpane.top); //容器 container = this.getlayeredpane(); //对象化面板 combop = new jpanel(); p1 = new jpanel(); p2 = new jpanel(); p3 = new jpanel(); b1 =new jbutton("确认添加"); b2 =new jbutton("撤回添加"); namelabel =new label("姓名"); gradelabel =new label("成绩"); showlabel=new label("当前记录为零! "); textname =new jtextfield(15); textgrade =new jtextfield(15); showgradearea=new textarea(); /* * 查找 * */ searchlabel=new label("请输入姓名:"); searchtext=new jtextfield(15); sbut=new jbutton("确认查找"); resulttext=new jtextfield(15); /* * 排序 * */ showtextarea=new textarea(); sortbut=new jbutton("成绩排序"); clearbut=new jbutton("清空数据"); } public void initwin(){ this.setbounds(300, 300, 500, 400); this.addwindowlistener(new windowadapter(){ public void windowclosing(windowevent e) { super.windowclosing(e); system.exit(0); }}); layoutwin(); this.setvisible(true); } private void layoutwin(){ tab.add(p1,"成绩输入"); tab.add(p2,"成绩查询"); tab.add(p3,"成绩排序"); combop.add(new jlabel("学生信息管理系统")); container.setlayout(new borderlayout()); container.add(combop,borderlayout.north); container.add(tab,borderlayout.center); container con1=new container(); con1.setlayout(new flowlayout()); con1.add(namelabel); con1.add(textname); con1.add(gradelabel); con1.add(textgrade); p1.add(con1,borderlayout.north); p1.add(con1); p1.add(showgradearea); container con2=new container(); con2.setlayout(new flowlayout()); con2.add(b1); con2.add(b2); con2.add(showlabel); p1.add(con2); b1.addactionlistener(listener); b2.addactionlistener(listener); /* * 查找布局 * */ container con3=new container(); con3.setlayout(new flowlayout()); con3.add(searchlabel); con3.add(searchtext); con3.add(sbut); p2.add(con3,borderlayout.north); sbut.addactionlistener(listener); p2.add(resulttext); /* * 排序布局 * */ p3.add(showtextarea); p3.add(sortbut); p3.add(clearbut); sortbut.addactionlistener(listener); clearbut.addactionlistener(listener); } /* * java内部类实现actionlistener接口 * */ class listener implements actionlistener{ @override public void actionperformed(actionevent e) { if(e.getsource()==b1){ if((textname.gettext().equals(""))||(textgrade.gettext().equals(""))){ showlabel.settext("添加失败(姓名,成绩不能有空)!"); } else{ name[countnum]=textname.gettext(); grade[countnum]=textgrade.gettext(); countnum++; string area="添加成功,当前有"+countnum+"条记录"; showlabel.settext(area); sortmess(false); textname.settext(""); textgrade.settext(""); } } if(e.getsource()==b2){ if(countnum>0){ countnum--; string area="撤回成功,当前有"+countnum+"条记录"; showlabel.settext(area); sortmess(false); } } if(e.getsource()==sbut){ if(!searchtext.gettext().equals("")){ searchmess(searchtext.gettext()); } } if(e.getsource()==sortbut){ sortmess(true); } if(e.getsource()==clearbut){ if(!showtextarea.gettext().equals("")){ showtextarea.settext(""); } } } public void sortmess(boolean sign) { // todo auto-generated method stub if(sign){ for(int i=0;i<countnum;i++){ for(int j=i+1;j<countnum;j++){ if(integer.parseint(grade[i])<integer.parseint(grade[j])){ string s1,s2; s1=name[i]; s2=grade[i]; name[i]=name[j]; grade[i]=grade[j]; name[j]=s1; grade[j]=s2; } } } }else{ if(!showgradearea.gettext().equals("")){ showgradearea.settext(""); } } for(int i=0;i<countnum;i++){ string content="姓名:"+name[i]+"\t"+"成绩"+grade[i]; if(sign)showtextarea.append(content+"\n"); else showgradearea.append(content+"\n"); } } public void searchmess(string n) { // todo auto-generated method stub for(int i=0;i<countnum;i++){ if(name[i].equals(n)){ string content="姓名:"+name[i]+","+"成绩"+grade[i]; resulttext.settext(content); return; } } resulttext.settext("未找到该学生!"); } } }
更多学习资料请关注专题《管理系统开发》。
以上就是本文的全部内容,希望对大家学习java程序设计有所帮助。
上一篇: 简单谈谈Java类与类之间的关系