javalzWord文件下载.docx

上传人:b****6 文档编号:16362601 上传时间:2022-11-23 格式:DOCX 页数:16 大小:143.35KB
下载 相关 举报
javalzWord文件下载.docx_第1页
第1页 / 共16页
javalzWord文件下载.docx_第2页
第2页 / 共16页
javalzWord文件下载.docx_第3页
第3页 / 共16页
javalzWord文件下载.docx_第4页
第4页 / 共16页
javalzWord文件下载.docx_第5页
第5页 / 共16页
点击查看更多>>
下载资源
资源描述

javalzWord文件下载.docx

《javalzWord文件下载.docx》由会员分享,可在线阅读,更多相关《javalzWord文件下载.docx(16页珍藏版)》请在冰豆网上搜索。

javalzWord文件下载.docx

publicvoidsearch(intk)

Labelprompt2

Labelprompt3

Labelprompt4

Labelprompt5

publicvoidInsert(StudentInfq)

TextFieldinput1

TextFieldinput2

TextFieldinput3

voidChengJi()

TextFieldinput4

Buttonbtn1

Buttonbtn2

voidXingMing()

Buttonbtn3

Buttonbtn4

OverException

Stringover

EmptyExcepyion

Stringempty

StudentInf

privateStringname

StudentInf(Stringxingming,intxuehao,Stringbanji,intchengji)

privateintStuNo

publicStringgetname()

publicintgetStuNo()

privateStringClassNo

publicStringgetClassNo()

publicintgetLevel()

privateintLevel

附:

源程序代码框架

importjava.applet.Applet;

importjava.awt.*;

importjava.awt.event.*;

importjava.util.*;

importjava.lang.*;

