该用户从未签到
|
- import java.applet.Applet;
& T1 E1 D4 B7 ]1 \* o' g - import java.awt.*;
8 \* I2 O1 C; _1 O+ c$ e - import java.awt.event.*;: S7 \# s8 E8 b
- import java.util.*;
+ g: @1 q$ f( X& P7 u) w* p1 Q& Y& C. p [ - import java.lang.*;) ^. a% ?( b$ d) j2 W0 `9 Q
8 Z5 C0 j/ e! C- public class Students extends Applet implements ActionListener
/ i9 n: A$ P1 k: v' G - {; s: }" C' E6 `0 } `
- Vector StuInf=new Vector();' E5 M& t @; r7 i& S: x: g
- StudentInf SI;
6 N; J# E7 [ W- U% Z7 z2 A6 H8 ^ - String xm;( X2 M, w& X8 i3 N! q0 U4 m
- String bj;2 m) g% a' }) I# Y# N
- int i,j,xh,cj;
( V& ?% _) X4 D5 e' O, j/ I - static int mid;
! _ }9 f: H9 x8 F5 ?" N - Label prompt1=new Label("学生成绩管理系统");
. e. W% i! G3 T+ `' | - Label prompt2=new Label(" 用户:");+ {/ Q' w; H' p8 N, ]
- Label prompt3=new Label(" 密码:");
! x0 s. w2 @+ O' @) F$ d - Label prompt4=new Label(" 班级:");0 [, s# C& ^5 b( B9 A
- Label prompt5=new Label(" 成绩:");; Z. Z3 ]2 r3 r; X
- TextField input1=new TextField(8);& Z; n" K) p& f9 _) g
- TextField input2=new TextField(8);
. C: j6 g2 s1 t, r( Y2 p1 [ - TextField input3=new TextField(8);2 I$ [( t0 m5 j7 ~7 T
- TextField input4=new TextField(8);
# Q0 o$ Z3 |) y: \& k" D$ N - Button btn1=new Button("登录");
! m% ~2 D8 T6 A% D& B - Button btn2=new Button("增加");; \$ J |+ d$ S' O
- Button btn3=new Button("修改");6 O# U* g$ F' ?- ~# M; u, q1 D8 z5 I
- Button btn4=new Button("删除");
2 f$ g# U/ ]5 I E -
2 L0 h8 O# R( X7 X5 W - public void init() f/ p/ \, Y3 \7 P6 y" T6 K
- {, L% D6 N5 C% b
- setLayout(new GridLayout(6,3));
6 f6 L. \( V1 y+ e' x. o - add(new Label());8 }# O5 o' J0 d
- add(prompt1); J, ^ [! r9 P/ \' C
- add(new Label());. U' @ \( U$ u* r# X+ s. N
- add(prompt2);+ n3 L; S# ?& U) y, n. g) @
- add(input1);: ]" }# b' a1 e, g- z3 P9 b
- add(new Label());
0 B' t6 |, Q- c9 T2 f* u5 m - add(prompt3);
: |2 N$ v% _+ \$ n* c - add(input2);
' o7 L1 U6 a7 e: o9 S2 n6 s - add(btn1);
) o. ?. i, G: H9 G. g7 K+ h - add(prompt4);" Z) v- a/ [- p3 G( W, t M/ a9 _
- add(input3);* T' d, e/ ] s) G
- add(new Label());4 X) D* S) w& `
- add(prompt5);0 j. |# _1 G C. y
- add(input4);$ N8 Y, Z$ O5 Z; ?$ L, O! r: L8 T. F9 _
- add(new Label());: `2 U `: O* [
- add(btn2);
/ j) [2 {2 y+ L7 a - add(btn3);# w! |* F1 w7 M0 o; w E
- add(btn4);
8 p' j% Q/ S1 C, W - prompt4.setVisible(false);
: u' U' x% m( v4 i9 L6 B' N - prompt5.setVisible(false);
4 c9 L, y. R2 }# o5 f& ]; }. P5 V - input3.setVisible(false);
, `- B2 {5 n5 k, z% _4 L# L - input4.setVisible(false);
. H9 f' v5 i" J. G# u s$ R - btn2.setVisible(false);
) K" X l" m5 u" \3 |. ]/ e - btn3.setVisible(false);
d; C1 j3 f- e; w { - btn4.setVisible(false);
$ d- E, K$ L2 G# ?/ X3 g& b - btn1.addActionListener(this); t2 q& ^: b' @' l. h
- btn2.addActionListener(this);
( h, e3 }5 B. W+ e - btn3.addActionListener(this);
2 M3 J( x1 \) @9 Y$ {! s' l; Q - btn4.addActionListener(this);
8 d8 N8 N! I# B ] - }0 z& t/ ~( S6 k
- public void actionPerformed(ActionEvent e)
1 H8 s! j% C8 v+ S. W& z, D) a - {
+ ^ [0 i2 {& L+ i! x. D4 J9 M - if(e.getActionCommand()=="登录")5 K6 v* [ e \# _( u
- {, N4 h2 F* N2 p
- String a,b;
n6 Z' z% p2 o. X Y7 F" v0 k4 x0 ] - a=input1.getText();
" ]1 m; X" l. f5 K - b=input2.getText();
$ G& S* n. |. {) @+ s - input1.setText("");$ x6 q+ X: @8 v# ]8 }! ]
- if((a.equals("12")==true)&&(b.equals("12")==true))
3 G# e6 ^$ |" V; d - {
1 Z" G) f0 Z+ y4 x - prompt2.setText(" 姓名:"); p( N0 ^ s8 G1 O8 I6 n% d" p6 G
- prompt3.setText(" 学号:"); 1 @/ g8 r2 z) d( H1 P [7 S
- prompt4.setVisible(true);5 K) c1 E" S$ W2 ~" k
- prompt5.setVisible(true);
* k. D2 L+ D4 D) K8 Q5 [4 I# n* A4 l - input3.setVisible(true);
2 o- n$ \, u) t4 T8 f - input4.setVisible(true);% _5 ?7 ]# o9 m: n
- btn2.setVisible(true);
$ K% ?' a# y5 u" j: z - btn3.setVisible(true);
1 x5 B: w) h( L7 w: b" `/ b" | - btn4.setVisible(true);
& h6 h7 |& |* X ]9 O. \ - btn3.setEnabled(false);
$ F" W7 a. `, s6 |8 p - btn4.setEnabled(false);
. T3 ^3 `# ~+ n8 B/ Y2 X: b - btn1.setLabel("查询");
, q0 V: m/ @* x7 n1 M: f# a: M7 z - input1.setText("登录成功");
7 U- n+ I5 Y2 u7 I - input1.selectAll();
/ I, J+ I5 \* h: B% ?7 P$ n - }& X( `! O* m) Y' P8 @$ B5 R) \
- else2 q! x) L+ w- S7 d
- input2.setText("用户名或密码错");
& ^0 M- e# _, \7 h - }
+ u" {2 z" K3 _: n - if(e.getActionCommand()=="增加")5 Q9 l8 K& _+ X9 F: d% c5 h
- {1 W7 U& K7 }7 R# k3 U. B/ m/ n: E" W2 ~
- boolean scucss=true;1 c/ N# l( N/ A1 Z: m3 |
- try6 i# g g+ s F( a
- {, k. ~; d7 D" e$ x
- XingMing();6 \# y: b! D6 _1 H, o
- }
! `/ \+ ?. w/ V2 u' E9 [* Q: z6 X - catch(EmptyException as)
$ n' H' B0 |, f& `: x - {
3 X1 w0 w7 c' t0 D4 w9 e9 e! ]( O - input1.setText("姓名不能为空");
}; t" m7 _! Z( s' M" {8 n - scucss=false;
% m: |, Q) C* x% w - }
0 b5 Y5 F, T) x* m - try
# I( u7 b; `. H0 S& F1 o - { ?! ?! d, k3 ]% Y5 O- ~
- xh=Integer.parseInt(input2.getText());) S; J; y2 C. s1 ^
- }
& y( ?! {3 D- @1 b) N5 e - catch(NumberFormatException m)4 |7 j$ i7 Y: {% A0 z
- {! e, j. r% x* s5 |9 p7 i6 Z
- input2.setText("学号为空或格式错");
0 X# V" a Q: I& ?* v5 Y - scucss=false;
0 M) G P( M% Z9 T - }
2 j1 |! b+ F3 m - bj=input3.getText();1 Y( m; C4 a4 H! l1 f$ d) |
- try0 \( k$ W1 }. G$ P- ~
- {6 s A- R$ ]! E/ K$ Q
- ChengJi();) i7 i& u' f& O+ g! ?$ q* H' T: F ]
- }
6 G4 [. }$ U2 K" S) B2 f7 |0 k% H3 [ - catch(EmptyException as)5 e: _8 f s( W2 s& U
- {4 `$ T, x* D7 p( J; Y( p3 Y, \
- cj=-1;
5 E n2 F9 o+ t3 S8 G - }9 _( g& J4 \/ P3 G8 L( H: r
- catch(OverException dd)8 q- }. a- k9 z
- {
9 m, X) R3 D1 k6 o# @: e: O - input4.setText("应在0-100间");
3 l8 ]! a- `( e1 a+ W* b% I$ {7 ~ - scucss=false;6 A z, ~& x9 j! F
- }
, j b1 L$ T8 T- l) O x& J - catch(NumberFormatException cm)1 O3 K& z+ u7 b3 o
- {
- g. F8 d/ a+ }- w - input4.setText("成绩应为数据");
9 C9 l2 t$ S3 o - scucss=false;
) a' O. ]( R# y1 F b# j - }: t/ [% _0 d& F7 ^# l
- if(scucss==true)
+ t- Z O5 E, ~. d5 H - {
: s m F0 V. }) _. q& u" d5 R6 H; R: p - SI=new StudentInf(xm,xh,bj,cj);/ e7 Z+ ~4 V, q$ ]/ k, Q' U5 n
- Insert(SI);# F# [4 G6 D: F9 Y
- }0 s0 n4 I0 U/ \, _
- }
4 v( h* G! ]# @& r& { {2 M - if(e.getActionCommand()=="修改")
9 W3 V7 X. F3 Y - {
9 v" E+ J2 s3 T; g2 ~* { - xm=input1.getText();
7 U( O* [5 _/ ]9 z* S: q. k6 G - xh=Integer.parseInt(input2.getText());* U) k2 K# g1 s( R$ F H2 j
- bj=input3.getText();
. s; x1 P& F; w9 q - cj=Integer.parseInt(input4.getText());9 i/ L0 L2 `: d& }
- SI=new StudentInf(xm,xh,bj,cj);3 \* q% F/ J' R( }* D
- StuInf.setElementAt(SI, mid);2 n: V, V P! W7 C: z
- btn3.setEnabled(false);
- C z1 o2 c; }0 }$ R4 o2 G" s - }2 R L( b! N" J8 X( J6 Z+ \: H; G
- if(e.getActionCommand()=="删除")
3 P. |3 L# W* Y6 C - {8 `+ @) i0 @9 f/ m# T
- StuInf.removeElementAt(mid);
0 |5 B: n! U9 }9 C! k - btn4.setEnabled(false);6 v/ \" {0 y2 y# C6 ]
- input1.setText("删除成功");
( M* E- J* J3 M# K! X1 p5 q2 D; H! y - input2.setText("");
. w- _2 Z/ F6 f: z( o# ^. t/ j5 N - input3.setText("");
% E8 }7 t N& R' I% ` - input4.setText("");- L' Q Q8 A, e5 j$ q' k0 _
- }
# k9 `7 s1 X, O7 i( f$ U% x - if(e.getActionCommand()=="查询")3 p8 r6 s6 N( h( S( W
- {
3 t; M. J* X8 X- H6 `: Z, X {8 U* V - boolean right=true;* ]0 H, N( A1 c" G* n8 e# A
- try0 l4 |3 M) S! _& T. G/ _, R
- {! I$ R9 N% g/ B; Y* Z' z% a( n5 a
- xh=Integer.parseInt(input2.getText());
9 E/ {% G4 M8 g9 P' \/ }5 x - }" G* l/ O# X3 x
- catch(NumberFormatException m): L' Y6 P4 h: Q" ~' [5 U! F
- {
3 W+ `% ^& R; l3 M - input2.setText("学号为空或格式错");
) e+ z5 ^8 G+ F7 U& { - right=false;+ M( Y% ]6 m( Y3 [% P) U+ x
- }
3 d1 A. v0 d# F' \' W1 s - if(right==true)$ w1 p; Z5 ^9 x+ d v. ?
- { a+ ~' N/ B& \$ V( @
- search(xh);# G2 q7 q3 T2 c, L7 W1 c! s
- btn3.setEnabled(true);# W! b" i5 R2 q) ]2 c2 P
- btn4.setEnabled(true);
6 j. q& Q# ^5 t3 K - }% h* Q2 d7 F) p8 i0 k
- }
% Z: B, e9 V2 c% r, z: q - , f6 T% J5 y+ d& g: y7 W0 [7 ]: P! @4 c2 r
- }! H8 |. c4 |4 I* }, V* s, ?( F
- //查找方法; _) I8 ?2 K, N. S$ ]2 @
- public void search(int k)' Q3 U" n5 {0 s' s) t
- {7 ^6 \6 t: [1 v4 n7 [
- boolean exist=false;0 l6 ]$ z7 [* |- M; {( Z
- int low=0;* M8 B' V' U/ d7 E9 R
- int high=StuInf.size()-1;
2 z+ `3 m+ K3 R - while(low<=high)
: e ]6 F( F$ F* {9 f - {
5 b* t8 q( A0 [$ y - mid=(high+low)/2;' s% V6 J j9 U" D' r8 J* E* u
- StudentInf a1=(StudentInf) StuInf.elementAt(mid);5 `% f0 l4 q9 [3 w8 [- s( t
- if(a1.getStuNo()==k)4 N4 n* T$ |: h2 j% |- l' o
- {
" ?3 i, H& E! b4 G( [ - SI=(StudentInf) StuInf.elementAt(mid); }# T" |, r3 f/ R8 c/ | C0 [
- String x = String.valueOf(SI.getStuNo());' Z$ G6 m8 K; G5 x
- exist=true;
7 q4 i5 N1 H. }# g0 \% Z - input1.setText(SI.getname());
$ K. K! }% B: p2 m7 } - input1.selectAll();
! F" R# P- W( r# Z- r1 L0 d - input2.setText("0"+x);2 @& L& r5 a u' ] n6 o( l0 B
- input3.setText(SI.getClassNo());2 c/ u& e4 x# O- m0 _0 C4 x
- if(SI.getLevel()==-1)2 d6 @5 @- ?$ G% d/ i
- input4.setText("未参加考试");
) Y& ^2 U, |+ |9 q- }+ C - else. \3 o5 J+ U$ _+ Q2 ?
- {
) ~9 P k# H3 _& ` - String y = String.valueOf(SI.getLevel());
6 ]3 e# u& I: B, Y- b - input4.setText(y);
8 t5 Q& I$ ~1 b l. r5 N - }
; s; q. z4 r& v& B. p! j \/ d& L - break;, y) a2 i, y! u3 u( }
- }! W& I/ P z7 a+ J
- else if(a1.getStuNo()<k)7 A# K# g- L3 V5 K
- low=mid+1;6 [) l6 b7 Z# @+ z- M
- else
/ v0 {: [# t" j - high=mid-1;
1 D5 I5 [8 f, r* O! s - }) c2 ^; J( O! I6 r' h+ y# D
- if(exist==false)9 [7 T: {5 F* q5 _$ D& U" n
- {
e5 |7 m5 `1 z( x5 n$ D. m j - input1.setText("无此学号学生信息");) R4 ~" t& i' }. {. A0 Z1 q% n
- input1.selectAll();
4 _6 u# d6 }5 R7 V7 s - }! t4 x! x; `0 q- h) [
- }
' E; L3 Z$ x/ R! b. R+ } - //添加方法: h$ x: ?! s. N5 R6 f; Z
- public void Insert(StudentInf q)# S$ d% m2 q: d
- {
- U+ s& W, ]8 e( H1 ` - int i=0;
: ~6 h+ ?0 }/ n - ' @- `; d( @7 _1 ?
- if(StuInf.isEmpty()==true) # n- y9 A) w3 k S+ j: y
- {
; Z8 K, R" L0 K) t* w" C& A! H - StuInf.addElement(q);$ N0 v6 j: b k; L1 v
- input1.setText("");
* y2 }' ^; A4 i7 }3 ]2 J - input2.setText("");2 m( D, u E" r) N4 p
- input3.setText("");$ U- N9 A/ B1 I% M4 b
- input4.setText("");* ]8 c: ?: X( k8 k/ P3 X% v
- }9 y6 |! y6 x: a; {" _
- else
( q6 c0 ^5 n: Q - {
' E u V* f$ K - StudentInf xh;- W: g, ], Q" K7 N/ R
- xh=(StudentInf) StuInf.firstElement();" T/ j8 g1 f/ H" d7 M# c
- while(xh.getStuNo()<q.getStuNo())' O( j5 i. ?/ v! P6 k: l6 z2 M
- {
( O2 \" Y" p9 T6 b - i++;
0 [9 |* j9 |* U k- ~4 U5 I - if(i<StuInf.size())
5 k$ }2 a* C% D3 { - xh=(StudentInf) StuInf.elementAt(i);
# [, P) {) X5 q; y, H% t- }& ~* c; A - else
" j& W+ I& D- w# C4 |7 h - break;
" ]( u" T, E6 C& C/ | - }
7 K. f) t0 V% L. W( R, ? - if(xh.getStuNo()==q.getStuNo())1 [, `/ N( a0 Y* W9 b
- {
]$ k6 i, A/ C. w: A; ~ S6 E" v: M - input2.setText("此学生信息已存在");) u+ l- u( w% ]& i. A p
- input2.requestFocus();* S' j% g' `7 `. |: ?* B' ?
- input2.selectAll();
b' k: ~0 ~9 o: y4 I - }" [3 K, \1 v7 p* q& T
- else
7 {" E w% t5 i& b4 R& y - {
* Y0 ?) x8 x4 L) j5 V - StuInf.insertElementAt(q,i); " Z# P. o& v3 _* G5 f
- input1.setText("");: c2 x9 H$ l$ {- |: ]$ R" v
- input2.setText("");
/ f M2 G- e$ o0 C' B1 ?" _! U: \ - input3.setText("");3 f3 |. h5 J7 K
- input4.setText("");, r2 o* D: e# y4 \2 {
- }
; \& m0 E# L n5 J; d - }
$ ~" K i8 Y: o& q9 O - }
; w6 `6 b P& ~: u2 V - h/ R5 T) I1 t4 s' x" D" b2 d! f
- //异常类; ]" [2 t7 u- G
- class OverException extends Exception
: M8 Y4 t/ H: F C7 C' w4 Y6 m - {( {/ z+ \8 }; [4 }3 v7 R
- String over;
) {( T: |$ }1 g2 f* Y - } 5 u" l/ b# C' u! J9 J/ d8 |1 N
- class EmptyException extends Exception
8 Y- E5 b, ?' I; L/ H - {
6 _$ F; H( h! M - String empty;1 l; o+ ?4 r5 g* Z) _
- }! J7 R! G0 ]+ [$ ?6 r2 g' k
- void XingMing() throws EmptyException
K+ M9 S( m, ]$ M - {
- D8 r; [: h7 D - if((input1.getText()).equals(""))
" a! B% ]+ D+ M6 N# R$ ^ g - throw (new EmptyException());
# e/ m1 G2 i, ~ - else/ v5 @2 m6 S3 q9 I
- xm=input1.getText();! B- p4 S* _2 @) H) S/ m! J
- }9 s. ^: f+ P3 J/ `. o7 ?- U
- void ChengJi() throws OverException,EmptyException ( ?* P. \5 a. Q. c" m8 p% C8 @
- {
+ w3 \; b$ U; E" ]- C$ V% `. |( k - if((input4.getText()).equals(""))
$ t1 z- I7 T4 d* ~2 r, G+ A" P - throw(new EmptyException());/ B. H: h! g5 L
- else
8 n- t( k" q1 L/ S - cj=Integer.parseInt(input4.getText());* E' F% Q" j+ H& r8 _' I, f/ Z
- if(cj<0||cj>100)
% G+ e: ]# \9 O, R, f - throw (new OverException());/ H9 J, Q; n0 s0 u* Q; T
- }8 A! `5 r8 u& ^! J5 c& |/ ?# \
-
3 g3 S, E; \9 l, S - //学生信息类
) d& F/ a7 \$ O/ i - public class StudentInf9 V M# b( s# Z# L4 V0 i1 Z0 Z9 g
- {
- ]$ d- U4 g; p/ a' G1 P. o9 u - private String name;. I" |3 Y' C% z6 ?2 Q" m, T
- private int StuNo;
, P+ m8 p2 I r/ s$ |& W - private String ClassNo;
0 R4 g' E# W3 o - private int Level;
$ q5 M' i! s$ v8 `; G - StudentInf(String xingming,int xuehao,String banji,int chengji)
2 ]& a# F. x3 ?9 W& ]7 \ - {2 p+ w7 M# k3 M) u
- name=xingming;
0 V' \; }6 L; A8 n - StuNo=xuehao;) G- e7 z: C M+ v9 M
- ClassNo=banji;
6 X: }" f' |- M, R9 a - Level=chengji;8 U' x4 R! y6 Q1 N. d5 J. M1 }7 U
- }6 }! t" C5 U* E$ @
- public int getStuNo()
, [; f3 t4 v4 E - {) @- d. k8 Z: h
- return StuNo;9 ]0 d, I3 D/ w& s `% e& J
- }) ~' E/ f) l/ j
- public String getname()/ y x4 _8 ?) B# s' Y, a* Y
- {
( O# ^3 Y3 n: V - return name;7 c( a" h+ ]- U0 P3 U, p
- }* _$ r4 i' U$ k4 `+ S; ^: ^+ k( [
- public String getClassNo()
. S* y; ]2 k' B: p1 H - {
4 q3 T' ]2 Y% S. N. C - return ClassNo;
- `& N0 {' R2 |0 C# k/ L2 W K - }
: ?9 L1 k q+ V+ j - public int getLevel()
" I! |% ^( `1 t2 R8 \' R: V - {; [' o7 G0 Y2 m
- return Level;
: y, o: j, o) f& t( }( R* g: v - }7 w/ P! G" e9 ^0 J4 H9 V+ } O
- }
' q0 J6 d2 s( Y, H' C: `) z - ; p T+ ~9 T b
- }
复制代码
) R4 X6 y! B3 _- Z. Q, D% F9 J( X2 ?3 d3 g* n
|
|