import java.awt.EventQueue;8 d0 I. e$ U' F7 T: o. n) o
7 p) v* |+ D; l$ W! {- w
# p& W# t5 w xpublic class TQC301 {
. a1 c9 h8 l2 J* F0 w* Z
5 V$ Y: g8 p. `) A" N, i private JFrame frame;6 t3 a3 ^1 i. O4 B* l$ L
private JTextField tf1;3 A' h; P9 `- Q! t6 h
private JTextField tf2;
8 n) O- t& `. E) l private JTextField tf3;
f1 W* }" @4 @& F8 r2 v$ {8 p7 | private JTextField tf4;) K$ ] G7 t# w
private JTextField tf5;4 T7 n- B/ r. X5 C1 R; X" |
private JTextField answer;
& M$ @$ c; y; q$ l& q' B$ A: E% H6 p2 Q6 x
/**/ n1 g4 G6 e' \, u1 m
* Launch the application.# }& [2 w" l# S, V2 h" T
*/1 C m- h& R/ p0 k3 _
public static void main(String[] args) {
2 e0 ?$ _( w, i% x& S5 X EventQueue.invokeLater(new Runnable() {
* n# T% e' }* r% @ public void run() {
! r, c- Y! N4 k( I) a) [% [0 k try {+ A+ d! u& n3 ^6 h% C; }7 l1 c) @4 n
TQC301 window = new TQC301();
' b: v; ~' _) z7 }. Y/ z window.frame.setVisible(true);! m. ^8 T! c0 ~
} catch (Exception e) {8 P d. Z! W8 V/ ^
e.printStackTrace();
|, ?- I3 R/ _% D- t, I: R' } }
0 `2 l2 C% J. Z1 B }; Z8 v& ?& Q0 Y
}); f7 s- h7 j1 O0 u( A$ \
}5 _, F0 W' z4 x
1 P, }- t$ _; x /**
5 P, k$ ~8 Q( [ * Create the application.. W% c8 \: N( G2 H' \1 ?
*/0 Q6 J+ }1 i6 y( `, A
public TQC301() {0 Q+ [! ~2 u* V, S m
initialize();
1 l% _3 s* e f6 A8 ` }
, ?* {% z! Q% n+ f# c6 W
! R* l! H* L% Y4 @/ Z! l# V) x! H /**! R4 K k5 ^+ x. }* Q: K0 `
* Initialize the contents of the frame.
5 x# J6 o- g% H; ^6 Y */
h; d' {7 |; U c: E$ [; E! ^ private void initialize() {
: D! h# N7 n/ C# j5 I9 v$ {! T frame = new JFrame();
) b3 h$ t! _ v1 T9 P) x4 l( @ frame.setBounds(100, 100, 450, 300);
: X3 v! P! r$ P# i. u- e4 v+ P frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
& i, V; s& O& T- e$ C frame.getContentPane().setLayout(null);# H9 F' B/ K- O# d' @8 ^ v: n( a* E
* F7 L z" E1 s1 T
JLabel jl1 = new JLabel("\u7F8E\u91D1\u73FE\u503C");
- S" ^- z! F& b: d' x6 {8 y jl1.setForeground(Color.BLACK);( i! ^) N. A& c7 l7 a# R$ S9 S% ^
jl1.setBounds(20, 27, 60, 15);
* g. X* H; f7 u$ S3 T frame.getContentPane().add(jl1);
4 A( J3 p/ n1 E6 }9 |4 v( ~ 2 z6 i- Y$ B) F, C7 P
JLabel jl2 = new JLabel("\u65E5\u5713\u73FE\u503C");; ^9 `( Z- i9 c# a+ }, v7 N1 q& t
jl2.setBounds(20, 63, 53, 15);
6 S) e' `& d5 h, p% C frame.getContentPane().add(jl2);
( i: N- [# Z& c& y( E% U3 ~ . u6 {3 n/ o6 `/ T
tf1 = new JTextField();$ [7 \8 D) N, ]5 D% B$ u
tf1.setBounds(83, 24, 96, 21);, J+ S3 O: P' ?2 @0 c. G; y3 J
frame.getContentPane().add(tf1);5 F& X2 Y% V# n$ Q* |
tf1.setColumns(10);
0 _* e" a& a! V; P! q3 c- \$ _
& x" m& s B3 e2 n1 R# P# _ JLabel jl3 = new JLabel("\u6E2F\u5E63\u73FE\u503C");' e6 G) L. f0 i* }
jl3.setBounds(20, 102, 53, 15);, z0 ~5 T7 V2 S. _
frame.getContentPane().add(jl3);
4 m @( y. T. `- ^- y$ u8 Y! _ 0 t! j* ?. d' M& l1 A( l3 |1 _% L
JLabel jl4 = new JLabel("\u82F1\u938A\u73FE\u503C");3 C. w+ i7 O0 ~0 P0 x
jl4.setBounds(20, 141, 60, 15); s. K4 F% n2 X/ H' d! \. H" a: Z
frame.getContentPane().add(jl4);3 I* j) l6 u2 A9 W
+ I, p/ `' ~7 C ^5 J9 j2 g) X JLabel jl5 = new JLabel("\u6B50\u5143\u73FE\u503C");/ Y7 `3 ~9 R5 Q3 e/ u4 D5 M: ]
jl5.setBounds(20, 180, 60, 15);; b0 d4 @& Q% f: C9 u8 X) y! ~% d
frame.getContentPane().add(jl5);
5 `' \/ r8 S; d/ W
# O( d4 y! F3 Q7 q4 l. K& H tf2 = new JTextField();: P i7 Z0 a2 E2 J. e) r
tf2.setBounds(83, 60, 96, 21);( J( }) k6 l2 t8 I6 |
frame.getContentPane().add(tf2);- |5 j+ w* I! Q8 _! e
tf2.setColumns(10);( E* x z; r3 h6 p3 |" U) w4 l
( Q7 r! w. ^* { tf3 = new JTextField();: k: W# C7 H- Y2 v9 E9 j+ t' Z
tf3.setBounds(83, 99, 96, 21);4 q& e. p9 z8 x* J1 }
frame.getContentPane().add(tf3);& f6 ~2 W, x2 U0 ~: c% r
tf3.setColumns(10);
0 o" C5 J& E+ L0 N # w& N% B8 I0 i4 v' B, a
tf4 = new JTextField();. C" E+ V, @! J+ @# `! @( j
tf4.setBounds(83, 138, 96, 21);5 i2 v" b" U; q) ?' z
frame.getContentPane().add(tf4);
1 w+ |) D# J1 O tf4.setColumns(10);8 d: E& j/ B: k R$ H) D/ [
- t3 U$ N2 R; ?. @( e# [ tf5 = new JTextField();/ q, `) M) p# u ?- s) f7 `
tf5.setBounds(83, 177, 96, 21);" `/ p. c* ^" m. K3 C& W
frame.getContentPane().add(tf5);# l e4 d& [) `( m
tf5.setColumns(10);& I& E+ f7 T: p/ p; d, L2 I
3 I- ]+ ~* `$ x7 D9 R% ~9 j answer = new JTextField();
. v9 {) w% b: ] answer.addKeyListener(new KeyAdapter() {4 }2 w3 a' m8 k o! T$ x/ |3 I
@Override
; `9 A9 M/ `% j0 h& w; ?% K, j public void keyReleased(KeyEvent e) {2 b- ~ k6 Q" H( m1 t0 D9 U8 s
System.out.println(answer.getText());6 k6 i8 x; b* `" h% B
& R+ M5 n8 K* o' J try{
3 e/ T5 g1 D, S+ o4 Z8 _ double num = Double.parseDouble(answer.getText());4 h- P# A/ x; k3 S& Z
3 x2 w8 H+ z! {& c) q
* R/ q( A+ v: r& I6 h- w4 ^ tf1.setText( String.valueOf(num * 0.029) );
1 k _) I" q% h0 `4 ^0 S tf2.setText( String.valueOf(num * 33.53) );8 W7 {8 [6 a# o' ^
tf3.setText( String.valueOf(num * 0.22) );0 H6 j8 d% Y; x4 a
tf4.setText( String.valueOf(num * 0.018) );2 |& ?9 d' L( q8 }! J
tf5.setText( String.valueOf(num * 0.03) );8 `& ?4 S. S. y3 }
}catch(Exception ex)
0 P; M6 x2 M8 C8 K0 |& U& h {
Q! X1 D2 i/ B% f. E7 ~+ M" G# i tf1.setText( "請勿輸入非數字的字元" );1 R; p) d$ s# G7 g
tf2.setText( "請勿輸入非數字的字元" );' O( ~, _% j# s1 x1 @
tf3.setText( "請勿輸入非數字的字元");
2 J$ p5 L3 _# A3 J tf4.setText( "請勿輸入非數字的字元" );0 N9 @1 g, p+ Z% E7 \+ ]& o
tf5.setText( "請勿輸入非數字的字元" );4 p' I$ O3 n3 F- m$ C% {
}
K3 i8 Y! o3 g/ H$ [5 q - U: f% i5 t! ~6 j: H1 @
} t7 Z) s. W% Q$ ^+ i' {3 G" c
});/ M! x0 O" _, Z2 s3 Y4 [
+ m o! q I$ i- n, M' f* I9 F
answer.setBounds(20, 224, 159, 21);
, Q; b+ {5 k5 i! z# l/ T2 F& g frame.getContentPane().add(answer);$ x5 K6 \9 C- n. Y0 I
answer.setColumns(10);
. n0 G( I+ o" V8 l/ P! z; ^ }; N0 k* N% b4 J1 L) C9 [$ ]8 |
} |