publicclassStudentsextendsAppletimplementsActionListener{

…………………………………………

publicvoidinit(){

…………………………………………

}

publicvoidactionPerformed(ActionEvente){

…………………………………………

publicvoidsearch(intk){

}

publicvoidInsert(StudentInfq){

classOverExceptionextendsException{

Stringover;

}

classEmptyExceptionextendsException{

Stringempty;

voidXingMing()

voidChengJi()

publicclassStudentInf{

StudentInf(Stringxingming,intxuehao,Stringbanji,intchengji){

…………………………………………

publicintgetStuNo(){

returnStuNo;

publicStringgetname(){

returnname;

publicStringgetClassNo(){

returnClassNo;

publicintgetLevel(){

returnLevel;

}

三、界面设计与事件处理

…………………………………………………

Labelprompt1=newLabel("

学生管理系统"

);

Labelprompt2=newLabel("

用户:

"

Labelprompt3=newLabel("

密码:

Labelprompt4=newLabel("

班级:

Labelprompt5=newLabel("

成绩:

TextFieldinput1=newTextField(8);

TextFieldinput2=newTextField(8);

TextFieldinput3=newTextField(8);

TextFieldinput4=newTextField(8);

Buttonbtn1=newButton("

登录"

Buttonbtn2=newButton("

增加"

Buttonbtn3=newButton("

修改"

Buttonbtn4=newButton("

删除"

publicvoidinit(){

setLayout(newGridLayout(8,3));

add(newLabel());

add(prompt1);

add(prompt2);

add(input1);

add(prompt3);

add(input2);

add(btn1);

add(prompt4);

add(input3);

add(prompt5);

add(input4);

add(btn2);

add(btn3);

add(btn4);

prompt4.setVisible(false);

prompt5.setVisible(false);

input3.setVisible(false);

input4.setVisible(false);

btn2.setVisible(false);

btn3.setVisible(false);

btn4.setVisible(false);

btn1.addActionListener(this);

btn2.addActionListener(this);

btn3.addActionListener(this);

btn4.addActionListener(this);

if(e.getActionCommand()=="

){

Stringa,b;

a=input1.getText();

b=input2.getText();

input1.setText("

if((a.equals("

lz"

)==true)&

&

(b.equals("

02"

)==true)){

prompt2.setText("

姓名:

prompt3.setText("

学号:

prompt4.setVisible(true);

prompt5.setVisible(true);

input3.setVisible(true);

input4.setVisible(true);

btn2.setVisible(true);

btn3.setVisible(true);

btn4.setVisible(true);

btn3.setEnabled(false);

btn4.setEnabled(false);

btn1.setLabel("

查询"

input1.setText("

登录成功"

input1.selectAll();

}

else

input2.setText("

用户名或密码错"

){

booleanscucss=true;

try{

XingMing();

}

catch(EmptyExceptionas){

姓名不能为空"

scucss=false;

try{

xh=Integer.parseInt(input2.getText());

catch(NumberFormatExceptionm){

学号为空或格式错"

}

bj=input3.getText();

ChengJi();

cj=-1;

catch(OverExceptiondd){

input4.setText("

应在0-100间"

catch(NumberFormatExceptioncm){

成绩应为数据"

if(scucss==true){

SI=newStudentInf(xm,xh,bj,cj);

Insert(SI);

xm=input1.getText();

xh=Integer.parseInt(input2.getText());

cj=Integer.parseInt(input4.getText());

SI=newStudentInf(xm,xh,bj,cj);

StuInf.setElementAt(SI,mid);

btn3.setEnabled(false);

StuInf.removeElementAt(mid);

btn4.setEnabled(false);

删除成功"

input2.setText("

input3.setText("

input4.setText("

booleanright=true;

right=false;

}

if(right==true){

search(xh);

btn3.setEnabled(true);

btn4.setEnabled(true);

//查找方法

booleanexist=false;

intlow=0;

inthigh=StuInf.size()-1;

while(low<

=high){

mid=(high+low)/2;

StudentInfa1=(StudentInf)StuInf.elementAt(mid);

if(a1.getStuNo()==k){

SI=(StudentInf)StuInf.elementAt(mid);

Stringx=String.valueOf(SI.getStuNo());

exist=true;

input1.setText(SI.getname());

0"

+x);

input3.setText(SI.getClassNo());

if(SI.getLevel()==-1)

input4.setText("

未参加考试"

else{

Stringy=String.valueOf(SI.getLevel());

input4.setText(y);

break;

elseif(a1.getStuNo()<

k)

low=mid+1;

high=mid-1;

if(exist==false){

无此学号学生信息"

input1.selectAll();

//添加方法

inti=0;

if(StuInf.isEmpty()==true){

StuInf.addElement(q);

else{

StudentInfxh;

xh=(StudentInf)StuInf.firstElement();

while(xh.getStuNo()<

q.getStuNo()){

i++;

if(i<

StuInf.size())

xh=(StudentInf)StuInf.elementAt(i);

else

break;

if(xh.getStuNo()==q.getStuNo()){

此学生信息已存在"

input2.requestFocus();

input2.selectAll();

else{

StuInf.insertElementAt(q,i);

input3.setText("

}

//异常类

classOverExceptionextendsException{

voidXingMing()throwsEmptyException{

if((input1.getText()).equals("

))

throw(newEmptyException());

else

voidChengJi()throwsOverException,EmptyException{

if((input4.getText()).equals("

throw(newEmptyException());

if(cj<

0||cj>

100)

throw(newOverException());

//学生信息类

privateStringname;

privateintStuNo;

privateStringClassNo;

privateintLevel;

StudentInf(Stringxingming,intxuehao,Stringbanji,intchengji){

name=xingming;

StuNo=xuehao;

ClassNo=banji;

Level=chengji;

四、运行结果

五.实验心得

Java程序设计语言是十分重要的学科,学习Java语言,重要的是要多看、多想、多练习。

通过本次实验,对图形用户界面的设计及事件处理有了更深一步的理解,虽然刚开始时遇到了一些问题,但通过查资料,阅读课本,终于把报告做完了,但对于调式程序还是有一定的难度。

这次试验让我知道,平时要多了解算法,多做程序,可以提高自己的设计和编程能力。

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 小学教育 > 语文

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1