该用户从未签到
|
- import java.applet.Applet;8 J, O W/ [6 \; ~/ R9 s. o
- import java.awt.*;
* i1 B3 ]# ]7 U& t$ E$ N1 J: G - import java.awt.event.*;
0 l2 X1 |# L* c+ I$ | - import java.util.*;
( G+ W3 }3 Q3 J S9 M& g - import java.lang.*;0 g+ N3 V$ `# J3 o9 ~- h. S: \
* d; [, }9 d+ V$ E4 c \$ p) H! b- public class Students extends Applet implements ActionListener! Y2 W2 W6 t; I0 w8 Q; D/ E% e
- {
9 y8 D2 _3 I* G( E - Vector StuInf=new Vector();8 s& q! d! `2 H
- StudentInf SI;
8 A) X* y; C7 L, k" }% ?: d2 y - String xm;4 h, |. I) K8 {( \
- String bj;
9 ~" k9 T2 [6 [ - int i,j,xh,cj;
6 n, G( L: e e. @. V: P - static int mid;
0 }: o- R+ [7 {0 h - Label prompt1=new Label("学生成绩管理系统");
% G4 S" [( Y' J A - Label prompt2=new Label(" 用户:");, ?: P5 ]5 f0 G m
- Label prompt3=new Label(" 密码:");
+ i& q6 [( p( j7 ?, P) m - Label prompt4=new Label(" 班级:");$ K6 @1 K' W1 y* V, |* y! L5 \
- Label prompt5=new Label(" 成绩:");
7 W% I# A2 g! K% l9 a - TextField input1=new TextField(8); U/ W. o/ ]& @8 E1 J" ` a
- TextField input2=new TextField(8);
* S/ M0 B8 U7 N0 H& i5 } - TextField input3=new TextField(8);8 a+ Y! Z# o% {3 ?
- TextField input4=new TextField(8);; I6 ]+ y5 H ]( }
- Button btn1=new Button("登录");" x9 S$ E) p5 [) p6 |, N% x ^
- Button btn2=new Button("增加");
% v9 @4 \5 q4 E7 e( T2 ] - Button btn3=new Button("修改");
+ d; r/ r) {2 s2 f - Button btn4=new Button("删除");4 |# @0 H9 g9 Z% [ [
-
7 B9 i0 S7 Y' a6 g" N - public void init()
9 A8 ]& ]4 l9 P( @: K - {9 ^( ]5 ~. I; |# @3 P
- setLayout(new GridLayout(6,3));
- g" B% Z) g( y3 V$ H8 I$ r - add(new Label());9 o- e: H* H1 ~+ e9 C
- add(prompt1);1 h# J# W" a5 }1 u, e }
- add(new Label());. S. M( V3 y' r( B1 h6 a
- add(prompt2);* ]( e( B7 H3 W/ }/ a3 H9 H
- add(input1);( h, \; l/ N. I% ^
- add(new Label());
! a+ D8 j3 Z% N7 s) L( a - add(prompt3);+ W/ V: Q2 m% @4 \/ c
- add(input2);4 D7 Y- j6 u3 e5 C# g! r2 J% v
- add(btn1);0 W; e" W5 `+ Z2 V+ R: [* U
- add(prompt4);$ A, w% b+ s; ?& M+ V" `$ e3 L
- add(input3);2 u' M l I9 [
- add(new Label());
2 x+ P8 {# j l+ H; c - add(prompt5);
5 j5 }+ o- _- V: J" f/ ?* |8 P - add(input4);. G$ F% q3 d" T h& h
- add(new Label());$ Q, b( c+ T# v5 p" e* I9 A
- add(btn2);
8 V+ D5 d& {! D$ J- l0 T - add(btn3);
8 T1 j; h9 U. z# K9 f! X& h+ ~ - add(btn4);
# \' B+ C8 l6 H2 ~; K c - prompt4.setVisible(false);. O$ O0 J i) {
- prompt5.setVisible(false);' c. A7 F& T' m8 B) I p
- input3.setVisible(false);5 h/ F9 ]' {$ U( ^& W. r. S0 c8 n
- input4.setVisible(false);) a% |7 H/ I S
- btn2.setVisible(false);
$ j$ K1 G3 v3 D8 K! r. ]# t1 `% ?/ g - btn3.setVisible(false);
1 b$ z, U* D) D3 ^0 ?* g5 ?9 o9 Y - btn4.setVisible(false);
* `& H& T6 l. C' Z4 k9 u, x# d - btn1.addActionListener(this);& ? Y" M1 z+ R% \9 E
- btn2.addActionListener(this);
y# t7 ]9 P4 |9 |% o" i" w' A# L) x - btn3.addActionListener(this);9 P! v+ F, T Y1 k3 D
- btn4.addActionListener(this);' Q2 K* K5 u, G; T
- }/ i4 y4 ~0 T- v- Y) q
- public void actionPerformed(ActionEvent e)" t3 J. ~- E U( ^
- {
& f Q- t3 p6 _9 T5 {$ v) j - if(e.getActionCommand()=="登录")
8 c' v. G+ C! @$ v& d" Z6 W - { m) P$ R( X0 C. Z K5 E
- String a,b;4 [1 h2 e% R( Y1 @9 f) W+ C
- a=input1.getText();
- T0 A! L9 M E( E( S - b=input2.getText();% y3 V. k) w9 d) \
- input1.setText("");
* J% i" P3 G K2 I$ B) z - if((a.equals("12")==true)&&(b.equals("12")==true))
" h% u/ H* W6 j+ d - {3 z: y D. d( g7 q
- prompt2.setText(" 姓名:");
8 v" @! L! r: d' z* F J% K - prompt3.setText(" 学号:");
$ k; R3 R6 v7 s7 _' }( p9 c - prompt4.setVisible(true);$ o0 N. T( K7 ~' \1 B/ A: c
- prompt5.setVisible(true);6 U; l7 s/ H. }: t- o
- input3.setVisible(true);
( X+ ]: U: P; n - input4.setVisible(true);3 d7 C, _& }5 M8 Z; |
- btn2.setVisible(true);
6 q9 \/ V0 Y7 \/ L% W8 s8 S8 N8 M - btn3.setVisible(true);
% ^6 h9 M" F$ x2 \) l7 D; O - btn4.setVisible(true);
) z) y( O; b: b - btn3.setEnabled(false);$ d& e5 g: a, |) Y. W
- btn4.setEnabled(false); h! f. p: d) w" N
- btn1.setLabel("查询");' o8 u" B, O: u
- input1.setText("登录成功");3 f1 ^) @9 m& @
- input1.selectAll();+ M( T# `7 g1 ?! G% T
- }2 A+ z" d9 G" R' o! H" K
- else
: d% i5 y/ C8 C) o - input2.setText("用户名或密码错");* \4 C- n7 w) K9 N
- }
( ?( E3 Q1 C) ~- W `2 X - if(e.getActionCommand()=="增加")
3 y, \' \2 d5 C+ u - {
J5 C( [% [) l! s$ K2 \. n - boolean scucss=true;! Y2 i2 Y5 T. a0 W, z
- try
$ s% e0 v; t7 ^6 t - {2 j! t+ d1 y4 a. o- p
- XingMing();3 v7 p7 {+ d, D6 K0 g U
- }/ F6 `) O/ B5 q: S3 d6 r7 H; c
- catch(EmptyException as)
/ a% L( u! t1 r. y - {
% |) v" L' V: X& } - input1.setText("姓名不能为空");' |' B5 ^! I! W# u5 O1 a
- scucss=false;
9 ~# k5 F+ T) d8 k! P4 N - }
) n7 \7 T0 A+ N5 W( | - try
4 {6 @8 l9 Z+ C; y6 h' z - {6 V1 J* x: L% J/ Q/ y6 W
- xh=Integer.parseInt(input2.getText());
5 _8 l; m+ r) M - }
2 v$ M7 O" z, o+ {$ r - catch(NumberFormatException m)
) H: g5 s6 L0 {, W# k1 c0 M - {
9 [2 ^% N9 [/ B9 {! l& y$ C. t - input2.setText("学号为空或格式错");* c5 F: G; r% L; ^
- scucss=false;; n% {( S" H- a" @
- } 8 O/ w& _" h: J G( E5 w2 V
- bj=input3.getText();, ?. P/ b- G' Y
- try
% |0 O* V6 N7 R - {
' O- |4 g5 F9 y - ChengJi();7 f s! H* ] q) p% R: _: ~
- }5 o8 q* N0 V1 U/ O, p( @
- catch(EmptyException as)
, \/ `. c" O8 u9 { - {. W+ m! H9 }' ~" X) }7 n9 Y
- cj=-1;* r: h) F# B8 }0 E7 V
- }
- d9 J1 g7 z Y- W - catch(OverException dd)4 e& g, G% ~6 m& v! o( y/ _2 U
- {
4 y9 V& I( S6 y* q0 k$ y( T" F - input4.setText("应在0-100间");0 x+ s$ } F1 P* P+ f( f
- scucss=false;0 y3 m+ _! M$ R/ ]" _$ M
- }
K5 V0 u/ d7 m2 q; C" { - catch(NumberFormatException cm)
) U8 H9 ^- ^9 s - {
% h) R" c3 {1 T' r& n - input4.setText("成绩应为数据");# q/ L5 ~5 p. e7 ^9 Z4 H
- scucss=false;
' x$ L7 M ^ ~( Q% B l3 I7 i6 Q - }
6 C- b. t3 w4 f$ Z+ M - if(scucss==true)
% H- Y6 j( g/ G$ v* ^ - { h& Y% q- q" Z0 d) n% k$ I" w- b# K
- SI=new StudentInf(xm,xh,bj,cj);
" ^4 K3 P- D7 X p% @ - Insert(SI);! K1 _: \- o5 S' ^( b) A; w
- }8 Y1 K+ k% a8 W8 }. ]
- }+ l" m" W; _0 k }/ S
- if(e.getActionCommand()=="修改")2 f n- Q1 K5 F' ]$ C& j6 @# G t
- {
- \9 W$ M- u: @1 L* a2 \ - xm=input1.getText();
* @1 l8 \8 Z8 a! x& `) Z - xh=Integer.parseInt(input2.getText());
l0 Z- o/ Y9 E* w5 [' W - bj=input3.getText();
7 l# l9 r! b( J8 j3 Z4 r( C - cj=Integer.parseInt(input4.getText());
- {( C* V" @' W8 S0 q0 s2 l - SI=new StudentInf(xm,xh,bj,cj);1 V- G3 O7 x) g# @1 Q- ~
- StuInf.setElementAt(SI, mid);* }: Z% {$ `; P# Y, y; K9 x# o
- btn3.setEnabled(false);
1 v% A# Q) a) V: C# K* ^4 y$ H" _4 a - }) c. f/ e, b! Z5 n3 n$ K) e4 w
- if(e.getActionCommand()=="删除")3 w5 j( m. X: k) U
- {
# h* R- ]1 |& F: P7 [ - StuInf.removeElementAt(mid); 3 C7 a" S+ t9 R$ x, O
- btn4.setEnabled(false);
- ?% }3 W; ?; i: i' C* J - input1.setText("删除成功");
8 }, _3 s! ~9 h9 z - input2.setText("");
Q) l# w/ ~4 F - input3.setText("");
: y- ~0 \3 w( b% T - input4.setText("");
+ g+ [6 o- S) A - }7 V, W1 u" B& \" R: e/ ~
- if(e.getActionCommand()=="查询"). l! a1 T3 S$ E- g) {) e
- {3 D3 R5 i- A; ]! k! Q/ s
- boolean right=true;
$ z# ^/ s5 i# n3 h# A6 |. J - try) O$ w8 f8 v8 s2 ~
- {
( b4 u& U' ^9 q: ?( { - xh=Integer.parseInt(input2.getText());2 N9 p# e# h" [9 I U$ i
- }
; m7 N. O) R) T% G* J - catch(NumberFormatException m): y4 u. z0 T7 K! t8 a! Q# m+ o
- {
/ w- \* p8 l6 o( C: |1 {2 E) ~4 \ - input2.setText("学号为空或格式错");
1 T$ Q& d, J/ ]- f3 n5 { - right=false;# {5 O+ D+ `' E5 y! [4 E9 S7 v% h
- }
/ u, ], L: v- w: p' U1 [% N+ U - if(right==true)/ L3 R2 @2 f; W5 ~, W% _
- {
* M* V! t' s- L+ G$ O" j - search(xh);
# D9 ?! f3 E# Y9 X) k - btn3.setEnabled(true);
! V" g8 K6 K1 \( H6 c) H - btn4.setEnabled(true);
2 |& Z+ ^6 y- ]5 t: B3 b6 D - }) g( e$ x7 |9 x# p1 I
- }9 _& E# |- H4 B# t
- , T6 m0 v) K3 S5 r7 G
- }
5 b! _- P9 ?3 f& N - //查找方法- Y; @2 c3 z; T% {, A r4 O( H
- public void search(int k)
+ ]5 H6 ?, b$ z2 q5 ` - {
" M+ h F# B ~ - boolean exist=false;
4 @8 ~7 I5 ^7 a: Q( e - int low=0;
+ g% X- i/ g( T5 E' z; f+ G- E - int high=StuInf.size()-1;
( V7 j$ D8 u; u% b" M - while(low<=high)) n) X0 t5 H0 w2 }5 F
- {
7 T" n+ n- k c$ h - mid=(high+low)/2;" k; B$ Y. R6 b% F p+ V" y
- StudentInf a1=(StudentInf) StuInf.elementAt(mid);+ I! a1 a; o4 _. {
- if(a1.getStuNo()==k)
+ j# \' b$ g0 B& J1 L/ A7 p. c - {
' O; z2 K8 @& V# I" W- ]4 O - SI=(StudentInf) StuInf.elementAt(mid);7 G' Q* Q# V6 m3 f
- String x = String.valueOf(SI.getStuNo());- M' x6 K, W% c/ G! b8 z% s
- exist=true;7 O1 ]9 Q" J1 n. @$ J$ |. M
- input1.setText(SI.getname());; H" m' h4 u# E' r3 {# Z5 J2 k4 N
- input1.selectAll(); i5 k7 \0 c6 @0 z; U
- input2.setText("0"+x);" t' J; }3 L$ ~" u- p% X( P! t
- input3.setText(SI.getClassNo());
+ }+ ~* O! h* P- R- i$ Y - if(SI.getLevel()==-1)
/ M$ ^6 j8 m( J. H. | - input4.setText("未参加考试");0 o! u' U2 S, k5 l! j
- else
2 j+ u5 A2 T) Y8 f- W: f - {
3 W: W4 a X `$ D# V - String y = String.valueOf(SI.getLevel());
7 Q5 D0 E' n( o# ]& U% W" ] - input4.setText(y);! l5 Y5 O7 u* i! O! W, c
- }
, ?: L$ W# ~% ]" V1 C - break;
* ]5 Q6 {3 X% A: i4 F - }* K0 z/ G! K m" S
- else if(a1.getStuNo()<k)+ K+ _+ V4 K6 S
- low=mid+1;: s* M' Y( I, V2 |+ W" N
- else
! B+ {. K7 C: G: l: N% F - high=mid-1; 9 c. a- m7 Q) P! U
- }
% r. B( u: m/ ?9 _9 y3 U' ^. R5 \ - if(exist==false)
- o% F) b# O4 f5 [6 x - {: M k" [0 E# ?+ [/ y' l
- input1.setText("无此学号学生信息");
' A) H' m d. g7 |& G# I - input1.selectAll();
1 L9 k8 K% y% `+ F - }
5 S: ^9 N" v1 @% k/ ^: h* b3 e+ h: S - }
: C( Q) P# X, m - //添加方法
! `- [+ z$ L5 }& e7 e3 U2 E- Z - public void Insert(StudentInf q)( h6 @0 C/ t7 F2 K# ]! }
- {5 l5 m; a1 D9 D) x0 H* B
- int i=0;
9 q0 R* b M5 X9 E- F+ r - 8 d% M+ c- e1 b$ P1 C+ M1 M# q
- if(StuInf.isEmpty()==true) 5 ?! v4 i) P2 B) t
- {
1 Q. P' m0 k! n - StuInf.addElement(q);0 _* _' q" e! x4 p; Q, c" M" S
- input1.setText("");
* l m7 i1 \. \; W( @ - input2.setText("");
* F2 T3 k2 \9 Z3 W2 i - input3.setText("");4 L3 J" U( ~# d* M& ?& h; L! i
- input4.setText(""); n! [0 U$ t& g7 w8 A
- }, ^4 k7 O& v. ~8 U+ `/ N
- else; b- u5 B& Z' ?! Z+ S
- {
8 o+ Y% d6 J W0 }6 V - StudentInf xh;
3 N2 o- j; f0 T# k V: u/ b - xh=(StudentInf) StuInf.firstElement();/ b5 R: ?( _ O8 E4 `
- while(xh.getStuNo()<q.getStuNo())( b7 M; K4 B3 N' E5 J
- {
3 q0 a: T2 M1 n/ d+ i* N4 c7 N' q - i++;
9 H9 o4 p& M! z+ L - if(i<StuInf.size())
6 S O& r! M3 h, O6 v5 D6 q/ m - xh=(StudentInf) StuInf.elementAt(i);: g! S! h% J, E0 k- |! h! l& T
- else 3 {/ q, ^3 z9 q* o) V
- break;
8 S/ B1 k- K% L2 m5 x+ ~ - } 1 Z& c+ p4 ~/ Z) r0 f. S! l) Z
- if(xh.getStuNo()==q.getStuNo())1 \- \8 {! q. \" |; F+ u6 H
- {1 i' e" I0 T G& x, k" u+ _, P
- input2.setText("此学生信息已存在");
1 q' O/ s! ]" B$ ?) S% O V - input2.requestFocus();7 V: T7 n3 J3 I! j
- input2.selectAll();$ Z, m) z! j6 V0 b: t+ _
- }
; e$ W0 c$ b. D- r3 D- N- z - else
, ^4 R f3 @# C3 K1 Z/ H - {3 E; E( s. {6 k e: g+ X- e
- StuInf.insertElementAt(q,i); 7 a; c7 C" B, y [* U: [) y
- input1.setText("");
4 [3 l- N8 R f - input2.setText("");
* V7 L4 D$ e$ ]5 r - input3.setText("");
! g8 O; f: {$ b4 O8 S - input4.setText("");
/ b7 u, O% b$ f9 {( @ - }
3 i6 d0 }' O: W$ o0 l m$ M* o5 x4 b& I - }
) F/ \- m7 _0 A! Q, { - }
g0 ?, G) H5 L# j, k7 U, A* D7 B - - l) {( W% o9 @7 p0 P# o/ V
- //异常类
7 i3 c( B% T' a; A - class OverException extends Exception0 Y) y3 T/ }, T$ s! T( `$ d
- {, x' e! E" W: b/ {4 h
- String over;5 C5 i9 x' N& Q, L
- }
8 R! V9 A* B5 h- z9 n - class EmptyException extends Exception. s7 d _ j0 C) B" s( L1 I9 Z k1 n
- {
# a I* [ r# f0 Q) c - String empty;
1 X. W% k! D+ T8 H2 o5 H. z% B/ n - }
' Y; @6 u8 p- q( _) c - void XingMing() throws EmptyException& X: Z% O2 V! A8 r/ K
- {
; s7 u: K; K" U' t9 |) Z+ ?& }( \ - if((input1.getText()).equals(""))' F* _) I2 t6 C8 w9 D* t! [. q# A
- throw (new EmptyException());! a2 R& g6 `& T
- else7 B6 W# y; f( O! v( w. {
- xm=input1.getText();2 `$ i3 A. l; g, a
- }
2 p3 R; y( e; J8 V: W4 I' ~- @ - void ChengJi() throws OverException,EmptyException
/ e! Q$ H. i/ X4 j9 x& F. b7 @ - {; ~: X& w1 k6 X# H* H" K* g- k1 {
- if((input4.getText()).equals(""))
2 `) Z) U) A* ]1 n# W - throw(new EmptyException());% F: n3 R0 p. R4 `
- else
% [7 x' y' M8 h - cj=Integer.parseInt(input4.getText());6 j9 f3 {/ Q" e- X/ c1 o
- if(cj<0||cj>100)$ T; C, e% i) J6 r5 P
- throw (new OverException());
' M, k# V b0 U3 r9 f; ~$ t - }7 z# L4 g+ B1 u" }# c9 p
- ) L' {# ^5 o" c( O* ^% G
- //学生信息类
K( w. {( j2 S$ b$ ? - public class StudentInf; W; K6 }3 M0 f$ {0 V; e+ F- B1 ? f
- {
. A6 T0 I4 g) F - private String name;
/ o$ z* I, h5 R; ]9 R7 {( ~ - private int StuNo;$ B; _) _* D* }0 t
- private String ClassNo;
9 b; [2 l1 \' g - private int Level;
$ Q/ G5 |: `* h/ x9 |. @) Z% R - StudentInf(String xingming,int xuehao,String banji,int chengji)( a4 \5 H4 D4 f! S6 h; q
- {
2 n( @9 l3 K8 p6 p - name=xingming;
+ b, }; P ^6 Y$ Z- ^0 p - StuNo=xuehao;: _5 j# v0 A6 c/ i7 ^3 \7 q
- ClassNo=banji; B( r. z2 n" C0 f7 Z
- Level=chengji;
7 w5 ]% D2 }/ S3 O& q- M7 m7 L - }' k1 r# X% j7 R' U- W5 I
- public int getStuNo()
/ f$ V+ q4 [+ Q0 g: ?, } - {" I; d" Z+ i9 H# n+ w, H2 F, p/ H/ v
- return StuNo;0 | J5 ]- M6 H. r- Y9 K
- }
; T. g; O, v+ U: g2 l$ ~ L) K - public String getname()
1 Q8 U; ]4 ?6 a6 F - {
' Q; d3 c8 P1 m+ E1 Y" x - return name;5 y% l8 }1 i+ h! ^
- }' x4 o& V% B3 F& i1 H8 d# k# z4 B: H
- public String getClassNo()& Q' Q4 |* u7 e1 v9 Z( P& a
- {# o2 D6 i1 m) @# d% d/ c
- return ClassNo;
" w0 `8 n; K/ E7 e" |$ T - }
$ ]# [0 p, s" _& @( a* A - public int getLevel()
* q$ O- I! P% t% {: E - {, x% q& A& d; l* m H( ~. s2 c
- return Level;
" z$ X9 V' {8 r, F$ A$ k5 @& i - }$ B1 H4 J6 M1 A# v2 J
- }& `$ `# ~& E$ ]! b" Y) D- s1 f
- : H8 L; {7 K4 Q9 b
- }
复制代码 ' [. t0 f1 ]- u% K. T
% U: r1 t4 I" u$ N7 q
|
|