该用户从未签到
|
- import java.applet.Applet;
1 R/ {/ p3 \7 ?3 b5 p4 ^7 ~ - import java.awt.*;
5 \- ]0 i' A! `2 [# V+ }! Z - import java.awt.event.*;
5 @# Q2 ^6 J2 ]# I0 g8 a: E: ^ - import java.util.*;5 b! A" n) [- N
- import java.lang.*;/ _" p8 x, {7 [4 I
- & \4 E* l- B7 P5 f3 R# v/ {% c- A
- public class Students extends Applet implements ActionListener
" I/ p* Y0 n z% Y8 Y9 ~8 e - {
0 r7 N9 h' u9 m) K - Vector StuInf=new Vector();! f i/ c8 w$ L& ]# ~& B. _
- StudentInf SI;: Z! d2 g! j* V
- String xm;
/ e% W4 {3 K' g& x6 u' r0 x - String bj;
' {3 Z$ Z& h6 q1 F - int i,j,xh,cj;
) W! ?* R1 X( }8 N - static int mid;
* ?! Y/ x: C8 p6 s5 q4 y - Label prompt1=new Label("学生成绩管理系统");0 \' l/ _4 D, E; ]
- Label prompt2=new Label(" 用户:");1 n! D# E) ?2 p/ b. w: n
- Label prompt3=new Label(" 密码:");
, q P- @4 b- W - Label prompt4=new Label(" 班级:");2 C/ ~! R8 Y' `" x
- Label prompt5=new Label(" 成绩:");
! }( a" b6 P, L: h& s2 @ - TextField input1=new TextField(8);5 w& y. I, I2 _% V- j4 [3 d Q1 z
- TextField input2=new TextField(8);0 w9 L3 T% I) c' o- j* k- f! W
- TextField input3=new TextField(8);
4 L6 ?) ~2 E* J. @ - TextField input4=new TextField(8);
% h/ O) s! i6 R6 h - Button btn1=new Button("登录");4 y* E7 j9 j. c# u& t, B4 d
- Button btn2=new Button("增加");6 V& x+ d" J, e, G$ W ^2 B
- Button btn3=new Button("修改");0 }- P+ K% _% o- \
- Button btn4=new Button("删除");* O9 m$ O8 E7 z
-
) |9 K6 I: \; Z; f7 [3 t - public void init()$ q* _+ e4 v) T* s0 p
- {# K# q& M8 I' a+ r: p: o
- setLayout(new GridLayout(6,3));/ B2 e4 Z/ p, V+ `- S
- add(new Label());: U3 e u! y7 s( X
- add(prompt1);0 ]' ~- N( J' Z3 j% C7 \# f' ~
- add(new Label());6 b" V [ h D0 J
- add(prompt2);
& w$ W; u- L# O' w. X9 {( Q - add(input1);2 ~3 E+ s+ u X; i; R- S; v
- add(new Label());' B! x( j Z% b5 y% ?
- add(prompt3);
7 }4 w( X0 D- d) L - add(input2);
+ Q0 n; l2 ~- G; s - add(btn1);
4 ^) g$ G! b5 m& l( G5 ?) K - add(prompt4);
5 D( l! \/ U2 _& [$ ? - add(input3);
% `1 d- G2 F' u# @; } - add(new Label());$ a8 R6 Q0 f0 ?7 R- S+ W5 E; V* |
- add(prompt5);( s$ y. i1 n8 ]" q& }
- add(input4);
& I" p4 Q$ d( N& P; z8 J) D- i - add(new Label());! q/ ^. }+ {, ^# e6 j- ~
- add(btn2);+ J+ N7 G; O8 T. x! c
- add(btn3);1 B% ~! d" I: [
- add(btn4);$ h: l3 I G( {1 [ G
- prompt4.setVisible(false);2 i7 m: Z# e* {* O5 l
- prompt5.setVisible(false);( g* a* Y- J6 _
- input3.setVisible(false);
1 c) X6 v. `6 s6 O, Y% B2 f4 | - input4.setVisible(false);( i p# H8 ]2 {
- btn2.setVisible(false);
; p; S2 o3 x, \; Y. n - btn3.setVisible(false);
1 a( b7 j3 \4 ` - btn4.setVisible(false);- a2 J! G% h$ j" W* f2 q( O9 u
- btn1.addActionListener(this);( w, \* C9 |, @" `1 T
- btn2.addActionListener(this);
3 T& g# `' H& j2 B/ m. Q - btn3.addActionListener(this);
5 G) s p2 {2 y9 v: e - btn4.addActionListener(this);3 y/ p# g, Y8 U1 v; k! j$ s
- }5 p, [- ]' |, `7 J b' B
- public void actionPerformed(ActionEvent e)1 b F( ~1 D# Z* v6 U
- {9 X" Y, o Z9 n
- if(e.getActionCommand()=="登录"): L6 ^1 u0 H# x! q6 w- l, O* P9 b: ^
- {/ n! ^' z1 Y9 F& P7 v( b( u4 @
- String a,b;
4 ?5 q1 U4 \" X3 r - a=input1.getText();
, m& l4 k; p% n8 n5 Q2 ?/ i6 b8 P8 ]! d - b=input2.getText();
- c8 u# d" j# p! n - input1.setText("");
8 F" Q# n. x$ j$ N - if((a.equals("12")==true)&&(b.equals("12")==true)); F/ N/ u+ N% Y9 Z7 H
- {
8 H+ ^4 B9 a) q& p - prompt2.setText(" 姓名:");% p" P! ~1 h/ V3 O5 j0 c1 r+ c, V
- prompt3.setText(" 学号:");
D8 t5 F* r# x% G+ @/ r; ~ - prompt4.setVisible(true);
3 d a# r, n: c9 W! [ - prompt5.setVisible(true);
3 q' k; L5 d, S( { e - input3.setVisible(true);
$ d) f h. f) J G" T7 b# r - input4.setVisible(true); o* K7 d7 \' f
- btn2.setVisible(true);
: Z5 j& W( I$ a" ~ - btn3.setVisible(true);; n2 \. P" W, _( i& C' t2 P1 R+ }
- btn4.setVisible(true);
; j. M5 q- S4 E - btn3.setEnabled(false);
8 y# f4 O ^( n" Z: G, b - btn4.setEnabled(false);3 a# S. Q, T0 Y4 }- a; M& T1 t$ S
- btn1.setLabel("查询");6 X8 c, q$ O' J' |- ^4 T# c
- input1.setText("登录成功");' w+ Z1 X+ O, Q) }" ~
- input1.selectAll();
2 U u; K i) Z - }
7 h# |: m! ?" \5 a7 d- t8 a' D - else
$ u: }1 q# X5 J8 `: J1 e' j% q - input2.setText("用户名或密码错");% z5 ?$ |+ q5 M! N) J/ t' w3 O6 ~8 j
- }: W; w/ d+ L) f) F/ S ~' W. I
- if(e.getActionCommand()=="增加")
( k7 q9 z/ l+ }# V - {
/ b5 b$ K. j3 s3 D - boolean scucss=true;
( c T3 ?6 D. [ - try4 G0 f; b9 m. v, f5 t
- {1 }( R5 e8 ` Q( [" P
- XingMing();
0 X# U+ l; s& ~; S- P - }4 E, m6 _9 s3 ~- Z8 S
- catch(EmptyException as)6 o- i) l( _& }% C) k! N& ]) n
- {
* L; e" C- D* @9 H4 n( d- P - input1.setText("姓名不能为空");4 R* A. q0 x% s u* g
- scucss=false;
8 O2 r# K. t2 f h7 i' F% S - }
/ Z$ j% q+ z0 X" A+ _; l - try
' t$ S+ R; ~9 [ - {
; ~3 `; [1 |0 g2 k( A9 W7 X - xh=Integer.parseInt(input2.getText());% ?, d* B3 f$ z. q' {9 Y4 p) v
- }5 `7 [) L# b; r8 @
- catch(NumberFormatException m)4 o% }1 b3 F( U1 y, K. |2 X: W
- {
! ^, | d& q3 l9 w, f) ~, b" l - input2.setText("学号为空或格式错");
i) e$ e2 ^2 y- h( d/ i* P - scucss=false;
' A- s9 |0 K9 V# o+ ~6 b d - }
! f% l- O1 N. R* v# w- ] - bj=input3.getText();! _: P' b. \! ?& j$ {! v
- try
: I% t2 a2 p9 z( v7 X5 C# s - {
# p' j; V' u# E" P- ^# V/ ^7 O+ q - ChengJi();
( L1 k6 |: f0 t - }
1 F) u, Y/ X9 [% A2 m( W - catch(EmptyException as)
$ t9 a2 E. ]. D) a6 O - {
' x ~% n8 g, e9 f; v& Q6 o - cj=-1;
0 f: P3 O3 s. y# w) m - }. v, B- b' H3 M7 f
- catch(OverException dd)% ?' E8 ^7 q. z" D/ J5 a
- { h8 s9 E" {( X: W% R
- input4.setText("应在0-100间");' d4 d# y j' G; f
- scucss=false;
2 ?5 F/ Z$ z# g1 k0 }& Y( H6 c% ^ - }
$ F6 ^. g' O) k6 W6 ^0 Z; O - catch(NumberFormatException cm)
' i7 Q; }* \* g" V8 d! w( u: N - {
& P; I% @" T4 g2 ~+ u/ P# S - input4.setText("成绩应为数据");* y9 S1 {% u* C8 s
- scucss=false;
$ \7 M" a$ q/ W - }
& H( q1 j% }" C3 M' H; V - if(scucss==true)
, E: d9 Z' X) y1 e; z - {
5 A6 D! i" D! _! K - SI=new StudentInf(xm,xh,bj,cj);
# ]* J5 A' g# ?4 V" }$ R2 I# w2 v - Insert(SI);
$ G% K& Y8 I8 ?) n - }
8 d( W& q+ u& }1 U$ m% D - }
. ` n* Y( x$ d6 l - if(e.getActionCommand()=="修改") J' [2 z3 H( p: a* W5 g3 S k% J
- {
& Y) C% h* v* N& B* ]( q3 { - xm=input1.getText();' l& U+ M, q8 ~3 [1 Y
- xh=Integer.parseInt(input2.getText());
, V' N# c+ x% h# g+ }, k, R - bj=input3.getText();8 N& w- L- a. R" T
- cj=Integer.parseInt(input4.getText());
& s5 U2 j' s! X# }% k. M - SI=new StudentInf(xm,xh,bj,cj);4 {! J* [4 N# X% h
- StuInf.setElementAt(SI, mid);; P% B" p; c; l( x$ u& o
- btn3.setEnabled(false);& P' c! D3 L$ @
- }
) `" v/ \3 X* u5 t& e0 p; A - if(e.getActionCommand()=="删除")/ ~( Q* s) b6 W0 L& P6 W
- {
G8 B# D5 ~% g6 F7 n. u - StuInf.removeElementAt(mid);
! B! g6 X. R! N+ P( N, V - btn4.setEnabled(false);
8 A5 E0 e }$ T1 j - input1.setText("删除成功");
( Q8 u1 X4 x) m8 y - input2.setText("");
7 x1 E! o! z2 m7 V f - input3.setText("");6 ^9 F8 l0 N6 q5 {/ d _
- input4.setText("");% S! T6 f$ Z* w% @9 `# s0 Y* g
- } R+ p2 A0 f) o* V: t
- if(e.getActionCommand()=="查询")
# e& [6 m9 B" ?& d) K! |/ ]/ f( O - {, S' T. K' u9 g+ y
- boolean right=true;
4 ^" r8 G; E8 z - try
5 X6 z- N* a9 q+ t9 _; p4 W - {
( h2 Z1 D6 q/ `' i# e - xh=Integer.parseInt(input2.getText());/ L- D% v3 n2 r+ \
- }
2 x# x. A8 K5 x; g+ H. L. b5 r2 j - catch(NumberFormatException m)
: u8 Q6 S3 n7 W# t - {
$ E T/ b, f# w5 u: A. s - input2.setText("学号为空或格式错");
/ g B) p. y+ I' J3 T4 ~- w - right=false;9 h" T: O3 o, T( I
- }
! i3 T+ n! ^8 U/ w1 w/ S& [2 I; m8 e4 _ - if(right==true)$ f3 a$ a$ l' G9 i0 E$ U! J
- {
/ v& n3 K/ [4 D; r! j - search(xh);: k/ C. X3 l5 g# k
- btn3.setEnabled(true);
+ y' A/ O' e; W2 ~7 F - btn4.setEnabled(true);" [- E& o9 a3 m( _
- }, a% D. d( o$ b$ g; n# y
- }7 Z1 C, r' p, F7 L' X
- 3 ?+ |. o9 o0 a) Q
- }! {2 ?! i: Z8 N) \, @0 P. D7 F
- //查找方法
( D/ d3 y( z& w$ d. m, @ - public void search(int k)# e0 H! Z3 l! M
- {; D: F( ~. l5 S) f0 @, g V U6 y
- boolean exist=false;. E5 b0 m( z7 X$ _: O
- int low=0; Z7 p5 X% b# c" N! J
- int high=StuInf.size()-1;
8 P9 Z9 |0 [ w: I; p+ ^7 ]0 d - while(low<=high)
0 ^3 n% x! ?1 E; R: r - {, }) l1 a# E4 [8 v2 Q0 D5 C. h/ F
- mid=(high+low)/2;
3 y8 N% t) m1 X% g3 B2 R - StudentInf a1=(StudentInf) StuInf.elementAt(mid);
?3 l0 g* s: h+ W! N2 W4 f. R - if(a1.getStuNo()==k)/ U1 T! _- P: l! [
- {
$ Y; q$ o- `& H' [. C3 |0 O - SI=(StudentInf) StuInf.elementAt(mid);
8 B# S( N5 p m( C+ Z5 u - String x = String.valueOf(SI.getStuNo());
/ ~ `: S2 |) ]3 f- y2 ` - exist=true;. ?- M3 n/ G& [2 y& [
- input1.setText(SI.getname());
5 ]) t8 l* R7 d. G' g: i - input1.selectAll();; \; h$ Q, P1 D: O+ k
- input2.setText("0"+x);% I: k4 v( s6 w# U7 D, T/ [
- input3.setText(SI.getClassNo());& o8 {) A3 ~9 ^, [5 E
- if(SI.getLevel()==-1), v V7 p& F* |+ E+ \. q# F
- input4.setText("未参加考试");
" i. ]( k7 e3 r K# o: P - else& R; x* F" j5 B+ U! \, W! V! \
- {# A2 f0 j4 k' g
- String y = String.valueOf(SI.getLevel());
$ |# S. E' N/ p' \3 c: N0 B - input4.setText(y);0 h3 I0 L- E$ w; q6 b
- }
! x; y, \, g% k5 P- X; g) l& C - break;
3 M1 o2 q" B$ {4 c% w - }
& T5 V. Q1 q9 a6 R7 V+ Z7 p. f, @ - else if(a1.getStuNo()<k)& v& m9 Z* n- q) q- L
- low=mid+1;" b: x" ?5 D5 }) j: ]) |
- else
7 k. A+ u8 T2 T+ @9 _" E - high=mid-1; 7 |" J& I$ d( t# y
- }
; t- ]/ E" l2 Z8 v - if(exist==false)- r k6 d0 z7 Q0 _, i& h. w+ ^
- {
/ s6 u+ u, B2 v u$ O - input1.setText("无此学号学生信息");
; z* t% `0 ~) y+ k4 d9 H# A0 H - input1.selectAll();
. ?+ l- @2 O8 j U' G9 X - }+ F9 a% w6 v; `( q
- }/ z( q- K% ?" I: m' N/ J
- //添加方法& g0 o1 Q5 i' S" b9 o1 Z. b
- public void Insert(StudentInf q)& c5 F! O9 z9 M1 P$ Q2 S" t3 D# h
- {
7 K2 i1 m9 |+ d+ _1 p# C* C& J2 U - int i=0;
. m- y# z, d' w- u% V/ { C0 K1 ] - - @$ {* ~7 }" N x: p3 V
- if(StuInf.isEmpty()==true) 0 f* ~1 ]2 d! [
- {
* Y; d3 S" e2 H* r - StuInf.addElement(q);; b; q$ C# z, U1 ^
- input1.setText("");7 ^5 P( }: b: k: ~* X7 N
- input2.setText("");% B2 F% a. f+ @; V& o; B
- input3.setText("");0 t& b" C; N7 N9 m3 Y
- input4.setText("");
% q! }9 H2 U0 [4 Z6 O - }
' T; t# r' O: h, i) z0 t$ b+ i9 g - else
1 d7 h1 v7 q; a. E- |8 z" C, \% v M5 N% p - {
- j( w. e. w7 I; M$ {2 j2 S - StudentInf xh;
5 ^1 W1 y+ w& S+ t8 g2 z+ r! e - xh=(StudentInf) StuInf.firstElement();8 H. N2 D' M% E- r1 I0 o3 ?/ w/ v! p
- while(xh.getStuNo()<q.getStuNo())8 V: d6 e' l" d. z3 t" C2 T: b) {9 O
- {
* X6 L; g' z8 q) q) s- o' o - i++;' N4 u4 J% S. d# W1 y* R
- if(i<StuInf.size())
4 c$ k! }1 J0 c z. M6 b/ } - xh=(StudentInf) StuInf.elementAt(i);7 I" ?7 ^+ u' B4 K
- else
( ?$ V8 q, D; i* w) C/ h - break;
7 E2 o7 A1 C5 w; d8 j - }
6 I8 F8 ?$ G2 w" o) m4 s - if(xh.getStuNo()==q.getStuNo())+ \1 T0 n0 j6 u1 {4 \
- {( z* H7 K7 L1 {
- input2.setText("此学生信息已存在");
3 O$ ?, @9 M" k2 W& T) v - input2.requestFocus();& m' |& w/ s2 b3 O. h
- input2.selectAll();) Y* N( |! L$ m
- }! D* [8 M1 E5 k% x' ^/ ^1 O
- else 5 E& M" j$ d" Y' I9 I+ D: I+ X3 t. o
- {
: h2 X- b* }/ u+ { n2 T - StuInf.insertElementAt(q,i); , M/ f% p! ^0 ^, F3 q
- input1.setText("");
. @3 S/ ~) H6 F/ e- a - input2.setText(""); N& ~6 z2 T7 R: J7 W* f
- input3.setText("");
2 {8 o3 i& m" V8 M6 y! B3 w6 M k& ~1 y - input4.setText("");
$ K( t) [: u, h) T; ^8 E/ F4 K - }
; ?, b: W+ J X2 ^5 O5 X/ q - } 0 ]/ U5 H$ r: Z# ~* d
- }
, \& j5 w& Z: I; U* [8 c - f: m, f$ h9 y: {
- //异常类! V7 z) z$ X8 y0 H% m! n5 `
- class OverException extends Exception
% @1 X+ `) c% l8 f4 K' n4 X - {" g! b* O, u& L. O6 h
- String over;' v; h" Z2 R5 ^4 @+ [
- } 7 B: t g/ p2 \. l4 k3 s
- class EmptyException extends Exception) q3 v8 w# ]! y
- { [2 V' c% p. @8 [% K! ]8 j" J$ S
- String empty; A6 e) j3 v3 l$ ?$ z1 S s
- }; J; h9 A! _- U4 v
- void XingMing() throws EmptyException& s2 R* i" {5 }* {! r0 p: }0 `
- {/ @$ X) j& n3 E* x0 ^/ r
- if((input1.getText()).equals("")), G3 u+ v: {( Y5 l$ K% j- y
- throw (new EmptyException());8 y4 t7 ~! M& h$ c
- else+ U5 i9 t6 [% Y) T2 G6 u
- xm=input1.getText();
. U( n: [4 y0 q5 i - }$ w6 K: ?* r Y' m2 \% u% W I
- void ChengJi() throws OverException,EmptyException i# O2 O4 @1 v3 W( [+ v' s, l
- {
( S5 I5 F, u5 o- t0 z9 v - if((input4.getText()).equals(""))
& E! Z/ x3 ]" ~; ~2 F - throw(new EmptyException());
( n$ t! t" g0 g# |2 y - else: p! ]" [8 |2 s& o( ]
- cj=Integer.parseInt(input4.getText());' m9 T7 [ S& ?* t0 U
- if(cj<0||cj>100)9 l& S0 P$ H6 y" Q) \. L6 q. [
- throw (new OverException());
* ?8 ~! B9 l/ A& H8 z - }
& v& P! j1 m/ J0 T. j - ' B2 [' ~% y& s4 B, ?0 O
- //学生信息类
A! ?! D2 \# k6 J7 V, m8 J - public class StudentInf
# ^9 i* J% w/ ^$ y - {
$ z. d3 }+ @- R - private String name;
2 K9 u! e; W) O( g) l) X: Y - private int StuNo;! a5 Z6 y" L. V# c! C+ z6 {; X+ v- q
- private String ClassNo;: l0 P; V; q% h! w9 o: m. W ^( D
- private int Level;4 |5 w0 H% @4 s5 a2 F: V1 i
- StudentInf(String xingming,int xuehao,String banji,int chengji)
# @5 x/ O- L* h1 Y - {
q/ j9 h& T: Q7 G0 A - name=xingming;
5 h& c/ V: v! Q/ ^9 x- D - StuNo=xuehao;
' `4 m8 Y# |8 V0 ?" _! ^ - ClassNo=banji;
0 P3 k+ |; r, s( w5 X$ K - Level=chengji;
; w" S. A) ^. g& w8 r - }
7 C9 Y) |0 K! m: t - public int getStuNo()
+ w. I- u7 X% ]7 C9 F - {7 u- y% T! d3 I- ?+ x8 z$ L
- return StuNo;
. C( M3 E( ~: J8 s - }4 B( D3 K5 g3 T
- public String getname()9 T- e. M$ X3 y" W5 P, F# E
- {
7 ]) K" ^. z% q - return name;
4 L! }0 c+ \( [( U7 J* k! T - }
+ l8 j5 x* s7 Q1 T - public String getClassNo()
3 F" M" N: ~' A, X2 t - {
7 m1 A. ~6 Z- T: X& S4 D$ `! S% R - return ClassNo;
6 B6 n2 H1 G1 p0 u - }
( P# j7 Q2 Q' g3 B- S7 o - public int getLevel()
$ e/ c2 @- q, R1 i - {! ~) y* h( V# ]' p
- return Level;6 e8 a# \! l4 [
- }) L/ X, k S9 g5 o* ^: ~
- }
' q8 M9 t% c3 @. i" |! s
) T& V; b( c9 H& z5 z- }
复制代码
+ G; p# c5 A5 y- u# y+ j- K0 A- c0 t
; Q* J3 \# O( c' t- w |
|