该用户从未签到
|
- import java.applet.Applet;
' o8 v; @4 v J. ~+ G/ `2 o - import java.awt.*;8 p8 C' h% S. L
- import java.awt.event.*;; ?& C8 s9 u* K# U( q* P; p# f
- import java.util.*;( I( \; {8 L+ ~* Z$ T+ J
- import java.lang.*;
5 C) q5 X+ [* U. R* }* L9 ` A0 `
% l5 s/ q' B9 L5 n$ [0 d: M, i- public class Students extends Applet implements ActionListener8 |! o9 b/ a" ^; R
- {
0 p. q0 ^! ?6 l' c0 V( N - Vector StuInf=new Vector();
# k7 F# e! m( i2 B% @9 }' P4 s" J; n- B I - StudentInf SI;
$ q/ b# k) U% @6 D - String xm;% H5 q3 t2 f/ ~2 Y
- String bj;1 P/ ~3 H ^3 W3 O+ Z5 e8 C
- int i,j,xh,cj;; |% f$ r% W6 Q9 O- S& M- _. K# F
- static int mid;6 b( [5 G( ?) }
- Label prompt1=new Label("学生成绩管理系统");
5 o" x( T% R, n% {3 m - Label prompt2=new Label(" 用户:");
! M2 h. q$ j/ J0 [1 P& {% _ - Label prompt3=new Label(" 密码:");- r8 w1 u4 p6 l6 {+ D6 q8 B% z
- Label prompt4=new Label(" 班级:");& X$ A6 z* `( R( @, z' ?
- Label prompt5=new Label(" 成绩:");
' N" s8 K* m0 e - TextField input1=new TextField(8);. g4 d( F' p! y. R/ A" p
- TextField input2=new TextField(8);/ G V- k7 v8 t( m
- TextField input3=new TextField(8);
. b& I. H/ `9 y" V) ], e - TextField input4=new TextField(8);
, r3 C/ p# N: z7 q - Button btn1=new Button("登录");) P$ h9 n+ O/ V6 t6 y: K
- Button btn2=new Button("增加");+ ?3 h+ G2 l3 o- }
- Button btn3=new Button("修改");4 J! Z0 w( Q$ O; T) e: A- g8 `9 J
- Button btn4=new Button("删除");
# b6 `) w% f; ? D - , P$ S7 N+ C0 d* w+ p
- public void init()
4 B/ V8 s: D$ O0 l- E# Y7 ]. U - {( H6 r* o9 Z: P6 P$ }
- setLayout(new GridLayout(6,3));
( m; j, M& Y; E( T# d1 T0 y - add(new Label());
9 W5 e0 s/ T4 z - add(prompt1);* Y5 T5 y& Y0 q+ [
- add(new Label());
, p# J6 D' t4 |2 M- ]; Y - add(prompt2);' a% X0 [" Q" d7 L8 K, P
- add(input1);
7 n6 |' E6 E+ R% d - add(new Label());
! { {' ^$ }2 D( w. g. u - add(prompt3);. P/ e1 u0 ^- V s: ]
- add(input2);9 I1 \& G/ {% ^: Y9 v4 K5 k; t
- add(btn1);: ?2 J" s% m0 h# m
- add(prompt4);
3 R) J# B h6 u - add(input3);
* U8 [1 ~$ a. a, @ - add(new Label());8 g, C( s8 A' U- s. D9 s; K
- add(prompt5);
! G- M5 d" T, @: D - add(input4);7 y/ ]! W- Q- j% P5 }. x
- add(new Label());
- R$ U/ k. b$ P0 |; H& B$ X1 V/ k - add(btn2);
* C9 a& z9 r; }& g - add(btn3);: J ?8 q& G& |6 y1 u
- add(btn4);
. Z# I x7 v6 J - prompt4.setVisible(false);
, P# |! o4 x* ~* I9 l* N - prompt5.setVisible(false);
$ u5 V5 Y9 a* h8 y - input3.setVisible(false);8 N/ R4 m$ d7 i/ m; a
- input4.setVisible(false);5 N- v# h, X8 |
- btn2.setVisible(false);: H# I6 s" R, P& R4 [' s
- btn3.setVisible(false);9 a" T( u" m5 s9 X, R/ s* p; w
- btn4.setVisible(false);5 P+ w- }$ S/ ^1 W- W0 \
- btn1.addActionListener(this);- ? N+ T& C; {% P+ M
- btn2.addActionListener(this);
, x! U1 l- O9 X/ S - btn3.addActionListener(this);
, Q# ` o, i" [: p( d; D. T - btn4.addActionListener(this);8 L5 {& x x/ u/ x/ z( |, o, Y9 N
- }4 s3 E# Z: A/ [' ~1 d
- public void actionPerformed(ActionEvent e)) u4 k, `5 E* x3 y$ D
- {
( G! G( c9 ^5 C m - if(e.getActionCommand()=="登录")
5 E* r0 E+ U$ [; G$ m% w$ j - {: c1 S3 H9 _# \ C
- String a,b;# i9 G" M5 H+ D. c, O- A% C; q+ z
- a=input1.getText();1 L0 S2 ]" i" M
- b=input2.getText();5 W; R8 B0 F4 {
- input1.setText("");& w: ~" ^& |& `; w+ L
- if((a.equals("12")==true)&&(b.equals("12")==true)) Q! s, H0 x1 l3 e. t
- {
( e( U$ z0 r1 [2 c3 Z - prompt2.setText(" 姓名:");0 `, q8 M6 ?! t1 A" C, W
- prompt3.setText(" 学号:"); 2 a3 Q$ _: w1 h( C
- prompt4.setVisible(true);
" T/ N0 a1 \" N - prompt5.setVisible(true);( R" a) I' }7 J8 b9 y
- input3.setVisible(true);
! A1 e: U5 c: i! {4 x) k - input4.setVisible(true);
* z0 O o! m1 n# u: b - btn2.setVisible(true);! w/ y) |3 P O! h* K0 ]
- btn3.setVisible(true);
6 {# P2 _5 [, d; g% d0 r. `, K$ c - btn4.setVisible(true);" s8 B+ D; O- ]& B5 `! L
- btn3.setEnabled(false);
% n, G8 z6 d4 G4 e& ~0 a" j - btn4.setEnabled(false);3 S$ P( K- p& @" ~* v; J
- btn1.setLabel("查询");
# c* A; D5 f- ]) w* _: } S9 l - input1.setText("登录成功");* ~# f2 f/ S* g% }
- input1.selectAll(); z% b0 `, M4 C! p( r1 h
- }
/ U7 Z, H0 M8 R+ c3 f; ?! b/ E - else0 E: w+ @- t% z" B
- input2.setText("用户名或密码错");
! S; p0 C% a0 S5 G+ O/ x- ` - }
8 s$ Y3 Z$ c5 Z% d! j. I - if(e.getActionCommand()=="增加")
) R0 |" {. @5 |( K7 S Z+ B" k0 ? - {# P u, e; E) X+ j1 S) E
- boolean scucss=true;
& A0 G6 R2 n8 N* N& B - try1 ^# \: e) E0 o/ g2 e
- {5 o' a6 X9 X8 m- M; h1 S- p( s! I
- XingMing();9 j; t t" i v) L
- }
1 z# O$ X) w. o6 g* J: @ - catch(EmptyException as)
! U# D) b2 F! b1 w2 i* p' d2 D - {
( Z* i E1 w$ N& s- H. R: f - input1.setText("姓名不能为空");
5 D! ~9 C2 R8 A - scucss=false;, L8 Q$ t" E6 K: O) x
- }
7 V& Y& ]- T; x0 W. l9 ~" O. X; h2 r - try5 ]7 h" b t% [! d* { @5 `. y9 M
- {
" t) F9 g' x, W) a* `- g3 Y - xh=Integer.parseInt(input2.getText());
" f( O' O- ^) y - }
) s0 ~; g& C9 z - catch(NumberFormatException m)2 R2 o4 T6 B1 i2 ^
- {
4 B" o1 O* Z$ p/ B7 { - input2.setText("学号为空或格式错");1 {2 P' q- X5 N
- scucss=false;( D* {( ^! ^) x* g# P# q9 l& y
- } 2 i3 E h' W3 o3 V/ ]* y
- bj=input3.getText();
: q7 z/ T2 C( ~6 Y% J7 W2 b - try
% y2 i8 y' I$ G! z - {
. Y) a: @* k7 U8 B* S$ b8 H - ChengJi();
3 u% F# M9 A/ F; L - }
6 t& \% b$ E3 U% N+ h% K - catch(EmptyException as)
. x* D; J1 l$ M( Z - {' ^; `5 T I' j5 I
- cj=-1;# r8 o8 [, ?, g: O7 p2 {9 _
- }
- y( L" p# `3 p - catch(OverException dd)" S4 g0 W* j R/ G, N- w+ Q) f
- {
9 Z" w4 Z& I- h8 e, k. s - input4.setText("应在0-100间");
8 g$ j# \! q. B - scucss=false;
?8 P7 b: I+ t8 W+ U* v) q - }( Y' `; \! F* }$ s) \0 @
- catch(NumberFormatException cm)
0 N' b) ^) i& e& r. Z) v - {
* w% H4 t( A; h' Y3 a( C - input4.setText("成绩应为数据");: Y, Q. F5 @7 S
- scucss=false; - V) r( L/ q2 Y1 X. k
- }
' [# @" c# r/ Z- R - if(scucss==true)
E. F5 B/ M! T4 f - {
: [ X! s" q2 W6 t8 m4 F - SI=new StudentInf(xm,xh,bj,cj);
/ Q0 p4 C! D2 C* _ - Insert(SI);4 N6 Y9 u6 Y* `; m/ B( P# ^6 b
- }9 _) Z, U2 M# `! k' E: _
- }4 g5 l9 N9 A* |# y
- if(e.getActionCommand()=="修改")
. }8 s- k4 q- x5 d& q ^9 Z8 _' q9 ~! J - {# x' U9 K( i! H ?
- xm=input1.getText();
4 |/ N# d: u# a* C0 B, ]' a+ V - xh=Integer.parseInt(input2.getText());1 s( l& g0 {1 c: s% j. u
- bj=input3.getText();
. E# j% }( K+ T! \6 ~- v - cj=Integer.parseInt(input4.getText());+ A+ N; {) f3 p3 r
- SI=new StudentInf(xm,xh,bj,cj);
8 S! {2 R8 Y3 {3 I - StuInf.setElementAt(SI, mid);+ c2 m( \& D0 c* S
- btn3.setEnabled(false);' @* X' D7 k7 B8 q. E
- }* R+ \ R8 i7 y. O6 Z+ m
- if(e.getActionCommand()=="删除")
, M- e1 J w0 `- ? - {$ d: x9 g T S* t. t! B0 ~ M3 J
- StuInf.removeElementAt(mid); ' [7 L! ^9 [ W
- btn4.setEnabled(false);+ `. u1 B$ W7 f- _$ G
- input1.setText("删除成功");
+ u1 h1 C* J+ `7 \0 K/ x2 {0 s: n9 c3 j - input2.setText("");$ ?# B+ ~% ^* z
- input3.setText("");
; Y$ c& X; C' | q2 t1 a - input4.setText("");2 ^5 Y& X6 }: m7 S$ Y/ R6 n
- }
! c# x( Z1 ^4 V, j. m - if(e.getActionCommand()=="查询")
! I) @" s! I' e! _/ d V8 ]3 ` - {! [# c: G/ s, z# k+ i, b8 E$ a
- boolean right=true;! J2 d$ o& r3 H: w a# f
- try
( g9 f- w5 v! t I9 E- W - {" C1 q9 D/ j8 m- }
- xh=Integer.parseInt(input2.getText());. h( ^- w8 \7 `; ~ m2 A9 j
- }
3 z+ d6 e- d9 j0 e5 r - catch(NumberFormatException m)
o. a$ S9 D% l6 u - {
! t# y# {- \( k+ b8 r7 Y - input2.setText("学号为空或格式错");
2 l; ]5 ^- N! [6 ~9 _" g1 F9 [4 F - right=false;
8 t+ Z a2 K* Y% F& u3 ?5 u - } ! ]$ [, j& z) |4 b9 A1 @
- if(right==true); P9 Y- H$ a4 T F4 z
- {2 L$ |/ `, U% p" t) x; X- {
- search(xh);
1 L* E9 K6 A, n( z- S2 J1 V - btn3.setEnabled(true);
. H# F+ W9 J& `/ F3 @ - btn4.setEnabled(true);# z4 Y1 b/ r( i* n7 Y4 v
- }
' b' {8 v* H9 F, p; v - }4 Y0 a" U6 m" x5 \1 X, O- w. T
- ' y m' N1 a1 m N- W$ ?
- }3 d8 O, i- Y+ H& B# x2 ]* }
- //查找方法
. G' u: j' L/ K( S - public void search(int k)
3 _8 ]0 ? }7 O: J4 {& W. i - {+ ?* Z9 j( [$ h& s7 @; g
- boolean exist=false;
& d1 a2 ]! e3 R# T e* p+ R9 U- i - int low=0;
9 R& I) k- Y: {0 h7 e# M" g - int high=StuInf.size()-1;
+ R, u% ]6 r# \2 \ - while(low<=high)
; h `; T8 a# s5 F - {
0 d! W0 W4 _+ M2 t. N. F i - mid=(high+low)/2;+ ^4 y/ c6 H0 q% t6 b
- StudentInf a1=(StudentInf) StuInf.elementAt(mid);
5 E& G0 M1 C, h& n) X9 G7 g2 U - if(a1.getStuNo()==k)
" d: g% V) ?4 d( _2 B1 n - {
" X7 b- H5 P- Q w6 _" G# ~9 e w - SI=(StudentInf) StuInf.elementAt(mid);) S, x, g% Z1 R+ I' J' u3 C
- String x = String.valueOf(SI.getStuNo());
' e* m( U* v1 L/ M/ o5 [* G - exist=true;! S; L8 x9 w L
- input1.setText(SI.getname());
1 w, F6 B' Z$ F - input1.selectAll();
- c! F0 I7 [5 T) Q. @ Q - input2.setText("0"+x);
Y9 x0 ]( [3 l. X" V2 f7 X7 Q - input3.setText(SI.getClassNo());$ k. `8 M# C/ w) o+ ]1 W
- if(SI.getLevel()==-1)
* d- x4 ?& g9 Y7 z: G3 b8 |3 \% r - input4.setText("未参加考试");+ J4 F; l+ k, C |
- else4 C' B5 D M. K8 r7 M6 H+ x
- {
4 N! J# V- J4 G( ]! U4 \0 ~ - String y = String.valueOf(SI.getLevel());# t; N* n2 A, o7 t; _
- input4.setText(y);! f: j$ p2 _8 d9 y$ |
- }
$ g: C, G! `: k$ G+ { `) F; I - break;9 z) d+ n3 l. C* u
- }
5 z9 \! T# _* Q; ? - else if(a1.getStuNo()<k)
& n( B/ _4 Z6 s; o' K- t9 @ - low=mid+1;- Y) s* X$ g# w6 U. f4 O
- else! O% d( x" i: i. S+ [) q5 J
- high=mid-1; % z% |3 q; _8 S! W9 p+ p
- }
3 e" h7 t p" }2 X2 J" o; o+ F6 Z - if(exist==false)
% F8 s$ O( [% k; X - {
8 |+ g& z% I$ [$ |/ G$ {' { - input1.setText("无此学号学生信息");( V* L* O& S- }4 z
- input1.selectAll();
/ Y4 P8 S B% b. L0 B- r3 Z+ Y - }& R2 ^) h4 _8 U: z+ j* z n
- }$ } Z, {% Z( B& R, Y- p2 X
- //添加方法( U- \" Q% P7 j& t1 f
- public void Insert(StudentInf q)0 g* o9 t( K1 d9 [6 a
- {
& b) y0 V; u: ?8 r9 o6 k" X9 n - int i=0;
+ c/ [( x$ k9 G$ U# X -
" k2 g# z% F$ Q6 k7 H - if(StuInf.isEmpty()==true)
9 B: F9 J/ ^: ?' p - {
$ x0 |8 B7 t9 `( f( x5 R - StuInf.addElement(q);
+ ]6 O# l% r$ L - input1.setText("");
$ d" v, z4 s& k/ X9 [) k! Z, q - input2.setText("");& g5 {% T. d# f& B$ Z$ Z- i& l
- input3.setText("");
) F! _& L0 V: w. m - input4.setText("");
& O: X1 m1 ], s0 O Y - }& F) {0 B' T' t4 N# w
- else
5 g/ B- ^4 x( A+ r - {
# e! |9 ^0 R: a - StudentInf xh;
5 V: f; O- x* n9 n6 w) X - xh=(StudentInf) StuInf.firstElement();+ k# ]" A |+ J9 P/ x1 ^+ a
- while(xh.getStuNo()<q.getStuNo())7 [; D/ s% {4 x$ z. ^
- {
" a4 X3 X7 c) ~4 A - i++;
( W2 v3 T) b( V8 W, q - if(i<StuInf.size()) n& V$ _4 L3 \" ^! w& M. r, o
- xh=(StudentInf) StuInf.elementAt(i);8 q0 ?0 V! h2 w2 p' j
- else
& a! Z. P. e" X9 N* O, R$ M, V4 m+ A - break;. K5 H2 \8 G2 W3 [# Y2 F0 d& H
- } , L2 K9 J. X) G4 U; _9 N7 d+ q
- if(xh.getStuNo()==q.getStuNo())
$ Z: A# N# S, |' ~3 _ - {- ~) l3 E1 g6 Z! Q2 n7 U: o
- input2.setText("此学生信息已存在");
: K$ U9 R" b9 S6 o( I4 w, ] - input2.requestFocus();
- y9 F/ w% m9 E' u - input2.selectAll();
; u& j4 A* c8 g: J: R: @ - }; R2 S1 i6 U$ U
- else 2 w1 L' W3 A& h
- {3 K3 K6 B2 c8 _" ]
- StuInf.insertElementAt(q,i); & O( w, A. O; P
- input1.setText("");
' A3 y/ C1 a' N: p: O - input2.setText("");
9 \* s' Z' d$ O% C9 P/ e - input3.setText("");" l$ o2 |1 O7 x4 g; b
- input4.setText("");( J* I: J2 Z1 ]
- }
. z7 N( F, M0 ~$ r i: p - }
+ k2 }4 E' s( s8 ?) H. H' r8 R- P - }8 C# ~+ V$ _: \/ I8 B
-
C9 B0 `6 }0 i0 v$ y9 y/ F - //异常类! @! ~1 g& n5 a
- class OverException extends Exception
2 W1 z" U/ ~- c$ a: _; v - {# X: e$ z6 S* n! z( X. U) w; I
- String over;
( s+ ?& X, o- L7 y - }
1 [+ I# `! B2 u2 D2 j" n - class EmptyException extends Exception: T& g( G- @: _( j- I9 q
- {, u$ Y: M9 r0 R, H
- String empty;3 b( e0 {# _. t+ z# a
- }- c/ ^6 o% ^9 p( ?3 ~7 D
- void XingMing() throws EmptyException& A! X1 C& Q. D, W, U4 _8 |
- {4 z; [9 }" `, q' K, n4 x
- if((input1.getText()).equals(""))6 `" {; N5 w0 \7 u7 Q2 j5 S: N
- throw (new EmptyException());- C0 a$ N9 x5 A& v
- else! d1 o d- x3 Y0 R( U2 r2 k+ v
- xm=input1.getText();
7 r! A8 {0 R; n% { - }! H: @3 |9 b$ |4 Q% g! U
- void ChengJi() throws OverException,EmptyException 3 ?0 K Y* O4 M' L6 W6 h" i
- {
1 g k4 w5 W3 {2 j# N+ H7 ~0 M) |; z - if((input4.getText()).equals(""))
" S% ?4 W3 a* w' v/ I8 D1 ^ - throw(new EmptyException());
) v3 g0 ]9 n- n+ I4 S/ g+ M - else! N8 Q- _- v( C0 o' z7 p
- cj=Integer.parseInt(input4.getText());; o+ |/ d2 i/ I, |5 M( t" y- i) I
- if(cj<0||cj>100)
# j; ~. l( U& _! Q# Y" U - throw (new OverException());) l" i; K" C; N6 h$ E" p
- }
- t, [7 C" s6 C4 ~ -
% U9 }* f- ~+ e - //学生信息类
) Q! X& L* e. L/ l' ^( I0 w$ c$ g - public class StudentInf3 C- ]6 a# \9 X' g: S
- {5 ^! e4 ]7 C7 K% S$ V
- private String name;
/ k1 ]/ s. E5 {6 ~ - private int StuNo;
, w7 N" x7 P2 R- { - private String ClassNo;) y; j' J& u" D
- private int Level;) ]; z' X2 b. r+ Z
- StudentInf(String xingming,int xuehao,String banji,int chengji) ~+ d+ c6 A5 W8 p7 l8 t. t; M* A4 I: E
- {* |; h5 X/ r; C' H' f( w
- name=xingming;- I7 \3 ?: ]( L" i$ h; {
- StuNo=xuehao;
1 X" a/ d) y4 ^ - ClassNo=banji;
0 R: }; Z+ X p# j: l2 p - Level=chengji;
% s+ o' H0 _2 I$ \' N - }9 z: G6 G* M& L8 Z
- public int getStuNo()
0 W! K: z' p; e' Y4 B! b - {6 L0 W; h2 T; e7 d2 W: Z
- return StuNo;
8 x8 M s% r0 n$ W - }8 u2 K+ o! U7 E: h4 z! V3 S
- public String getname()% w: b- r4 ~0 u/ A
- {! ~. ]. @ a+ J8 j( _
- return name;
" V; `$ f( e7 U- L, l - }, L) P; ?' ~* \
- public String getClassNo()
* j- B. M, ~' N0 r - {
. Z$ W1 v9 O" w - return ClassNo;
% w( O' C( u. S- B) B4 C5 D ? - }
: y8 f3 T @1 o; B0 I9 d7 [$ N% a+ t - public int getLevel()( k/ C: P( P' b0 k
- {
- V0 r& R) N5 |3 e - return Level;4 h& @* O3 j& O% d7 y
- }
. W* x+ d% x0 s3 b- @ - }
, J( ^5 P9 e7 u
5 P7 M4 o' x1 h! R! `- }
复制代码 7 k# H+ w0 t. m @! }; P" y9 T* j
; G+ m a7 o; I3 J! m) C |
|