该用户从未签到
|
- import java.applet.Applet;
" b. j. H+ L. t' B- M - import java.awt.*;
( L+ \! L8 y5 ]* T - import java.awt.event.*;" i' p1 W% K1 G9 _, {: }/ \
- import java.util.*;
( t# t. `8 ^, W3 I1 n - import java.lang.*;
0 S9 W4 h9 g( G7 L
8 }3 H- p' Q( x0 `- public class Students extends Applet implements ActionListener
) i7 T. M6 q) c& f$ }3 g - {
/ u- N* x2 @4 L1 a - Vector StuInf=new Vector();
2 U+ C: _0 A8 F* g! A! Z - StudentInf SI;
5 J2 Y5 ]8 m' F! I - String xm;
, t* N2 t: k9 `0 L - String bj;/ S6 S# t* V4 C! g& ?; k* p- g
- int i,j,xh,cj;
$ r4 G' \/ p& }/ d' n' z7 G) h - static int mid;' o8 [2 R# n7 I. k4 k2 Z4 X8 c
- Label prompt1=new Label("学生成绩管理系统");
: S' T. V& E1 F/ o7 f - Label prompt2=new Label(" 用户:");
' ?, [6 C& a3 @2 W0 ^ - Label prompt3=new Label(" 密码:");; x; r# _, d9 @0 d
- Label prompt4=new Label(" 班级:");
/ [0 r7 J, \ u( O% X# r - Label prompt5=new Label(" 成绩:");- a' V7 {* p8 |( D
- TextField input1=new TextField(8);
, |5 b* A- j3 R/ S! i% m% \ - TextField input2=new TextField(8);
S7 U$ d- N9 t* P - TextField input3=new TextField(8);
9 x0 a0 ^- t0 i% H9 o# I3 E$ G - TextField input4=new TextField(8);+ t$ V; t6 R7 P: \9 P8 t8 K5 G4 Z6 {
- Button btn1=new Button("登录");
2 H+ ]! M/ F1 C' X9 h7 U( { - Button btn2=new Button("增加");, s6 e! {9 Y! \* U' E5 l
- Button btn3=new Button("修改");+ Y5 x% u) A/ s/ T( f
- Button btn4=new Button("删除");$ E# Q; J0 a0 Y* C9 m3 M/ i" I8 q/ q
- 0 j3 V2 ^; p( i0 j4 c( z |
- public void init()
. S$ b2 q% A; K8 q# w6 ^ - {0 M7 K0 x# i( ~0 r, w
- setLayout(new GridLayout(6,3));
# A+ j n. Z& |; _ - add(new Label());
0 \* v5 a4 C& l D3 r - add(prompt1);
# f5 V0 E0 v! S5 s/ ?+ v - add(new Label());. [; }7 ? e$ a
- add(prompt2);
& g/ I, |7 c, r - add(input1);
- ?+ B8 ~: k9 _1 A2 c4 L( F$ y& x - add(new Label());+ Q' @9 o9 N9 z3 B, m a) K6 j
- add(prompt3);; \/ ?0 P% e U h; M
- add(input2);
: e" g8 G$ k1 q' u. a - add(btn1);! x- W5 w- l. M! ^
- add(prompt4);' {% k+ B( T: B* J
- add(input3);
1 I& f- G# k8 n5 }! ^- o - add(new Label());
v) |& j" |6 B/ p" D - add(prompt5);
! P, m, Q3 ^, n7 b: H' J - add(input4);
( r# U, R. E6 w8 F& S" O - add(new Label());8 Y, [2 S5 K, e8 W) u
- add(btn2);
' ?' _4 H! N# l8 B% X X1 d5 V5 ]/ Y2 W - add(btn3);+ h R7 F' r$ {; k+ |* m- L$ d
- add(btn4);& a6 I9 s! Y$ U% `, y: z
- prompt4.setVisible(false);6 Q0 m' ~: [8 k0 i
- prompt5.setVisible(false);
9 G X9 }4 i7 E: ]# l' x# E- k - input3.setVisible(false);8 p. T2 v* F: M2 ]; T: R
- input4.setVisible(false);" y. E/ R' Q8 a0 V. I# Q: i) t0 M
- btn2.setVisible(false);+ E. M6 B; J7 ~+ S% L$ m8 }4 n) [* @% Y; _
- btn3.setVisible(false);
& e+ O: u+ s+ X [+ \ - btn4.setVisible(false);
$ h5 D; |' p' J* e% F8 C - btn1.addActionListener(this);) ?) L/ H9 H% H" |$ c# y
- btn2.addActionListener(this);
( }3 N0 x* W. L! u9 k - btn3.addActionListener(this);
; B, k) g' _( D6 V - btn4.addActionListener(this);
* f9 R5 ~: k* c1 c - }
! V' u( B# c/ b: q2 @( l; ^0 J' T - public void actionPerformed(ActionEvent e)
! p: \2 g w) w* G3 ` - {' C% c+ @: S# u; O7 `7 c) Y" S0 |3 l
- if(e.getActionCommand()=="登录")
2 J/ r( y2 s5 t0 d6 c - {( [+ n* p+ A" E% @" o% { d# _* x" \
- String a,b;& d/ b0 ], u2 J# t
- a=input1.getText();5 h0 A: u$ `+ S
- b=input2.getText();( i" P+ I/ p/ z
- input1.setText("");
- j5 \5 d2 g4 _' p- ?# p - if((a.equals("12")==true)&&(b.equals("12")==true))0 `+ a% D0 e6 T3 u7 r
- {, r7 S1 ?# `0 a# p# q
- prompt2.setText(" 姓名:");2 X9 k& `, f4 j+ Z0 K
- prompt3.setText(" 学号:"); + k: H! d$ @" m+ b
- prompt4.setVisible(true);
/ u9 d$ ^6 J6 Z) V* L5 B. z+ P - prompt5.setVisible(true);
8 A% |9 M* l4 L( `6 `5 C - input3.setVisible(true);
. U* h& Q; s( E. `+ e6 O% J - input4.setVisible(true);1 G2 t6 U+ o! T9 B0 L# U
- btn2.setVisible(true);
* q! p# v s! F8 o. a - btn3.setVisible(true);! s8 ]* }7 r2 u) d
- btn4.setVisible(true);
" a* |, H2 D1 Y2 t8 f1 @ - btn3.setEnabled(false);+ w& j- \3 q, n+ i+ j4 D
- btn4.setEnabled(false);- a; E$ G3 F. {' l; e
- btn1.setLabel("查询");
! S9 _2 E. n$ l/ B - input1.setText("登录成功");
3 G+ W0 e1 o/ z% O - input1.selectAll();
! g. U+ R! j# z" J; y1 f+ y - }1 |5 W) @5 s2 w: Z" S
- else# c. n" J6 ?! N
- input2.setText("用户名或密码错");/ E! \* s( Z. B
- }
& H$ i+ @" p( n& h3 c# w& j - if(e.getActionCommand()=="增加"): d4 B2 f9 @- p+ u' H$ F" S
- {* z. O0 {! M$ t9 S, s: ~+ F, v
- boolean scucss=true;
; ^1 c* _! \6 H6 @. {6 G) I - try. F0 q$ p: Y) d$ [* x# I
- {
& P; ?0 |7 ]8 F5 x0 v q7 { - XingMing();8 F. I) H& _& i8 v: D
- }' r7 P K. N! ?8 @& Z
- catch(EmptyException as)" ?, k7 ^! Y9 z {/ F4 C B
- {9 @6 O' z2 ] |! | p6 B
- input1.setText("姓名不能为空");
9 r) {1 M2 e5 b2 C }# M- S - scucss=false;% o; T- ?8 [. x! r+ a6 l! V
- }- C5 s, G% g; H/ N6 Z/ N
- try! v$ G) O% b0 o" S8 x5 y
- {
8 |% r3 x: y+ t2 F( | - xh=Integer.parseInt(input2.getText());% M: Q$ e6 r. {$ t! y7 w
- }/ k r5 K2 C9 ]. ^6 f
- catch(NumberFormatException m)
v: Q! W f$ {; M - {
4 R% c+ z1 g/ m+ L* K- L8 E) K - input2.setText("学号为空或格式错");
7 | I- p& y7 T8 [; }- T - scucss=false;. b( q$ F" _) c3 U l* {
- } . V _* B, w* a' V, _
- bj=input3.getText();* G. Z* n! Q, a+ ^
- try2 G5 ^$ A% w _4 l* H
- { i& q/ \) [1 O- u
- ChengJi();" C% V' C' U6 B9 \! b! T6 S. {1 c
- }
9 U, i" s9 t% O! q6 f0 a - catch(EmptyException as)+ b' ^/ z7 e" o& v2 ~4 a
- {& ^, Q; @" Q$ C1 K* ]4 p! W
- cj=-1;
$ Y6 u* k5 ?, E( { - }
- X0 |. |6 b" u3 K& }- E - catch(OverException dd)
' r9 @/ W% Q; M c) g( F, ` - {
1 L9 U4 S2 w5 E! w+ h6 }! |% r - input4.setText("应在0-100间");
" G1 j D" S! T) k! y3 Y/ W - scucss=false; A$ W- I. n9 P* z
- }
6 L1 H& ^5 c% {& H - catch(NumberFormatException cm)
* I7 p4 k. Q0 M5 u% c/ [5 {# T - {
2 X- Q$ O9 D9 n$ ^! u! G; V - input4.setText("成绩应为数据");- |3 s; Q3 m" R+ A
- scucss=false;
9 ?' R" O1 _( X - }3 x U. D: _9 k8 A+ b R2 X
- if(scucss==true)8 u/ q" A7 X4 m+ W
- {! B5 I6 c7 L4 [. r) n9 f
- SI=new StudentInf(xm,xh,bj,cj);
: r3 _% h) J$ _" Y - Insert(SI);$ Y' G8 e) d: u) {9 Z8 C: a2 L) q: a
- }
8 b, \9 g- q3 P/ m$ M( e - }
- Z# ^) H0 q, S3 _3 K2 w - if(e.getActionCommand()=="修改")8 d, r" x0 ?0 s6 W7 C+ \
- {' W& X, g6 s+ A# }# _+ ]# V
- xm=input1.getText();2 R j G \! E% Z3 K" y$ I, v% b9 T
- xh=Integer.parseInt(input2.getText());3 k# v2 C1 W/ W2 s! B g
- bj=input3.getText();
! | [, |: V- S; v0 o - cj=Integer.parseInt(input4.getText());
+ P7 g8 M4 l! {; t8 g9 Q- O) g - SI=new StudentInf(xm,xh,bj,cj);
( |% P& q* H0 ^5 M - StuInf.setElementAt(SI, mid);
" m3 x: V+ @, E E+ C+ X! _ - btn3.setEnabled(false);
2 p# ^5 J1 O4 ^ W. Z0 K2 H# A - }0 q) P2 K" _; X8 B8 L
- if(e.getActionCommand()=="删除")
1 c _) x( K5 D: e5 h - {
8 k& `1 {5 n" ~ G* A& h - StuInf.removeElementAt(mid);
$ c; @' B4 ]1 P6 X0 ?- w' B4 e - btn4.setEnabled(false);8 P5 x4 b: E/ V* D5 q7 `' n
- input1.setText("删除成功");
5 r0 _ ^! F. ? - input2.setText("");* B o; ?# Q9 \) H3 u7 ?
- input3.setText("");
' x1 C; n# d8 \3 R) U - input4.setText("");# b4 { e5 c7 s/ d$ n8 F0 W
- }
4 W* M/ h% \5 G% p - if(e.getActionCommand()=="查询")
9 {# S P/ ]# C - {/ _9 J6 A- x! W. X
- boolean right=true;, g8 c1 |. U9 l W' h$ K
- try
' `: c: x: U/ P- }# K - {9 i8 d7 [! D' n+ H4 v( M
- xh=Integer.parseInt(input2.getText());0 D% H) H/ v3 {! X6 M
- }1 b @! a4 b n$ J4 \% g
- catch(NumberFormatException m)
' I6 R# O$ |, Z0 P% p# W - {6 Y3 @0 k9 l7 W" |/ E" C
- input2.setText("学号为空或格式错");* D; E0 L; f3 H# Z
- right=false;
T2 Z5 w' R5 W3 f9 s3 ? - }
7 ]$ F5 C5 y& o; @ - if(right==true)) M4 Q# {& T8 Q( p
- {# y/ i" @ p# l0 `6 c% G: }, M& l
- search(xh);
9 r' b$ r6 j, | - btn3.setEnabled(true);3 ^2 V- b! }. J h, o1 v
- btn4.setEnabled(true);' ^0 f; A- E& t5 h
- }
) S# {2 i C- W. C) ^( r# {+ @ - }9 P. q' i+ {( V
- ! [0 o& g& N; d3 _8 [
- }
# @) Z1 G* f; G) ]9 a; w. I, d - //查找方法9 S4 f. ` o7 S. B _, D& n
- public void search(int k)
0 n' @0 g% Z- | - {6 a( ~. m3 t" i' I
- boolean exist=false;1 t3 X: ~# h3 @' m" G1 ?
- int low=0;' M( ?# d% T$ W
- int high=StuInf.size()-1;
2 B, [1 l5 w2 y3 {5 ~' e9 t - while(low<=high)
; [/ A. k0 C m7 m) G0 f0 V - {
/ L: W; h) D0 E - mid=(high+low)/2;
8 m- S8 |" [% Q0 ~6 n3 M: G/ Q6 K1 } - StudentInf a1=(StudentInf) StuInf.elementAt(mid);
* T Y% \" W% e - if(a1.getStuNo()==k)
, Q: x. b7 f& F' N: ]8 b* [ - {
5 v$ K) ?; ~. p2 B - SI=(StudentInf) StuInf.elementAt(mid);& d) [# G1 Y3 r @, P
- String x = String.valueOf(SI.getStuNo());. P- L( G9 N* m/ X- U
- exist=true;& R1 D D7 q0 q: O% h; J
- input1.setText(SI.getname());+ f1 h. e) T( t$ W0 `1 s
- input1.selectAll();1 K$ w/ E1 D% O
- input2.setText("0"+x);
- a/ v. f0 D% [: r - input3.setText(SI.getClassNo());
' u e; V6 N; D4 V* C6 T5 P J! e& R - if(SI.getLevel()==-1)
! a+ i& c+ D. k$ y6 }& v T7 ?# A - input4.setText("未参加考试");
* |- M: i1 d, R+ F - else: s3 T+ f( `) a8 H/ j
- {- G5 ?* ^) s2 @& d3 b
- String y = String.valueOf(SI.getLevel());
6 w' e. S) R; @ - input4.setText(y);
1 n/ c( v# @' _4 Y( H - }
; @9 S' J1 v6 c0 H+ j' E% q - break;
: i% t/ [: X0 Y- v2 a- u: R T - }! d; O% v. u. c$ _9 }& }7 P
- else if(a1.getStuNo()<k); B) f% ]8 o( G0 l9 L, E
- low=mid+1;2 K8 l4 |2 G" E; i
- else. ^5 e& I! }1 `0 n
- high=mid-1;
3 i' X/ u! M8 Q% U& C3 u - }. S/ @& W0 [) O" B$ a' ]7 `
- if(exist==false)7 p7 d9 z7 t" Q0 S/ x) a( L7 p
- {5 y1 j" Q3 k6 y. c% Y; I& S
- input1.setText("无此学号学生信息");0 w2 j9 ?5 J8 `9 I3 Y% X) r
- input1.selectAll();/ `0 Q. Y" ?% H1 b7 e' U1 w
- }, z" G2 F% L: E9 v% g
- }
/ H# O6 V7 C0 I - //添加方法- s9 ]. K" q0 |+ z/ T3 z
- public void Insert(StudentInf q)
, e- L9 h1 Q. h6 S$ f! H l - {- E! z+ K4 }+ u: r' d3 E% R: Q
- int i=0;: I8 ^# H8 V$ K6 ~
-
: E( x& k. W; [' r3 ? - if(StuInf.isEmpty()==true)
/ R. E: a6 ^" ]+ g1 g - {0 X6 E* g4 N( K, W7 }" V( Y: A
- StuInf.addElement(q);$ Q* |1 U( |7 Z
- input1.setText("");
3 u4 |. b% L/ C4 e* `* ^$ x4 }, l - input2.setText("");
+ m( C: r2 x/ k. K9 I3 Q5 B. k - input3.setText("");
# ~) F/ O; `% g- ^& Q6 D - input4.setText("");
/ X1 y1 e( }$ ~+ Z1 n: a" a, d - }
7 C! Y/ n7 n% T2 a( m5 ~6 W' k - else
. {+ O7 Q$ @! V i. u4 _$ a9 z - {& j8 A( o1 x% T9 P3 `) l6 \& O1 W
- StudentInf xh;$ a& |: R3 m, \" A$ ]1 F7 s
- xh=(StudentInf) StuInf.firstElement();
) a8 _- j$ t% Q9 K, A - while(xh.getStuNo()<q.getStuNo())
/ H9 M5 w$ f8 o9 m - {
/ ^/ Z* k/ @5 x8 f/ n! B2 U - i++;
u: v% {; v" O: n; l, p1 C+ R - if(i<StuInf.size())( x! m) c; B- z) \" f
- xh=(StudentInf) StuInf.elementAt(i);& D* \8 X. X* s V* O
- else 1 a: T4 P8 F% d, b
- break;" n/ e8 R! m) h8 |" E2 _
- }
4 Y/ A5 u* I+ j) T! M4 Z' @ - if(xh.getStuNo()==q.getStuNo())# Z/ ]7 H& |0 U- N0 N4 X% u
- {/ s4 v" h1 g* M
- input2.setText("此学生信息已存在");
* H. w; O% C) Z% ^! v+ I - input2.requestFocus();( @' g3 v( V" D t9 c \) x7 `
- input2.selectAll();2 ~& s% o' g( j5 J: j ^) M1 O
- }, ]# }, W: r7 Q& k
- else
M/ d5 Q# w p% Z9 U+ }1 Y - {
% E$ k& Z6 j+ @ - StuInf.insertElementAt(q,i);
/ O. j. [. w- I& G4 r! h. } - input1.setText("");
: ?5 v/ ^" J3 g! G - input2.setText("");
& c$ e5 J& O' R' q- t - input3.setText("");2 o# Y2 \" e* X# B9 q* U% P- e5 j
- input4.setText("");
' P% M9 v* J3 Q- g* B$ m( ~ - }" A. _' [6 ^" k+ q' X6 [, r, R
- }
- X# P! i6 X1 }$ a& c - } S8 H4 _# a c
-
1 z3 \4 [* n6 Z4 w$ F - //异常类
: S% x4 o6 z2 f) O* _/ K - class OverException extends Exception
1 o& ]( @7 h2 Z# e - {
+ j+ B2 _( W7 _2 k& E# {+ N1 | - String over;
; R7 A7 A9 P# Y$ c - }
6 q; P# ?6 N' {" F+ w - class EmptyException extends Exception
3 D+ b1 c/ d8 y- G/ q& D6 | - {! Z* f; i! |3 E4 K
- String empty;
& C* \& ^5 I% I1 p; z, i' i0 I - }
# S& O* a: W( _0 @4 f& t9 I+ B - void XingMing() throws EmptyException+ Q( h! u. f! `1 p
- {
K& W8 `) l8 R! d* q4 E' Q - if((input1.getText()).equals(""))9 i, T+ x( |* K0 w+ |
- throw (new EmptyException());+ ^9 A" w6 E2 z, |! q/ v1 i
- else
0 `1 L, _6 G% o" h1 I$ H - xm=input1.getText();; K5 Q# j5 Z1 S% {) z: V6 T5 }
- }) {# {) M& Q0 o7 q
- void ChengJi() throws OverException,EmptyException
n$ F& O) ^7 l9 j - {
% P, E0 Q, e3 e& J7 v( b - if((input4.getText()).equals(""))
( v- Y2 m( B) M1 G1 I/ M - throw(new EmptyException());
8 _; V, y( l6 N2 W1 H" d - else
4 P. [0 l: o* H - cj=Integer.parseInt(input4.getText());/ h5 o# |! S: ^: \. v2 G* b% U+ _& |
- if(cj<0||cj>100)- V0 {- q& G% a+ O
- throw (new OverException());
) K. W+ A7 j, l% _ - }" V/ i! }! F7 h9 }: [ N, c1 Z! e7 E, T
-
3 i- t: h8 N9 \: q - //学生信息类1 d% Y3 m6 A$ c2 Z9 V# _
- public class StudentInf
# T5 S) A: E3 c4 Y1 S1 B - {4 h8 p& `5 c1 m7 o _, J- {9 V
- private String name;
! [! Q9 B a1 l: g- E7 {, A3 c - private int StuNo;
; @# x9 f: o0 R3 Y - private String ClassNo;
1 Z6 X# f; r% `, I4 j3 m+ q2 ? - private int Level;5 P: V: i$ }8 b$ U- ~( ?
- StudentInf(String xingming,int xuehao,String banji,int chengji)0 M, ^. |4 ?' O* U( _- k; C# U
- {
/ I' C; B& O& ?7 U - name=xingming;& W# \% O) j. m( g( O4 q
- StuNo=xuehao;
. p6 T& f/ s2 _& t$ t Q* ` - ClassNo=banji;- C/ V, o. j" w8 J! {& M, p6 @& y
- Level=chengji;/ P7 `! A+ o! N7 E5 w3 E
- }
! n6 e, @ h: v: `/ s, @$ X - public int getStuNo()
& a8 [! O" O7 e, R' v - {
! L/ e9 w7 M6 ]+ S - return StuNo;8 ^8 k: c! |- E* O
- }/ F$ \/ P$ a% @6 n6 R
- public String getname()
% a3 b( y& h2 s. z& P6 | {; G - {4 V. v' S4 T+ Z9 S8 {5 v2 j
- return name;+ Q- R, S, Z6 s; D% [+ t# X
- }
& P3 c1 [4 V/ U0 ]9 q3 ]/ G - public String getClassNo()* n* x. m2 A' g
- {2 g: F3 W$ ~( ~2 k# f) M+ I# X8 I3 o6 N
- return ClassNo;
1 h% w/ ]2 O( Z* Y7 E* K8 R - }
! I6 N$ b& d, Z; h7 m - public int getLevel()
9 a, X, }. `9 ? a - {
- ?% L: B J2 a; {2 T ~8 ~ - return Level;
2 z" f$ f5 @$ G4 G& f - }. [ I' P0 x( Q6 O4 C* l( ~4 i8 R
- }
! X9 c" y& ^8 c, T' b. d - ) t9 S. F: Q$ z. b# R
- }
复制代码
" n, K: S5 _" d0 }6 b' {1 L7 E' u; v4 i, O) }7 H+ X( \7 h
|
|