import java.awt.EventQueue;
8 \$ o& ?& V. Z* ^; C0 }$ b V( P, P' Q3 u
" L0 T# ?6 u0 ~' _0 Q
public class TQC301 {( h! f$ n- ]# |& i
- L1 ~( M+ ]2 Y private JFrame frame;
! Y! `- U( w0 G+ ~$ p private JTextField tf1;
0 W* p& i4 X7 ?, J private JTextField tf2;
c7 W! m9 d# Q: N, ]" ? private JTextField tf3;
0 S2 L- H7 `2 \" F private JTextField tf4;
# |2 O, {1 \9 V9 _# ^9 F; W; Z1 q0 v private JTextField tf5;( T8 m1 W1 x, O
private JTextField answer;* J1 q! h: M0 x; u4 u1 t6 w! d
7 o8 e# j0 f* B& m. v
/**+ Z+ q& l2 e' a) n( U! H
* Launch the application.
; F/ L1 ^! C$ s4 [! j */6 c. ? ~ {, \
public static void main(String[] args) {5 @1 W2 u- X1 d3 z
EventQueue.invokeLater(new Runnable() {4 c/ L9 O5 C5 J- l
public void run() {3 f$ ^ B' @$ v' A
try {
2 R. b- ?+ [8 \" q+ \ l TQC301 window = new TQC301();
/ c/ \0 B3 Y2 O2 c window.frame.setVisible(true);! v1 c7 @7 o& v. _8 j0 S3 L1 p
} catch (Exception e) {
5 [, m9 f3 b; B+ f Q# |$ \/ p( o, g1 G e.printStackTrace();! w! C$ D8 I9 {8 N; r2 r, p
}
* o. |; ~+ A, M, i& U5 @ }
0 j0 h8 C) n6 @- F5 g. \9 g });
" E' F. H0 @4 }) D } o' E( `" ?5 _9 Q
r1 Y0 N) y1 r _4 N, u3 a# g /**
& C8 |, T! l9 J2 H4 g7 o" R2 G1 m * Create the application.7 i9 ?* l4 c, x! c
*/: r7 x5 w0 l# n: d
public TQC301() {& [; l( k. W/ M7 f
initialize();5 K b. W$ L1 h+ t
}
3 g) ^& q' v, ^: n, M" k
p/ r$ ]* X, a( G& U* T /**
: ^- L( Y, O7 \' w# y0 ^; Q7 m) i * Initialize the contents of the frame.: B; U4 L x( p: z
*/4 O( u: H; m ?- {1 i( S4 j- L% w
private void initialize() {: n) e+ M* G0 w- I5 Q0 B+ @
frame = new JFrame();
! k0 [8 y( D, s4 H- E- @' O8 S frame.setBounds(100, 100, 450, 300);
S) ~ ~0 V# {3 q( p0 V4 X5 c7 J frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- A1 I7 N; M7 W& H7 b" S' h( \ frame.getContentPane().setLayout(null);
, V% a$ u: Y' f, M3 ]# d1 T
) `2 S; f) Y. u1 o( P JLabel jl1 = new JLabel("\u7F8E\u91D1\u73FE\u503C");% X& a9 U' a$ E9 y) r8 a9 l- v* o; c
jl1.setForeground(Color.BLACK);
4 d$ D6 A! K& Q3 S- r W7 q jl1.setBounds(20, 27, 60, 15);
, x Q4 F3 R9 Q { frame.getContentPane().add(jl1);' B: t2 c3 [+ D9 w1 y, z/ K) j2 J
0 O" Y% [4 R" t7 E/ L; Z5 s4 Q& Y
JLabel jl2 = new JLabel("\u65E5\u5713\u73FE\u503C");* |4 v. z- j+ ?' R
jl2.setBounds(20, 63, 53, 15);% _0 P$ x2 k: D- N w6 e( e
frame.getContentPane().add(jl2);
: Y' ~1 S+ }1 A* m3 p( m
$ S/ J! D$ w( G5 b9 L4 g tf1 = new JTextField();/ `3 W* d: J2 m! ~ _3 m
tf1.setBounds(83, 24, 96, 21);
2 O+ w5 d4 M2 O frame.getContentPane().add(tf1);
! H0 O0 E' T. w tf1.setColumns(10);* ]/ t- |- ^3 |% F! F
- b$ _8 V' }, i; D8 U JLabel jl3 = new JLabel("\u6E2F\u5E63\u73FE\u503C");8 O/ |7 x9 V7 t9 ]9 W3 V# }
jl3.setBounds(20, 102, 53, 15);
6 h, B r' M- V frame.getContentPane().add(jl3);5 R" {! U+ w: B& K" P0 X, ? j
# i5 W4 M# U8 j6 x
JLabel jl4 = new JLabel("\u82F1\u938A\u73FE\u503C");9 y6 V5 H1 e3 W3 {* u) }: c
jl4.setBounds(20, 141, 60, 15);
t8 [- c* s7 J/ t {: K( h2 {" k frame.getContentPane().add(jl4);# M$ q4 r0 M) g: y$ ~; w+ f+ M. |
8 Z& ?. n/ i* Q' g C JLabel jl5 = new JLabel("\u6B50\u5143\u73FE\u503C");! S }, C+ F5 L7 P0 |, V- a
jl5.setBounds(20, 180, 60, 15);
- ?& }; c# `9 ~0 `* y2 u7 Q/ d frame.getContentPane().add(jl5);! m+ e, R* J! G5 S9 L
e/ \1 G9 `0 d! J tf2 = new JTextField();
/ o1 z" [8 D4 z+ Q6 d6 _1 w0 { tf2.setBounds(83, 60, 96, 21);' W7 l7 d K5 J
frame.getContentPane().add(tf2);/ U9 |2 r$ e S( c9 G9 J, ?
tf2.setColumns(10);9 ~7 e8 E1 X- n2 U: j1 O9 |
! A Q- Y* F- p# q; Q/ u
tf3 = new JTextField();
/ \3 s$ D0 j; Z4 d3 `* v tf3.setBounds(83, 99, 96, 21);
# b0 `* S a. H7 S3 s& ?/ X+ O: E frame.getContentPane().add(tf3);6 o w* y$ Z, Z6 B3 R
tf3.setColumns(10);
- k& c, m1 Y" P2 e/ P% Y $ N7 I$ O* U& A# m
tf4 = new JTextField();
) H# U4 [. V; r! w3 E: D tf4.setBounds(83, 138, 96, 21);% d) J1 M2 c, V, p
frame.getContentPane().add(tf4);! a3 h- F* L& V9 l9 u; _1 E; _
tf4.setColumns(10);1 w5 j" `5 u. M! C y' W
$ Q6 ?3 p/ q7 Y1 K) a tf5 = new JTextField();
$ k$ v0 y# t' ^& h, e- P tf5.setBounds(83, 177, 96, 21);& R8 [# k/ |% ~3 b: |" d
frame.getContentPane().add(tf5);$ ?' w! ^ }# c" r9 j3 s
tf5.setColumns(10);$ \. X' @. @6 ]9 j! e
$ F% v8 B" ]/ K" a& e
answer = new JTextField();
* u( a! p; C3 b. D% H answer.addKeyListener(new KeyAdapter() {4 M) U5 Z! C1 F6 I
@Override! x7 B" f) L* ?8 e2 Y" B( C w2 H6 a
public void keyReleased(KeyEvent e) {
7 [* V9 K$ n/ S$ v( m System.out.println(answer.getText());
! x: Z: q0 P, ~4 _+ ] 7 {8 e( X9 B X' P
try{
% P% \5 ~; P1 @: D8 { double num = Double.parseDouble(answer.getText());
4 Y1 x) {8 P E( L
) H* j. P/ x0 z3 i7 _
$ O( l8 d# D9 c1 k; T' x tf1.setText( String.valueOf(num * 0.029) );
6 A% w) Q+ F1 n) ~ tf2.setText( String.valueOf(num * 33.53) );
: _+ W+ ?* Q8 o3 N" E tf3.setText( String.valueOf(num * 0.22) );
/ r: f u. ^: Y9 ?( p( r+ V# Q tf4.setText( String.valueOf(num * 0.018) );; b( M( c5 \3 y2 }% U1 R" P7 _
tf5.setText( String.valueOf(num * 0.03) );0 V5 ?1 ^! f5 h, E: g/ q
}catch(Exception ex)
5 O- V# o- c2 z8 \9 J. j {. w$ d! m1 k3 k! F# \; h
tf1.setText( "請勿輸入非數字的字元" );
' P: O) ~+ Y% S' Q8 Y; n2 u tf2.setText( "請勿輸入非數字的字元" );
" z0 F" U5 G# d9 w5 d* x7 Y tf3.setText( "請勿輸入非數字的字元");: a* P' A$ g) n% c
tf4.setText( "請勿輸入非數字的字元" );
' s" i, W4 k s. B. t$ b% D tf5.setText( "請勿輸入非數字的字元" );% C+ E& v! Q6 c9 V3 | m; C; p
}
# W. R/ H' X- @6 d; c9 l* A - ?0 S1 M& k6 X
}
X/ y# g) [5 S6 e6 P( I });. d- X3 R" l: a8 I2 R/ T5 W& F
# u* {! ^/ b- x/ k) e answer.setBounds(20, 224, 159, 21);
7 f9 ^0 n6 |5 T) t% q9 X9 V frame.getContentPane().add(answer);
: F! z3 E' p: i$ f answer.setColumns(10);
% X, |( {+ H* v, S- ] }
- x/ y1 u; y6 v( v8 Z9 C} |