import java.awt.EventQueue;
- D4 {& n5 _7 R5 K+ t X% b# y3 R9 P9 S' W1 V* ?. d# z, L
2 G) s8 v' j1 ~, U* \% O: `public class TQC301 {, T4 Y: e, p4 I8 F
' \, ]; j n, T( G- a6 C/ W
private JFrame frame;
m8 ?% Z; f* r n' h6 k/ | private JTextField tf1;0 U# L" c. D3 K7 R
private JTextField tf2;
# ^: f- E, `5 f. \' u private JTextField tf3;
( b, ~/ P0 g) t) C* X private JTextField tf4;
0 t2 c0 T% S% i5 f; ]( R private JTextField tf5;- I3 j8 N6 k6 i" K5 Y
private JTextField answer;! D6 I# F9 o" d* U- d
" a; X7 D+ B( B/ W0 | /**
$ |& K$ }- m! g( P @9 F! ~0 K * Launch the application./ F( S( p) ]+ W
*/
/ C6 w" _ l+ [6 i( ] public static void main(String[] args) {
) Z$ c# B8 c; F, v9 F$ _ EventQueue.invokeLater(new Runnable() {3 x2 D2 o7 f& f6 F$ N& p( h$ j1 C
public void run() {1 I( u" y3 k1 S* y( j+ t/ I
try {
/ a2 c1 K. ]# Z p TQC301 window = new TQC301();
! E* M5 N) {$ @ window.frame.setVisible(true);
8 o+ N* K. T# y0 g2 h3 N& R } catch (Exception e) { q! z( I1 h: o" |, @
e.printStackTrace();+ d2 J9 ]; e+ t: B( U/ Q
}! q/ V; S& ]4 o8 p/ `: ^9 |3 ]: c
}
, k0 b0 B; G1 D) @ });
# [" b2 s2 Z' g7 t$ }4 L, b7 C }
- z6 x9 J5 E5 C$ x/ {6 E I6 i5 l6 l" d& G9 v
/**. q/ L6 ]) z0 ? x! t) d
* Create the application.
' k6 Y! ?& V! ]! x& F2 S" g8 u */
6 Q2 ]: @: d, q9 | public TQC301() {
x0 x/ S* }% _; `" j8 S' q initialize();
, }" s+ a: _) o' U; Z }
; Q9 U' ~5 i, Y* V5 N6 r; ]* ^6 H2 j& W2 n
/**4 W' \: f1 \3 H* K C9 B
* Initialize the contents of the frame.
" x/ e! T: g) A9 w5 g) E$ U1 @$ Y */
/ J7 |6 n; a* ^ private void initialize() {1 m( V" g+ {2 d9 _8 G# U" H2 \
frame = new JFrame();
$ A# F. Y1 H3 n9 d/ P$ `$ i1 \- L frame.setBounds(100, 100, 450, 300);/ O, J: j, |6 F+ l; v$ P
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ w) K: y! @ m: Z) J frame.getContentPane().setLayout(null);8 N- |$ M" w9 r* }' b4 H* c
5 R( \5 F; S d" A' T
JLabel jl1 = new JLabel("\u7F8E\u91D1\u73FE\u503C");
! T; t+ P' x# ]- A4 ?6 { jl1.setForeground(Color.BLACK);
- [! ?$ A& ? ^ jl1.setBounds(20, 27, 60, 15);
3 f: y) J6 {! V) F% \ frame.getContentPane().add(jl1);2 L" n0 D- o6 e2 I3 @
2 I# h" C" _7 b8 y1 Y) Z+ l JLabel jl2 = new JLabel("\u65E5\u5713\u73FE\u503C");$ Y, Q" h9 `2 Y. F
jl2.setBounds(20, 63, 53, 15);7 T/ o6 e6 h% \# A5 J
frame.getContentPane().add(jl2);
) s9 p) n4 }4 F# B/ @4 E! R
! S4 C, b R& K6 [ tf1 = new JTextField(); @6 w; h$ F2 X3 z5 b
tf1.setBounds(83, 24, 96, 21); D: ~# v( z' D5 s* R3 f4 K
frame.getContentPane().add(tf1);
$ W. g. c& M* t4 H: d7 Y tf1.setColumns(10);, v6 _, U, D# s5 g3 ^
9 [, Y/ w/ A: k1 y& R JLabel jl3 = new JLabel("\u6E2F\u5E63\u73FE\u503C");6 F3 N" F7 Q! @; u
jl3.setBounds(20, 102, 53, 15);8 A- h5 P, k: Z) H' S- U! W
frame.getContentPane().add(jl3);1 G$ d+ W* i. [* X1 I
& o8 W- ]: a; l+ K JLabel jl4 = new JLabel("\u82F1\u938A\u73FE\u503C");
; @$ p; Z& a$ d9 q2 t6 t9 j! y jl4.setBounds(20, 141, 60, 15);" P2 b0 [/ U, f, Q9 k7 N
frame.getContentPane().add(jl4);7 |8 G5 {7 ?5 ^
: n% C6 X/ v0 R. {7 c+ \8 J4 w0 P JLabel jl5 = new JLabel("\u6B50\u5143\u73FE\u503C");- ?$ @5 Q7 F( L( p
jl5.setBounds(20, 180, 60, 15);4 o. y2 a5 m% l0 y D
frame.getContentPane().add(jl5);/ ~0 n! N/ A" }/ m4 H, a
& }: y! p- J0 f2 D7 |- I; e
tf2 = new JTextField();: J6 \3 u1 @$ t6 v
tf2.setBounds(83, 60, 96, 21);
/ _- O& ]0 ^6 E, ? frame.getContentPane().add(tf2);
2 h+ m O9 w) D/ O( w tf2.setColumns(10);3 \7 [- O1 A i6 b* ~
' T7 ?4 P! ]( `! T+ p) P( j
tf3 = new JTextField();2 B/ S3 s2 b. e* O. ~7 C
tf3.setBounds(83, 99, 96, 21);
/ }, D1 v8 M6 r3 b3 C frame.getContentPane().add(tf3);
! t' E9 b7 x/ W8 k+ L( L tf3.setColumns(10);4 i0 S6 Q$ V/ q% O! u
$ J! e3 [. {) x7 u; m8 O- d tf4 = new JTextField();
: Y$ ^; ?9 V7 {$ j tf4.setBounds(83, 138, 96, 21);
4 x# p/ b$ h4 G frame.getContentPane().add(tf4);
+ Q- ?: Y4 @! m/ ~ tf4.setColumns(10);
6 V. F0 z, y8 n+ a" V
8 T0 |8 b. f% L% ] tf5 = new JTextField();0 W2 F }4 L" U
tf5.setBounds(83, 177, 96, 21);" m' ~5 \9 b& K6 S1 I
frame.getContentPane().add(tf5);' b! @7 T3 H; |' k- h
tf5.setColumns(10);. E- v" C) s) r& ?+ X* P Q' s* r3 E
1 s* K/ q/ R" D$ f4 Q/ d' F
answer = new JTextField();/ O) l$ a# K3 z/ D8 ]2 l' O
answer.addKeyListener(new KeyAdapter() {
: W' t+ Q/ b: y* K% R @Override) i3 E0 S3 F! X1 s$ e$ s
public void keyReleased(KeyEvent e) {* z. u# H4 G8 `* O3 d; ~
System.out.println(answer.getText());6 z. q& t/ L" b( r2 n
8 f- I+ V9 r0 }+ k9 A0 [
try{
# K/ x1 T% a, c+ c6 p double num = Double.parseDouble(answer.getText());
2 c7 E5 P- D$ V+ Q2 ]* J9 i# r2 J$ ~
: T1 m/ [1 p+ I m; J) \/ S( Q : T9 n9 o! @$ d9 R
tf1.setText( String.valueOf(num * 0.029) );
# c f/ S6 _+ x) D4 i( N tf2.setText( String.valueOf(num * 33.53) );- L1 v/ d3 U% |* }; ]
tf3.setText( String.valueOf(num * 0.22) );) Z `" n+ Y' W: p* }9 M
tf4.setText( String.valueOf(num * 0.018) );
6 M1 B/ L( \5 T$ U2 D1 W8 ] tf5.setText( String.valueOf(num * 0.03) );& w4 o3 ]" |( Z6 E$ ^' o
}catch(Exception ex)
. G# b- a' H% V5 v1 v5 [' } {! N! i3 h# N2 D& b
tf1.setText( "請勿輸入非數字的字元" );, {6 ]/ G u2 p9 f, y, l
tf2.setText( "請勿輸入非數字的字元" );
: X' v K7 N, i9 l5 N' ^; I tf3.setText( "請勿輸入非數字的字元");3 z! w N5 }& F. h$ K5 v& N7 X
tf4.setText( "請勿輸入非數字的字元" );
8 N/ h( B, k+ R) J8 u tf5.setText( "請勿輸入非數字的字元" );
/ Z# @: {+ j% N2 c$ h5 s3 o! D, G }
/ c+ D1 _8 `0 I4 {( ~' z3 x ' t0 z7 q3 `7 i
}
& n+ j" T! d/ [$ ?5 W9 o });
, _" Q+ W" W8 c' g: _# p0 Q1 Y
4 U0 g7 y( t2 ~ answer.setBounds(20, 224, 159, 21);. M+ |" c. L" K \* A
frame.getContentPane().add(answer);
! P7 B9 E; S" S answer.setColumns(10);
. {6 |! k8 w$ F& x }' s! O- t4 A" {( c; r
} |