import java.awt.EventQueue;) U4 \- t* {( G" o( o0 r3 b
" _9 s) v7 v3 O/ q" d2 R7 A
& Z6 x7 G6 p* v8 q5 I/ c: opublic class TQC301 {0 a! W2 k: H' }9 ]2 A& B
3 Q1 k5 V+ z, h0 S3 b
private JFrame frame;
1 m' [! ~* L; m private JTextField tf1;
- u. l; I1 o* L+ U private JTextField tf2;
0 h5 S, G" p, C9 O0 r- v: g) l7 [- ~ private JTextField tf3;* u( E9 c/ w' p5 R4 ?2 J) I& }. U
private JTextField tf4;' h) D: D- `7 e% \
private JTextField tf5;
7 Y/ O% q6 q% w% T# G* n private JTextField answer;* z- V7 v3 e1 q
' M; L/ J# q3 [ /**
]1 g0 q0 x9 C9 f8 I, _$ V * Launch the application.
/ r1 T" q, B1 Y. ?1 k) G9 b */
$ v: X x7 a" Z public static void main(String[] args) {
) b/ `5 _( P) z# } EventQueue.invokeLater(new Runnable() {$ n& Z' ~: Y+ U7 X2 ^4 f) [: M- v7 L
public void run() {
& }8 t, [/ X4 ^+ B try {/ W. |+ ]# c; s- n2 w4 I& h
TQC301 window = new TQC301();
/ r' Z+ k9 T3 O' l8 o3 {& e/ b window.frame.setVisible(true);* f2 ]3 P5 }) b: z
} catch (Exception e) {
- Q5 U& f$ [0 J1 T! _ q- ` e.printStackTrace();
% \" g. t0 Z4 |( w4 K }( Z1 _( V% Q# o4 X# D! l! _' x
}' [$ Y& Q7 z. P2 D
});
& y- U# i0 d7 b' g' s# ? }
, c0 H3 s; u' H
& R q) @/ ~4 K! t5 J7 U' a6 d: Y& f /**# ?7 W( | J7 N. p
* Create the application.
8 b! w/ I3 w" j */6 x' P7 m& S1 V
public TQC301() {
% I7 q2 [. M! b i1 a8 Q8 L1 c initialize();
0 m! R4 H/ C7 S; p* C }! _, w" |; T$ U- }7 @: }* T( H
; J: z ^7 D: d" E7 Q /**
% b0 X( P! W1 _; N$ a; H& j/ [ * Initialize the contents of the frame.1 a& b) L0 O! }( L3 Q( \ h8 V
*/
$ p4 T0 Q6 |6 X3 e& l7 V8 M private void initialize() {* p: E8 c, Z( R8 X' ?+ I3 t; S
frame = new JFrame();! g2 j" d0 E* `5 H
frame.setBounds(100, 100, 450, 300);& ^; ~) M3 {) M6 C$ M9 C1 e
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);3 m# w( E* a5 Z# e( d( s
frame.getContentPane().setLayout(null);2 O& m( {" ?/ ~$ h" D+ f9 j/ z
6 i- H3 \% t, j7 l JLabel jl1 = new JLabel("\u7F8E\u91D1\u73FE\u503C");
7 A: c r+ m0 O/ a jl1.setForeground(Color.BLACK);
) W( ~: J4 U% H2 {- u1 B jl1.setBounds(20, 27, 60, 15);$ J; c% h0 _$ _' a+ c" m* S
frame.getContentPane().add(jl1);
8 @1 ]7 i, T( @3 z" ]
; |% a1 m& y, ]; X' _ q JLabel jl2 = new JLabel("\u65E5\u5713\u73FE\u503C");
) D2 E x; Z! A' { jl2.setBounds(20, 63, 53, 15);
5 l1 U2 e5 M+ e frame.getContentPane().add(jl2);7 P ?$ s4 b) \
; g- [( z2 `! _: M tf1 = new JTextField();
' N) j' G4 A L, O: ^) j, N$ p tf1.setBounds(83, 24, 96, 21);/ e. I8 k2 j8 |% K+ z
frame.getContentPane().add(tf1);
; V" A T9 G- \7 d4 J- S* T tf1.setColumns(10);
' N( |' j" X' l, W- d" T6 r' a / P8 }1 J0 {6 C# p* D. N
JLabel jl3 = new JLabel("\u6E2F\u5E63\u73FE\u503C");
, _1 N6 u" F+ z: J4 U& o/ R jl3.setBounds(20, 102, 53, 15);
! _. s' h9 X& t' j1 t# {/ b3 S+ v frame.getContentPane().add(jl3);
" t* Q+ N8 k2 V9 F6 F. X5 h% D$ q
2 E' ?/ H+ l" x5 u JLabel jl4 = new JLabel("\u82F1\u938A\u73FE\u503C");7 n4 ]( q! j }/ `8 i' Q4 W
jl4.setBounds(20, 141, 60, 15);% O8 \" M5 q: ]) @) C2 z6 R- u/ r
frame.getContentPane().add(jl4);; {" G# i. W" Y) k7 n# k9 ^0 ?. o
5 g8 N' u4 n8 [ JLabel jl5 = new JLabel("\u6B50\u5143\u73FE\u503C");
& h! _) U9 r. G1 B3 ~ jl5.setBounds(20, 180, 60, 15);" U, v9 y/ I( k/ J$ A. V7 V$ F8 T
frame.getContentPane().add(jl5);
5 Q- u. F6 ?2 `1 t" u' R Z9 P/ s2 I+ i! v) n0 E
tf2 = new JTextField();6 T7 F8 q( N7 R: W$ H
tf2.setBounds(83, 60, 96, 21);
" E) R. ` m, f+ u# W7 U frame.getContentPane().add(tf2);
' B- i1 g2 b/ @ N5 V tf2.setColumns(10);
: E$ i2 j0 E! f4 D$ n( P, v ) s- b% e, x, a+ i. b' t
tf3 = new JTextField();
5 C4 ^7 U; d. n tf3.setBounds(83, 99, 96, 21);
; e' K y" P6 z frame.getContentPane().add(tf3);2 L2 @' Y# `6 y( [" I4 u+ _7 P
tf3.setColumns(10);, Z' e2 D0 A8 N. w
! h7 y, j+ K% P! x* S4 l
tf4 = new JTextField();
- ]" M1 @1 i* j8 l& I" ~4 i* d/ U tf4.setBounds(83, 138, 96, 21);4 j( L6 M- s& a/ D
frame.getContentPane().add(tf4);
$ W/ R8 j% I7 z7 j tf4.setColumns(10);2 A" h5 u1 I0 G6 `- _
+ ?; w* D; \4 t n2 R) O tf5 = new JTextField();
! E( {& u+ O9 {, y$ } q' a tf5.setBounds(83, 177, 96, 21);* q, U, }* y- T0 F
frame.getContentPane().add(tf5);
4 n9 Y3 L' M& O3 C. a! T% R" {9 ?( ~ tf5.setColumns(10);3 S, A2 G$ {- D
& Y* q: M* U7 s' B( `+ e- ]& S/ A( a
answer = new JTextField();
! |( C5 |+ e3 D& n, h* X9 I answer.addKeyListener(new KeyAdapter() {
$ Y* ^9 Y2 Y* z @Override) v4 y8 ~$ n; |& P, L8 R
public void keyReleased(KeyEvent e) {
, O+ i( D4 l8 M* _5 Y% [% ~ System.out.println(answer.getText()); [. x( `8 u2 v; s% I; R
: k% a% d8 T3 a2 C [, R
try{
+ \5 H2 m) z) J2 j double num = Double.parseDouble(answer.getText());4 T( }; w: @! c$ x
8 h. H/ P5 U! b9 ]- {% q - ^, D' H& A# g! V6 s
tf1.setText( String.valueOf(num * 0.029) );
- \5 }% J, H% n. z1 E tf2.setText( String.valueOf(num * 33.53) );
$ ]# a2 j: E% a: d8 Z8 M tf3.setText( String.valueOf(num * 0.22) );, j# f) H. E+ e2 M# F2 Q7 ^& S3 O
tf4.setText( String.valueOf(num * 0.018) );0 R" ^* i1 d( {2 Q+ \- r
tf5.setText( String.valueOf(num * 0.03) );* R z5 ?( ~2 d l5 b8 @
}catch(Exception ex)
& y7 ]# W$ m- j3 ^ {
! b$ X% |0 |! b* e3 E- G8 \ tf1.setText( "請勿輸入非數字的字元" );0 R" n) H9 Q8 {- J3 D( Y" i
tf2.setText( "請勿輸入非數字的字元" );) ?& A+ f3 {, N: c* w0 L; X2 ]
tf3.setText( "請勿輸入非數字的字元");
7 J3 f% |- |' n( p7 z tf4.setText( "請勿輸入非數字的字元" );) }$ Z3 R9 }1 O7 F a
tf5.setText( "請勿輸入非數字的字元" );
; V0 J1 R3 G: P" Q }3 C$ k& |5 g$ k3 Q
& d' e- s5 {4 y3 z! z) J9 @1 E }
, H5 U" Z: T% Q4 j! u6 _ });! z7 G7 m9 w& [% H+ D4 j4 _
7 i$ f8 g# S6 b1 Z. T7 | answer.setBounds(20, 224, 159, 21);
- Q* N# z) @& c/ [$ g7 g frame.getContentPane().add(answer);
4 ]- @- |9 @, V+ P, j answer.setColumns(10);! Y3 Y1 Z3 F! ]2 R2 r
}
V1 y* n* V$ I* h8 {} |