| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 733 人关注过本帖
标题:[求助]一个java小程序的问题,请求帮忙~
只看楼主 加入收藏
心之记忆
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2005-9-1
收藏
 问题点数:0 回复次数:9 
[求助]一个java小程序的问题,请求帮忙~

小弟在网上下了个小程序,做参考用的~
我是个初学者,很多代码看不懂~
希望各位大侠给我解释下每个类和重要语句的功能,谢谢~
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.lang.*;

public class Students extends Applet implements ActionListener
{
Vector StuInf=new Vector();
StudentInf SI;
String xm;
String bj;
int i,j,xh,cj;
static int mid;
Label prompt1=new Label("学生成绩管理系统");
Label prompt2=new Label(" 用户:");
Label prompt3=new Label(" 密码:");
Label prompt4=new Label(" 班级:");
Label prompt5=new Label(" 成绩:");
TextField input1=new TextField(8);
TextField input2=new TextField(8);
TextField input3=new TextField(8);
TextField input4=new TextField(8);
Button btn1=new Button("登录");
Button btn2=new Button("增加");
Button btn3=new Button("修改");
Button btn4=new Button("删除");

public void init()
{
setLayout(new GridLayout(6,3));
add(new Label());
add(prompt1);
add(new Label());
add(prompt2);
add(input1);
add(new Label());
add(prompt3);
add(input2);
add(btn1);
add(prompt4);
add(input3);
add(new Label());
add(prompt5);
add(input4);
add(new Label());
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);
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand()=="登录")
{
String a,b;
a=input1.getText();
b=input2.getText();
input1.setText("");
if((a.equals("12")==true)&&(b.equals("12")==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("用户名或密码错");
}
if(e.getActionCommand()=="增加")
{
boolean scucss=true;
try
{
XingMing();
}
catch(EmptyException as)
{
input1.setText("姓名不能为空");
scucss=false;
}
try
{
xh=Integer.parseInt(input2.getText());
}
catch(NumberFormatException m)
{
input2.setText("学号为空或格式错");
scucss=false;
}
bj=input3.getText();
try
{
ChengJi();
}
catch(EmptyException as)
{
cj=-1;
}
catch(OverException dd)
{
input4.setText("应在0-100间");
scucss=false;
}
catch(NumberFormatException cm)
{
input4.setText("成绩应为数据");
scucss=false;
}
if(scucss==true)
{
SI=new StudentInf(xm,xh,bj,cj);
Insert(SI);
}
}
if(e.getActionCommand()=="修改")
{
xm=input1.getText();
xh=Integer.parseInt(input2.getText());
bj=input3.getText();
cj=Integer.parseInt(input4.getText());
SI=new StudentInf(xm,xh,bj,cj);
StuInf.setElementAt(SI, mid);
btn3.setEnabled(false);
}
if(e.getActionCommand()=="删除")
{
StuInf.removeElementAt(mid);
btn4.setEnabled(false);
input1.setText("删除成功");
input2.setText("");
input3.setText("");
input4.setText("");
}
if(e.getActionCommand()=="查询")
{
boolean right=true;
try
{
xh=Integer.parseInt(input2.getText());
}
catch(NumberFormatException m)
{
input2.setText("学号为空或格式错");
right=false;
}
if(right==true)
{
search(xh);
btn3.setEnabled(true);
btn4.setEnabled(true);
}
}

}
//查找方法
public void search(int k)
{
boolean exist=false;
int low=0;
int high=StuInf.size()-1;
while(low<=high)
{
mid=(high+low)/2;
StudentInf a1=(StudentInf) StuInf.elementAt(mid);
if(a1.getStuNo()==k)
{
SI=(StudentInf) StuInf.elementAt(mid);
String x = String.valueOf(SI.getStuNo());
exist=true;
input1.setText(SI.getname());
input1.selectAll();
input2.setText("0"+x);
input3.setText(SI.getClassNo());
if(SI.getLevel()==-1)
input4.setText("未参加考试");
else
{
String y = String.valueOf(SI.getLevel());
input4.setText(y);
}
break;
}
else if(a1.getStuNo()<k)
low=mid+1;
else
high=mid-1;
}
if(exist==false)
{
input1.setText("无此学号学生信息");
input1.selectAll();
}
}
//添加方法
public void Insert(StudentInf q)
{
int i=0;

if(StuInf.isEmpty()==true)
{
StuInf.addElement(q);
input1.setText("");
input2.setText("");
input3.setText("");
input4.setText("");
}
else
{
StudentInf xh;
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.setText("此学生信息已存在");
input2.requestFocus();
input2.selectAll();
}
else
{
StuInf.insertElementAt(q,i);
input1.setText("");
input2.setText("");
input3.setText("");
input4.setText("");
}
}
}

//异常类
class OverException extends Exception
{
String over;
}
class EmptyException extends Exception
{
String empty;
}
void XingMing() throws EmptyException
{
if((input1.getText()).equals(""))
throw (new EmptyException());
else
xm=input1.getText();
}
void ChengJi() throws OverException,EmptyException
{
if((input4.getText()).equals(""))
throw(new EmptyException());
else
cj=Integer.parseInt(input4.getText());
if(cj<0||cj>100)
throw (new OverException());
}

//学生信息类
public class StudentInf
{
private String name;
private int StuNo;
private String ClassNo;
private int Level;
StudentInf(String xingming,int xuehao,String banji,int chengji)
{
name=xingming;
StuNo=xuehao;
ClassNo=banji;
Level=chengji;
}
public int getStuNo()
{
return StuNo;
}
public String getname()
{
return name;
}
public String getClassNo()
{
return ClassNo;
}
public int getLevel()
{
return Level;
}
}

}

搜索更多相关主题的帖子: java 请求 
2007-01-09 19:15
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 
我服了你,初学者就看这个东西

还是先看看简单的基础的东西先吧

不要好高骛远


可惜不是你,陪我到最后
2007-01-09 19:21
心之记忆
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2005-9-1
收藏
得分:0 
我现在是基本的代码是明白什么意思~~
但是看别人做的东西,就看不懂了~
可能是没实际运用过~~
所以想找些源程序,自己试着改,看能不能改出自己想要的

2007-01-09 19:24
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 
你学JAVA多久&gt;?

可惜不是你,陪我到最后
2007-01-09 19:31
心之记忆
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2005-9-1
收藏
得分:0 
学到包和接口方面的~~~
不算很久~~

2007-01-09 20:21
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 

那就继续学基础吧

不要这么急着看这种代码,对你没什么好处


可惜不是你,陪我到最后
2007-01-09 20:23
心之记忆
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2005-9-1
收藏
得分:0 

对了,版主~~
你帮我解释完这段代码~~
顺便给我介绍些比较有用的JAVA方面的书籍,行不?


2007-01-09 20:23
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 

代码我不给你解释,因为解释了也没有用,并且这代码都是很基础的,也不需要解释

比较有用的JAVA书,我也不知道如何回答你,我学JAVA也是东看一点西看一点资料的,不过,如果你的基础打好以后,你可以看看JAVA编程思想


可惜不是你,陪我到最后
2007-01-09 20:29
liming566
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-1-2
收藏
得分:0 

版主说的很对啊...对初学者来说..JAVA变成思想真的是很好的工具..里面什么都有..有了他.看代码就简单多了..

2007-01-09 21:33
无理取闹
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:53
帖 子:4264
专家分:0
注 册:2006-7-26
收藏
得分:0 
初学最好就是自己写代码

win32汇编
病毒 加密
目前兴趣所在
2007-01-09 21:46
快速回复:[求助]一个java小程序的问题,请求帮忙~
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020341 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved