import java.awt.EventQueue;
( h# v) O8 O$ K5 l( o& b& k# S# r0 {$ r7 L
6 Y( N; M& }7 m# R2 spublic class TQC301 {- U6 U- ^: y; M3 R/ t8 |
7 e& ~) C: M: }) ?
private JFrame frame;
8 F: n, w& f7 h$ U% F3 o private JTextField tf1;* ?6 o# u3 t, G6 O
private JTextField tf2; L6 v& p' G( k0 @% ]) z2 W
private JTextField tf3; G' o2 i" _3 o; T3 h. Z% J' x
private JTextField tf4;
7 D9 s* |% W5 M2 p6 o( P6 K! y" _ private JTextField tf5;
4 Z7 f2 M+ b# v8 b private JTextField answer;6 H# N' ^$ {& P3 u/ x. s6 n
. O" {. f7 K" ^9 d: G0 l /**
: r1 O. x/ b! Y o * Launch the application.
& G: w! @( h5 o7 q( Q$ u( K1 b. @ */
& i ^8 ]; O/ n9 O9 q- y# r9 f public static void main(String[] args) {8 s: X7 v0 Q7 J) d6 T+ a
EventQueue.invokeLater(new Runnable() {# M3 R* p$ n0 B% s, ?2 `9 {
public void run() {. W7 a, P& X* ]% Y5 J+ {
try {$ L k8 E& w" `
TQC301 window = new TQC301();6 V6 {" s ?0 ] }. }
window.frame.setVisible(true);
* k2 `% w3 r+ }. U } catch (Exception e) {
5 @3 |0 A$ x0 h3 A/ n7 {1 Y e.printStackTrace();7 r- |% R; h1 a' m6 H
}- u, m, W: ]5 ]0 T/ V% n% v1 X
}
) |0 j6 h- r' ^5 s; i5 S });+ g. l6 X1 g, U8 r- }% C" V
}% Y+ L' D' o) n+ O4 v8 f1 ]# }
y3 `, P* _+ C( L) V3 P
/**
& x1 q$ S; P8 w) m, } * Create the application.0 e0 z/ J v) r. _2 _
*/; [) F0 m4 J6 i) Q
public TQC301() {
4 d4 m" U0 ~$ F4 e/ O% `% z initialize();
$ o% O4 R3 ~ ?( l5 c! D8 I' h }
- k1 G7 Z+ d) a2 q
% @) ?1 t. F5 C" w6 S* } /**
! l m0 |+ k( U * Initialize the contents of the frame.
: `) a+ m8 [7 {# \% e */
& O! [% F4 d7 ?- f# h private void initialize() {% o1 h# z' R+ x4 _9 D" n
frame = new JFrame();
9 b0 m% Q3 f0 E$ V6 I frame.setBounds(100, 100, 450, 300);
; {! b+ a& x! H4 r/ X0 S* r' f frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);' o% i) R( @" ]) ?+ L5 d$ J' C
frame.getContentPane().setLayout(null);
( G& y3 R! S% a . @4 V7 N9 \! r4 u( y( ?
JLabel jl1 = new JLabel("\u7F8E\u91D1\u73FE\u503C");- s2 T: A1 f* f1 p* x2 C3 ?" a
jl1.setForeground(Color.BLACK);
- c* @9 C! z& q* E jl1.setBounds(20, 27, 60, 15);2 O. c# H8 i* X0 T6 {: s
frame.getContentPane().add(jl1);! H2 i$ N3 G4 k1 M, P" d
- q! }* B8 l0 {) s JLabel jl2 = new JLabel("\u65E5\u5713\u73FE\u503C");
- M) F: y; c5 j8 w2 S jl2.setBounds(20, 63, 53, 15);) @ B( D4 `: h# q9 l* S
frame.getContentPane().add(jl2);
; R0 R# Y! E. ]; u) ~ + a0 D! K$ y4 t: e; n6 B
tf1 = new JTextField();
2 |3 b- W! ]! x- h9 o% O tf1.setBounds(83, 24, 96, 21);0 q& i! R* k1 S* Y( L& y
frame.getContentPane().add(tf1);% J5 g3 D; p, K
tf1.setColumns(10);
; E1 X! v6 o* Q$ {* g
: C; p6 M% B% \% y0 P$ R6 | JLabel jl3 = new JLabel("\u6E2F\u5E63\u73FE\u503C");4 A9 d& Q% @% e% |1 m
jl3.setBounds(20, 102, 53, 15);6 M8 X9 {( K3 Q9 R
frame.getContentPane().add(jl3);
! A, H& G. S( X9 m 2 J2 |, G5 _) u% ?7 K5 Y
JLabel jl4 = new JLabel("\u82F1\u938A\u73FE\u503C");
6 f( X, e' D/ x; P7 o jl4.setBounds(20, 141, 60, 15);
5 {, a; W0 e+ H5 v; @/ J6 u frame.getContentPane().add(jl4);
7 b# k% B8 q% c% S
5 h0 K' D5 F3 X; \9 \7 i8 g JLabel jl5 = new JLabel("\u6B50\u5143\u73FE\u503C");
/ x2 S: l s' ] jl5.setBounds(20, 180, 60, 15);" z2 w0 h, @6 e8 \; F$ D7 {- h
frame.getContentPane().add(jl5);2 ]6 z9 \$ W& k
0 i: \6 @) `! m tf2 = new JTextField();5 t4 W' n M) M3 G: m4 ?7 g' a2 W6 n9 f
tf2.setBounds(83, 60, 96, 21);. Z# V8 f% E! y2 L( z
frame.getContentPane().add(tf2);! p5 s% {6 [0 [+ V! E
tf2.setColumns(10);5 h, n( i7 H4 ]7 \! I* f
7 f8 U; d, Z* D, C3 P" x6 d; p tf3 = new JTextField();
& U% }6 L1 X8 r; Q tf3.setBounds(83, 99, 96, 21);* L: l2 Q5 @# D3 Y: x' o
frame.getContentPane().add(tf3); a! L& V: i' J! J4 F" Y2 P, s' ~
tf3.setColumns(10);2 K: m1 l" B3 P% ?. U9 F. R+ {4 D7 T
* c5 |+ s" y. h+ A8 l
tf4 = new JTextField();
( } Z* r$ Q+ O# r a$ v" ] tf4.setBounds(83, 138, 96, 21);
1 s& w/ |, ?) x" F _ frame.getContentPane().add(tf4);
* ~! F5 C& {; c- p% k8 q2 f$ h tf4.setColumns(10);
" V$ u }$ {. Q& ^
8 t7 D5 C; u& Q% y4 [, k) ^% s tf5 = new JTextField();. Y! c" I% x# j7 J, F* u3 A/ n" r; ~
tf5.setBounds(83, 177, 96, 21);6 h9 Y* o' L1 b4 r7 j! A' F8 ]9 M
frame.getContentPane().add(tf5);$ `! O8 s& v0 Z' i1 U" ~; @; [6 g+ @6 z
tf5.setColumns(10);
# X+ W5 ~. A% N V2 j; [( b
" Q: h! A: V& n9 f: D& x/ D answer = new JTextField();
8 ^7 ^$ ?* H7 W: m5 V" y3 j* P answer.addKeyListener(new KeyAdapter() {
+ L" i; B* W4 G+ l @Override( s1 B. _- y8 {/ h! |
public void keyReleased(KeyEvent e) {
2 e/ x: d: u5 ?& @ System.out.println(answer.getText());/ |' u4 W& S% _; b
" q. p# r4 V8 {8 B+ h0 [$ A) k; P! ?. _
try{
& ]7 e8 k7 o- Q double num = Double.parseDouble(answer.getText());
- S; Q# H0 O4 q% U7 {# C8 q
$ C' d* j+ m% M
& w/ |& L* H+ m: Q. U& ~) _ tf1.setText( String.valueOf(num * 0.029) );( Z$ b9 t- W9 q, W8 I
tf2.setText( String.valueOf(num * 33.53) );9 g8 R4 u+ i$ [* b
tf3.setText( String.valueOf(num * 0.22) );
+ L: ^7 G* }; r9 ^' O. X tf4.setText( String.valueOf(num * 0.018) );
0 {; ]( S% r# j tf5.setText( String.valueOf(num * 0.03) );
- p: q& q d) i2 T! m0 P( G }catch(Exception ex)2 r; W) y9 f7 a) \8 b1 a
{7 c7 }" X% U" \6 s3 \# e2 M5 W7 y% ?
tf1.setText( "請勿輸入非數字的字元" );& C$ r& }" ]8 S2 Y. J
tf2.setText( "請勿輸入非數字的字元" );
& ~) Z- f, W( e- n. M) W7 x tf3.setText( "請勿輸入非數字的字元");4 M7 ~6 ~9 e' I, `4 Q- K T
tf4.setText( "請勿輸入非數字的字元" );$ a5 B" X# O% x" v4 Z
tf5.setText( "請勿輸入非數字的字元" );, ]( ~( U; Z* O! M. c- T
}$ r k0 I% j/ P$ v4 d" L3 |
' p: p: P9 k( O) O, L- I& ^ }
9 _* |4 ?2 o$ w0 G });
" F0 R" Y1 y1 n0 a# Z5 ?/ N
/ U& ~. x3 [' _ answer.setBounds(20, 224, 159, 21);
* @( W! v. B5 i9 e; k frame.getContentPane().add(answer);
+ B% m6 y+ F3 I8 S |( E answer.setColumns(10);+ B% z; o) n& C r$ I
}9 J' G! G% s, F! {: v
} |