import java.awt.EventQueue;4 J" k: v! T; Z
2 x u& P: _# l4 \! N
& o( I6 L6 ?, G" A" T# F2 v% e0 n8 G
public class TQC301 {+ B6 H7 l! o' P8 |! \
$ |2 _; ~% f# w, m3 R/ T private JFrame frame;5 w z4 l, S7 e3 G3 A
private JTextField tf1;
) ~3 n# y; ^% N private JTextField tf2;! L& A! G5 e" O2 O& x" S
private JTextField tf3;" f. S( ]) R) {2 d1 b! T7 `- ~
private JTextField tf4;
4 S4 r6 _' E4 y8 E private JTextField tf5;
_7 O3 |5 |; ]# c I. O! H0 ]5 Z private JTextField answer;+ D2 Y9 G' C& r. |' f1 F) }
3 o& w* M% O! Z, N) m /**- x! N# Q0 x% i+ H
* Launch the application.
, J0 Q, v8 }" ?+ x& Z: t */: m8 ^- Z" N3 z$ g) b2 ]* `
public static void main(String[] args) {
4 O" L* Q1 x- G8 Q+ R EventQueue.invokeLater(new Runnable() {
" E2 [( {# R( O! z$ T! @+ J public void run() {
! `3 l9 t+ T4 r& p; r; o try {0 g7 ^, Z: r6 C% }
TQC301 window = new TQC301();9 C- ^% k1 p' R5 A
window.frame.setVisible(true);
# a3 W/ y- Q3 ~6 M& L } catch (Exception e) {7 P0 i" K: b5 Y3 D' h0 a' {/ |
e.printStackTrace();% g6 I6 k% f1 X* K, r
}% Q% L- G6 _" b5 \
}. `* _6 y2 a- b: k y* n
});- T/ S" K! m- u+ B. v! |7 E$ x
} o& R' J" g9 \& D5 e0 {& F7 r
3 g3 ^& V- r4 m4 [) Y! W& V3 m7 W /**4 `* o4 f9 M6 k5 g) M
* Create the application.0 r8 p" ^3 ~3 M$ Y9 o
*/7 S- M8 F. M8 I$ M- F
public TQC301() {* V( H: e% x) Y& p( c: _6 I
initialize();4 V' u1 T! ~" V0 ^
}' J5 C1 C) O5 ]. X: p. E
; z) G) V2 J1 p: G% P1 G
/**
3 }( i4 Y" Y/ {! ~ * Initialize the contents of the frame.% i. {7 L1 `: \ d8 K
*/6 E' W: y! K/ ?4 J6 D8 a4 E
private void initialize() {3 q+ T+ Z5 o4 [3 T- B9 j6 y
frame = new JFrame();
/ \ e! E# U3 {& a. g/ c- n$ ~ frame.setBounds(100, 100, 450, 300);
& I% }) ? j7 X& s p- }* P frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);8 w1 y7 [8 S; ~. Q; K: R+ M9 t
frame.getContentPane().setLayout(null);
* @0 i4 r) V; U; u
+ ^$ [1 p7 }% G% N JLabel jl1 = new JLabel("\u7F8E\u91D1\u73FE\u503C");
' v9 o( z3 z6 s: M- q5 J4 M+ j jl1.setForeground(Color.BLACK);
- p) p- f9 v) L jl1.setBounds(20, 27, 60, 15);; [ G, q# w' _/ i" D1 Z+ i; Z
frame.getContentPane().add(jl1);
- G0 D! l I5 C# }* \' V; b 7 [% o; Y4 f. e8 f
JLabel jl2 = new JLabel("\u65E5\u5713\u73FE\u503C");5 d$ n! B2 V& u( k( g% l% ]: h
jl2.setBounds(20, 63, 53, 15);2 G5 l* B; z: ]1 e; \7 N
frame.getContentPane().add(jl2);' g) k/ l: d' |2 O
9 u3 | Q* M) E tf1 = new JTextField();
( _# e: l7 S& {) W# t tf1.setBounds(83, 24, 96, 21);
2 N( e) `5 n4 B" g4 }( @, i0 _ frame.getContentPane().add(tf1);
3 L" S- `; v) D# \6 ^ tf1.setColumns(10);
: X0 t+ o: _( J
' m' f i$ R5 c' E: k1 o" E JLabel jl3 = new JLabel("\u6E2F\u5E63\u73FE\u503C");
6 M c% B% K2 x I jl3.setBounds(20, 102, 53, 15);
- l- I, ~! x6 o frame.getContentPane().add(jl3);7 H: E7 f3 B8 y6 C% j
9 [) T3 U" W9 {/ p' j
JLabel jl4 = new JLabel("\u82F1\u938A\u73FE\u503C");
3 F/ z, J7 a# D$ o" b0 V7 P jl4.setBounds(20, 141, 60, 15);
1 g) K" u% I P frame.getContentPane().add(jl4);' ^% L- D1 K+ E
. S2 ?5 F+ N4 N0 G! F$ c
JLabel jl5 = new JLabel("\u6B50\u5143\u73FE\u503C");2 p0 B1 v7 j. Z
jl5.setBounds(20, 180, 60, 15);
- {- V! b: T, `. f1 G frame.getContentPane().add(jl5);2 p7 b3 m5 r4 ~9 C5 B4 A. |
1 g! r4 N, S* |8 w tf2 = new JTextField();
6 I' g/ M. ~7 ^8 f$ A1 W/ g% B$ h tf2.setBounds(83, 60, 96, 21);5 Y! r/ {/ ?& A" g; w3 C( l
frame.getContentPane().add(tf2);% D! o4 N3 I6 I( E" q& u
tf2.setColumns(10);
' r/ R3 n% b/ r+ t- d* y+ {" l . g1 |# C0 m+ K
tf3 = new JTextField();( Z' W) Z; q0 u
tf3.setBounds(83, 99, 96, 21);9 T' t" [6 x( w2 [2 o8 I
frame.getContentPane().add(tf3);
. b' w- h0 s) n6 y tf3.setColumns(10);
/ q- G) t# r4 q+ h$ j5 I 1 [! r" B" \! Z; Q3 N6 P6 N
tf4 = new JTextField();
9 j& ~! n6 k4 c: N+ y tf4.setBounds(83, 138, 96, 21);
) v2 o" f/ N* _) p R frame.getContentPane().add(tf4);
! d& i/ g7 s+ [3 k; y W& s: Q% R tf4.setColumns(10);
2 W# e0 l( i1 p0 H 3 I \6 s! {* W$ Z, y
tf5 = new JTextField();- w4 T% ]7 y/ ^' J- q) j, U7 o
tf5.setBounds(83, 177, 96, 21);
; g0 J: p& R& j5 u; q2 l) g frame.getContentPane().add(tf5);
4 B6 J- O$ h* f; F7 A tf5.setColumns(10);
( t( Y- F3 J( i; b7 |* b5 K
7 W* @4 e5 x* _ | answer = new JTextField();
) O! r1 F4 } _7 m; E" V# Q8 ]1 }* R answer.addKeyListener(new KeyAdapter() {- R |$ [; @. m/ _" L k/ R
@Override0 [4 a3 H$ f8 h
public void keyReleased(KeyEvent e) {7 ^3 [0 B; d& Z3 ~- y* [& o6 h$ U
System.out.println(answer.getText());! Y* b8 b+ j0 h
% s7 s7 d/ D, z+ t z; ^& B try{9 M5 p# w* X' t: A" w+ S
double num = Double.parseDouble(answer.getText());: y, j ^% `' k# J; d
. X+ _2 f8 E5 T8 @
' H( X' N3 A+ K/ l. p' ` tf1.setText( String.valueOf(num * 0.029) );% M3 _: n" @9 H
tf2.setText( String.valueOf(num * 33.53) );
/ r' B& z" ?: W: x8 ` tf3.setText( String.valueOf(num * 0.22) );
. `- ]5 W9 t+ ^8 M; Y! H( S. v tf4.setText( String.valueOf(num * 0.018) );$ Y' M- y1 ~2 d1 \* D" R
tf5.setText( String.valueOf(num * 0.03) );
5 @" V% ~, J2 A4 T% | }catch(Exception ex); P, ~7 i2 [+ z Z; a# u: D, a
{/ F1 A: W2 a) d: V, {
tf1.setText( "請勿輸入非數字的字元" );
2 } S+ R7 X. { h$ i tf2.setText( "請勿輸入非數字的字元" );
" a( _1 O6 c8 R4 t tf3.setText( "請勿輸入非數字的字元");& Y4 ^+ P5 I5 ^5 [2 x% V
tf4.setText( "請勿輸入非數字的字元" );5 |% ^4 y) A3 W: u% T3 M& |- i
tf5.setText( "請勿輸入非數字的字元" );; t8 N! z+ B8 A. ~2 B# ?. Q
}- g3 D4 T: C6 U3 k. X8 k1 y! {- o
& c; _$ ^2 v7 |! H2 [
}
& s8 f' _0 U( ^$ U });
" L7 j# w c9 G1 i; ]$ a- _( X8 |3 k/ d3 M2 }
answer.setBounds(20, 224, 159, 21);" R5 L7 }* l: M7 ?* I0 T2 F
frame.getContentPane().add(answer);8 G( |" P# f$ I+ I; G. t
answer.setColumns(10);+ b/ A8 N% t$ i
}1 H% k5 x7 ?+ R& w* L# H! u) i
} |