该用户从未签到
|
- import java.applet.Applet;
2 k& j( ?( x* h# x5 t4 A - import java.awt.*;( m( I7 V4 y5 Y
- import java.awt.event.*;+ w+ m+ t. O' {0 t" @
- import java.util.*;
( I2 l+ K! l7 ?5 ?& | - import java.lang.*;
- A: h X; z Y# R- n1 K- [9 `4 `
5 d+ V( p+ }# |4 s- public class Students extends Applet implements ActionListener
2 l8 O8 c# M3 G, _* b# _ - {
, m1 R/ t) k) ~7 N - Vector StuInf=new Vector();3 N( y3 T. x. _0 \6 l# q5 t7 t' ~: v
- StudentInf SI;3 @" k5 F @. F' O
- String xm;
' y5 M. {6 k4 S8 b7 M! E6 ` - String bj;
" @. x+ H$ g0 t6 Q' l# w) J& ? - int i,j,xh,cj;8 _0 [4 i# G" V
- static int mid;2 K4 C8 x# j$ y$ |
- Label prompt1=new Label("学生成绩管理系统");
; E3 H$ O$ [, `8 q9 y$ f% ]9 l - Label prompt2=new Label(" 用户:"); }: O- P9 M( d+ j! F
- Label prompt3=new Label(" 密码:");, \. y3 C! A- }9 l
- Label prompt4=new Label(" 班级:");
: b. }" d0 C7 K I - Label prompt5=new Label(" 成绩:");* E Q8 f, [5 e" x S
- TextField input1=new TextField(8);
, j+ b) H" H& |' L3 [: V - TextField input2=new TextField(8);4 j0 F$ V5 ]! b& P3 u0 ~& _8 v
- TextField input3=new TextField(8);
' m! m; k* B+ [6 P: Q% s - TextField input4=new TextField(8);
8 x5 K# a: Q. ]+ O2 u4 n: n - Button btn1=new Button("登录");- c: z! ], i- G6 h
- Button btn2=new Button("增加");
2 V# R& d; h) Z0 L7 T* G - Button btn3=new Button("修改");: Z; ]& ^3 N5 @! `2 a. p
- Button btn4=new Button("删除");
" U2 i# i4 z' {% o - 2 ^) w: C9 ]7 N7 ~+ [6 T; |8 O
- public void init()
8 j/ ~4 }& I7 \0 o: f1 z C1 s - {9 S% Z0 A+ d$ [+ ]
- setLayout(new GridLayout(6,3));( h: ?7 k: e% ?8 b, k
- add(new Label());6 n) e5 ]# S! q8 ^ _ }$ {
- add(prompt1);$ }# i9 k, E a1 v$ D* r5 V
- add(new Label());
/ N; {0 g; c f8 N3 o6 ~, B& X" ~ - add(prompt2);$ B4 Q, t) r2 ^6 Z
- add(input1);
/ V: d+ w }; w4 t2 I - add(new Label());- O& y6 r* `! R" a6 l: Q
- add(prompt3);" A8 @- d' C8 K1 ^" L1 \# J1 N5 |
- add(input2);
- m9 N* K; U' z - add(btn1);2 ^3 e* A& \* M
- add(prompt4);
" j8 w) U0 ]' a" M) P - add(input3);6 z" _% i1 O0 a
- add(new Label());% W# n) S' y6 C- z: |- D) N5 w
- add(prompt5);3 x- {7 P2 K: r( f9 [
- add(input4);
+ w- n0 P7 A# I9 n1 W& c: k - add(new Label());
6 E- O) c+ V) P2 ^# E$ ~. D - add(btn2);
{% j7 G2 P. j, c1 Y9 w - add(btn3);
+ R! H* u9 w* ^0 D - add(btn4);
8 |" \ o! Y/ p0 L - prompt4.setVisible(false);
8 t6 g8 H' o' A - prompt5.setVisible(false);4 r) ?* s1 Z* b7 X1 y: V
- input3.setVisible(false);9 I! j( \6 D# c
- input4.setVisible(false);7 A/ e6 \/ W H! @6 Y" j
- btn2.setVisible(false);7 N' |. [* r2 f/ b( G0 {4 b
- btn3.setVisible(false);2 G. l. e) R, X6 Y$ l4 }
- btn4.setVisible(false);
}/ Y4 Z5 c0 j - btn1.addActionListener(this);/ W/ a' Q |5 S% Y% o$ e/ x
- btn2.addActionListener(this);# f) x9 I: p) K4 C, ^
- btn3.addActionListener(this);: a: Z) s9 i+ J" S
- btn4.addActionListener(this);/ `! r8 S- x3 H) {" @+ V* _$ d
- }
" R2 @# T% U4 O- }2 p - public void actionPerformed(ActionEvent e)3 U& V0 t; s: t9 L+ K }1 Q
- {
/ S4 v' K, e% i/ M' Q - if(e.getActionCommand()=="登录")3 B- ]7 h6 M; j2 c/ r% l+ G
- {
, }; x* y% {7 H - String a,b;
! z/ |0 D3 Y) `, ]7 i+ f' Z. C - a=input1.getText();
$ V e6 F$ ]0 j3 i - b=input2.getText();- { \+ u+ c# |. ]( D! a
- input1.setText("");( u }2 e% a, n/ G( {$ Z" x
- if((a.equals("12")==true)&&(b.equals("12")==true))1 ~. ~; u f- a) U
- {
V* y. f& [2 v. d9 e* v/ A8 m - prompt2.setText(" 姓名:");% T8 L" z6 k) f0 a+ H, g
- prompt3.setText(" 学号:"); ) i8 d( {% }4 K: n; A! j
- prompt4.setVisible(true);1 Q, r. Q- ~& A2 I/ N# o% H
- prompt5.setVisible(true);
+ a8 O" O& k' n, { - input3.setVisible(true);* C0 `0 g0 `) D" [
- input4.setVisible(true);1 y4 ?+ `% D \ @3 y1 ^
- btn2.setVisible(true);
$ L$ d" Z4 f( x - btn3.setVisible(true);
2 y' S$ m8 p3 p$ [+ W& S/ @ - btn4.setVisible(true);% a0 u+ `4 j/ l( N$ ?% V. N p E
- btn3.setEnabled(false);' k7 e/ P. t0 |/ y+ W" l
- btn4.setEnabled(false);
. V0 u% @8 U f T! W% F - btn1.setLabel("查询");8 F; R! p) P, A: C4 ?( j$ I* r
- input1.setText("登录成功");
8 e) ?$ N& t4 b: G m. g, c' _: g' @ - input1.selectAll();6 ?$ X1 G' c: ]+ c. w5 c
- }
4 B- v4 a) \1 t% C- x; h' m# Q" B) G( P - else5 k6 f- u5 u8 K2 t4 W3 B
- input2.setText("用户名或密码错");+ g" T- k5 p7 d8 U, V- `
- }. ?& K$ V( e/ ~3 R) C( f: m
- if(e.getActionCommand()=="增加")
, @. k/ R: m6 ^2 ?4 f - {
9 N8 v5 ?( W. b; r+ U - boolean scucss=true;+ u. d, D1 u' i8 l* S( v
- try7 P& h8 \. G+ P6 X: R. |
- {
f$ ~5 @* `8 ]5 U; S7 O+ ~ - XingMing();/ Z: Q8 |/ G$ ]
- }& x: h" g/ r( i7 I4 d( G2 {
- catch(EmptyException as)
8 n7 e/ N. Q, T: X! J0 t - {8 Z/ A% T1 F) m! c' l+ ]
- input1.setText("姓名不能为空");& ?/ X4 t n! i* P6 U, H2 S/ Y' G/ w
- scucss=false;+ ]# u6 E2 d) Z& f! H6 x$ _
- }' s- n# P5 T2 h0 U! U) q% I' M9 B% h
- try
2 C; k/ M7 r7 R2 C, X; z - {
, O1 {+ a* _% \5 N5 e( ^- ] - xh=Integer.parseInt(input2.getText());( u$ N9 R0 G: P5 r0 x2 |4 q
- }
! R l( @0 t8 N* X - catch(NumberFormatException m)5 }& B+ ^: l! |. i( R. c
- {
4 \( e! ~( \% y& I1 }" v - input2.setText("学号为空或格式错");
0 {8 E+ Q3 M+ [2 K - scucss=false;' q! G2 [! D2 D5 G; `1 J# R
- } 1 h" k# _$ D5 O6 N
- bj=input3.getText();
* W7 l& b) K: v - try! t( N& s0 I' a2 |- s# O
- {
/ j$ f) _0 t6 `5 u - ChengJi();$ j- E3 p+ D( |% e% B% X
- }
. j, x- {# a! B, z( J f t% H" M - catch(EmptyException as), o/ f- Q& j6 d0 U2 K# |( ^" Q' l; ~
- {' L$ x! _ H3 o3 X1 d
- cj=-1;# Q7 g4 c7 V$ ^" a
- }
$ p" Y! \! r% ^ - catch(OverException dd)
4 g* ?0 Z- k3 u4 \+ H - {
; N" H5 L( e) k, r4 V - input4.setText("应在0-100间");+ b7 S/ x8 l$ ?' N5 g/ j1 l8 G
- scucss=false;/ {& O7 U/ y# m3 P. _
- }/ H" X( \, T8 c0 S
- catch(NumberFormatException cm)6 [% w( S& x0 T( B7 u* {% j4 m# ]
- {; J& ^! E# S) R& q. c. j
- input4.setText("成绩应为数据");
3 j" K$ z; R1 q5 c - scucss=false;
0 ^- h2 }" a7 ]3 v, y+ K; g* t X - }! I+ ^" R- @" M: D, a5 N0 g! M. z0 g# X6 k
- if(scucss==true)
: ~: C Q8 ?& a# I" P - {' [/ p5 R& j9 `" r
- SI=new StudentInf(xm,xh,bj,cj);
/ E! w7 `# e9 V Q - Insert(SI);
0 R6 }3 o+ ~" B4 W" \/ m - }
- H8 { D& X( D+ ?" e - }
. a. T. y1 _" H( }* {; Z - if(e.getActionCommand()=="修改")
( S8 [$ d# H" m0 n0 _ - {
+ c3 v7 a6 d" U, Z9 }3 t$ `' {- N - xm=input1.getText();
, l- T& H) W8 n. J+ d' m9 N - xh=Integer.parseInt(input2.getText());
, U/ k! W/ z9 C: ~: t - bj=input3.getText();& w# g& R8 k8 r( R! N" w* N
- cj=Integer.parseInt(input4.getText());
_1 X. Y- e3 J - SI=new StudentInf(xm,xh,bj,cj);
, e V# x( S+ f7 l) L - StuInf.setElementAt(SI, mid);4 V2 ?, y, M( T( p" e' \+ _" k
- btn3.setEnabled(false);+ H2 Y0 `( H/ u) ~
- }
9 H/ ~9 e, }6 N3 }4 o# \ - if(e.getActionCommand()=="删除")
$ ?( T; a% r X# F4 I - {
; C; s$ X8 s6 A2 }: W - StuInf.removeElementAt(mid); * F- q2 S0 Z, X7 O9 E
- btn4.setEnabled(false);3 l# H- R- \3 ]- H7 ?. v
- input1.setText("删除成功");$ p5 O0 J$ h7 ^! K A
- input2.setText("");
$ B- D: I4 B4 }9 D! n - input3.setText("");: V% ]. K, d: p
- input4.setText("");; o5 m9 J1 m T* @; l. m
- }
( i+ a" M/ e- ]: y+ P# E% i9 a - if(e.getActionCommand()=="查询")7 K( G- v& p! m
- {7 m; A# w6 B' D, K( C
- boolean right=true;
0 z9 ?1 f% N; u) I$ N7 ? - try5 p8 v2 r# B" o5 i
- {
" I1 ~! R5 I- j0 v: l) A - xh=Integer.parseInt(input2.getText());
. z4 J8 N% a/ P- _) k' W) c! s - }* _* h( y! X, @0 w7 |4 _3 T& ?
- catch(NumberFormatException m)! h5 P8 D* L+ ?( d9 u5 }8 t9 t5 k5 x% P* v
- {' w0 ?& A6 o, I, N" e( F
- input2.setText("学号为空或格式错");# } s/ ^% g& {0 n/ w4 o
- right=false;
7 l& o) d( Q6 [- ?4 R$ a - }
# P$ M. a; @) l: ]% Y5 d# p* i - if(right==true)+ G& }/ Q- r' |6 X0 H$ e, e
- {0 F% h; \2 l, i5 J5 _, ?+ O
- search(xh);
' b% s6 r7 C9 B0 m; L ] - btn3.setEnabled(true);5 n7 `+ N' y! w# Y$ ^
- btn4.setEnabled(true);
6 J1 E4 c3 }2 I. T+ H9 M - }' U! l5 B. U, ~3 r6 Z- w) ~3 N
- }$ l4 p% D, } z2 E+ F s: [* e$ g
-
9 B$ `: f* a7 ^/ u% v! |& J7 H - }
3 T5 H3 b. O; y4 L, }: z: ~. y$ s - //查找方法6 _3 F% e: K1 b9 T0 D
- public void search(int k)8 u- X3 E! |& i4 ^3 z
- {+ l0 F/ }1 q w
- boolean exist=false;* b0 C" Q1 S/ I/ D
- int low=0;
& c+ `9 r/ b- ?( [. v - int high=StuInf.size()-1;
8 }/ T5 Q- L1 {1 g9 w0 s - while(low<=high)8 s) B# i7 F8 g8 g* j/ w* B9 T
- {
$ ?% G( c6 ^) X! g - mid=(high+low)/2;2 T4 w# @. a- n3 e7 T5 F
- StudentInf a1=(StudentInf) StuInf.elementAt(mid);
8 u G8 J9 s" B+ [. k3 K - if(a1.getStuNo()==k)/ o4 i z( B& }
- {
% o% ], ~8 K: d, a7 T( t" X4 E - SI=(StudentInf) StuInf.elementAt(mid);
- P( c- B3 s8 d/ q( ? - String x = String.valueOf(SI.getStuNo());
; H% } {0 G. y - exist=true;& R+ v0 d) T1 D4 Z
- input1.setText(SI.getname());: h5 P# t! i, F4 ~2 U2 u
- input1.selectAll();
1 b1 M& h# `8 ]. j - input2.setText("0"+x);% y, C, f) O# X+ h5 I! g4 q
- input3.setText(SI.getClassNo());' t7 r$ J W9 _. J' o
- if(SI.getLevel()==-1)
4 D9 g9 b9 c- l3 p4 s - input4.setText("未参加考试");$ O5 j! |' v# D9 H$ a
- else- X0 I4 W; j' @2 I! I4 ^
- {: u; n" f( N, U; ~" T
- String y = String.valueOf(SI.getLevel());5 A" f3 k! P- l: C! W* V
- input4.setText(y);
% h4 [2 r* ]8 z* b0 ^ - }+ T% k) k1 o, Z9 w T8 c7 C( K
- break;. N% \" \ k+ Q9 L s0 l
- }6 k$ T/ `: }" J% ]7 N4 X1 _8 K
- else if(a1.getStuNo()<k)
) L( ^( q* G9 z - low=mid+1;
$ g/ b" r0 {( T7 ?" W1 Y& X- k9 k" s - else
( p/ D" P m( B" H% J, c2 r! Y - high=mid-1;
$ b! U8 u# ^8 ]) y+ y3 M - }& L7 u* A) z: X# d) L
- if(exist==false): C# E3 a+ [/ L9 V+ O
- {
5 u3 x! c2 `' Q8 ]9 o - input1.setText("无此学号学生信息");$ [1 V6 o: F, J' B: D
- input1.selectAll();
% e& c& B% d# ]! |0 ] - }
0 }& C; d. G ^4 g1 u - }
6 Z4 }9 g6 v, O. J2 l* z - //添加方法
. V* W! }. h' e/ M8 @2 h - public void Insert(StudentInf q)1 m. J3 w% J1 p- H
- {/ b7 _! f8 O+ U; {. i& t
- int i=0;! f3 U' a3 P" w! J4 C
- " y! l$ X$ ?6 \
- if(StuInf.isEmpty()==true)
# ~0 a& C6 Y$ R( G) m: ?, Y - {) `6 u. a0 W* n& X$ c
- StuInf.addElement(q);: L/ w& ^" L# Z+ f* i
- input1.setText("");- v: U0 k" O K K4 E
- input2.setText("");# P) j; Z6 q* w2 V/ e+ ]; r0 r
- input3.setText("");' J# c' o: W. n8 {- b
- input4.setText("");& e9 l, } j3 x1 ?+ [2 ~ Z- x
- }( ^, ~2 K9 m; x9 z7 z- q
- else( ^9 }" y2 j6 P$ y7 L2 j
- { i& v9 m1 b# f) g( c t5 P: v
- StudentInf xh;
8 e+ w' M) W+ K - xh=(StudentInf) StuInf.firstElement();
8 W' X7 n, R* U s6 }8 l$ n3 d4 l - while(xh.getStuNo()<q.getStuNo())
) c" r3 v. Y ] - {
5 s! T' H5 N* u - i++;
1 ?; W9 e9 m: c - if(i<StuInf.size())
9 _# e1 z+ G! f/ K& x7 Y - xh=(StudentInf) StuInf.elementAt(i);
) `6 l: ~! l" U/ v9 s - else 8 @- x+ ]' w) r, x K, k
- break;
* f. M! L/ P* u( d0 H - }
1 I9 t. H6 P- c }8 k - if(xh.getStuNo()==q.getStuNo())
, Q3 j: c7 s/ [# H - {: e' |' U/ y: V! h
- input2.setText("此学生信息已存在");+ Y3 }- \9 F' D3 R" Z. i; h
- input2.requestFocus();
; S! c! T4 p& g; ^1 ^0 z9 |# w6 m - input2.selectAll();
9 {) v3 l1 x) U - }0 Y" ]1 u5 S! \. m. y# r
- else % W: b" [; P: g; V
- {
+ m/ e* w2 T8 L* j, I, C - StuInf.insertElementAt(q,i); 9 s) I" f# Q+ J. S0 D
- input1.setText("");
1 ^- A& q0 X6 \; ? - input2.setText("");; p5 _ ^9 B' M$ l2 h7 g
- input3.setText("");
! ?/ b! { x6 m7 R; p7 |8 P: H - input4.setText("");: B8 e* z6 P i: K% d' D8 i, W" _
- }6 U, \2 d; Z$ }: w" t b
- }
& e, { I" G* b6 j- L0 ^ - }
; w$ a& H$ U4 _& Q - ) s. ~( u A8 {$ O7 K6 V
- //异常类+ q/ ]& E* _1 i+ k1 ]
- class OverException extends Exception) b0 T5 Q! l! h" i( e
- {8 M) m& w( H3 R$ j. |! R
- String over;
) l9 E; @2 K! N: X: ?" _ - } & \1 I3 J& q& m& n' i+ E. Q
- class EmptyException extends Exception6 z/ f' h4 ?& K2 ~5 _2 ^0 w
- {
3 L6 M. n; e1 J$ z! K$ b0 F6 c, ~ - String empty;& v7 M7 r1 H" ?1 d" G
- }
; l8 F! _% I4 z4 ? - void XingMing() throws EmptyException2 x/ [: U4 `. M5 @/ S( @
- {
3 h) S7 o6 ]" `* ~ - if((input1.getText()).equals(""))
. R, q6 E2 j1 F - throw (new EmptyException());4 s) x- X" ]2 Q8 g3 X+ H" W) P+ l/ A& M
- else2 C+ i. Z% J( O. r4 ?* O" h; P9 Z3 G
- xm=input1.getText();
2 y! k1 w; a7 v, ~& k5 T - }
- L" @+ E2 J2 ~, j - void ChengJi() throws OverException,EmptyException
$ n( k. }; h+ t$ g9 A - {
: J5 j0 Q/ w# W) f - if((input4.getText()).equals(""))
9 o# W& F7 ]1 q, p0 G) ~7 n - throw(new EmptyException());$ F, d- M6 Z: [4 J! O4 l
- else
E1 Y1 P( n$ H/ Z( J) Q# T - cj=Integer.parseInt(input4.getText());
{$ _) k/ b* ^# Q - if(cj<0||cj>100)
4 h; T. ~! @+ \' @# s4 l - throw (new OverException());
( t0 U5 a( v# f9 D; o1 \ {! } - }
2 L9 @+ R/ }5 y6 K - G& m7 t7 Z* E8 W
- //学生信息类! ~2 H( U/ R$ t) q5 E" R; p
- public class StudentInf
* S+ [2 d- _2 A" ?3 l; `, q - {
4 z& e" K0 q; e1 e) X - private String name;
6 I$ h$ X/ k' r2 Z7 o - private int StuNo;
% ]7 P" a6 Z i7 h7 v f- [% [ - private String ClassNo;, f% \* V5 Q- n1 H+ g7 j
- private int Level;! _+ X2 W A6 u+ J( H
- StudentInf(String xingming,int xuehao,String banji,int chengji)
4 \" l e7 q; U) Y - {+ c- A6 p! l4 q$ b( a1 ?* X
- name=xingming;
3 A. W1 |3 _# ~! z1 N - StuNo=xuehao;
% z9 v2 E( a/ o y3 a' I# ~ X - ClassNo=banji;4 G( @% G( _0 {5 B
- Level=chengji;' v/ K# H3 L. n. ~3 w z
- }
/ j6 ~$ t% d0 {/ f* H - public int getStuNo(); h0 Q5 E6 Q4 Q# l$ Z0 K) E' b/ ^
- {; i7 s9 W: A: U; J( e6 @
- return StuNo;
6 Q# W4 @# `0 ^* t2 ] - }$ K4 O5 B8 V7 I& X9 \$ [, B
- public String getname()- W+ k& c9 x% u
- {; g4 K; q) |- T6 z4 j
- return name; l0 c& r( ?# T- t5 R! Q/ p# E$ [
- }3 M3 J! T7 O# { `1 Y$ M3 z1 { Z
- public String getClassNo()$ q+ W# r) h- M: ~, h
- {+ b+ D# T8 U3 M$ ]- p
- return ClassNo;% \. a! u9 b, u+ l: D
- }
6 T) H& ?3 |2 u- b: R4 d0 @ - public int getLevel()
7 g& E8 B. b9 h; P: R2 L - {
# }# q7 c! \4 g - return Level;
& z5 K4 }* S4 a. _) k$ U7 m - }) d, R) i( H. E- F% q: [
- }4 J I1 |! |( w3 ?- @
- " z+ X8 K; E: \; n
- }
复制代码
6 w- d1 o8 f1 @2 R0 a
0 J7 M; A6 F8 v0 K) h |
|