import java.awt.EventQueue;& |& o8 D6 a: ]# l" x0 U9 M0 u* p' g
! _* w! t7 M- z- p# U5 C
# D* _$ P8 X3 p$ i+ E* j+ Vpublic class TQC301 {
9 r0 X ?( Q- X* {2 [% x: ^. o
2 W; Z4 i* Z5 D private JFrame frame;
" T3 C- X1 V6 |" l" b L |6 F) ~: j private JTextField tf1;
- T# H7 i! p7 ?2 K private JTextField tf2;+ j7 U1 \+ Q$ Y! k( c$ \* u# p
private JTextField tf3;
/ ~ v8 Y. B" e* Z0 _ private JTextField tf4;
* _5 c, k' ^. L5 x private JTextField tf5;
5 B/ r4 }: j# B0 C private JTextField answer;3 G. d# t/ E) Z
" ?( S9 U! R. s' y6 d' c4 g r
/**0 F5 l4 J- J5 a# v. p) R3 ?
* Launch the application.
+ @1 K5 T2 |: N: {: f */5 V% C- F4 M+ T2 h& r+ z2 L3 _0 \8 r
public static void main(String[] args) {
7 e8 l5 Z* E5 V- |9 C EventQueue.invokeLater(new Runnable() {
4 U+ r2 Y4 d' J; f public void run() {
+ I7 `6 y9 n' u* C2 Y F try {# o" y- v0 x4 R: n* T: G
TQC301 window = new TQC301();1 _; P& L, s" j. Y
window.frame.setVisible(true);
2 k% [% r% ]0 t2 N1 N% T+ F' G } catch (Exception e) {
, z. i8 y" [' r5 y0 @4 n1 |; x7 e. ` e.printStackTrace();
' ^, X0 S/ m3 `; j* e$ k }' z1 F @* u7 K0 w
}
( V2 y5 Y% M& C2 i9 n });4 V- {) h: h! [* e2 E" C
}& k+ z% b+ F. N2 y6 Q
- @* c# c* \8 l" u# T /**
( B; d: b! d5 h3 a; ^( _ * Create the application.
* u/ ?; z, P) x; `3 D3 k1 p) { */
% L* Z9 f* `, l [6 E public TQC301() { K/ Y. V9 m0 q% i/ W( r
initialize();; g t% m3 v) o
}
+ T6 D$ D8 u, b' w) V( h
' B3 T7 P7 P/ [% }! ?, r /**- x$ }$ j0 b) s0 }
* Initialize the contents of the frame.( I. P! s" p2 b! }4 E; @5 `3 ]4 l" s
*/
8 i3 c! n4 B$ U! G- n& [, V5 h private void initialize() {
. Z) q, Z) ^9 L% v9 T; Y: m frame = new JFrame();, f L3 A- T! ]+ w/ n
frame.setBounds(100, 100, 450, 300);
1 P8 e2 x8 A0 a frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
, S3 N* X1 P7 N, j1 Q frame.getContentPane().setLayout(null);% b) E6 \* q- w4 `
* p% X, |5 S* Q: C
JLabel jl1 = new JLabel("\u7F8E\u91D1\u73FE\u503C");
& C- [) T: R% _/ ` jl1.setForeground(Color.BLACK);
! I7 C' h) }+ c5 j8 }* e jl1.setBounds(20, 27, 60, 15);
# `, x% t$ \5 @# I* X& O. D frame.getContentPane().add(jl1);
: p |! M$ H& H7 c5 l1 g2 o* |2 p" g6 y
4 y" h- A" f; a8 |% Z. r. g: C4 E JLabel jl2 = new JLabel("\u65E5\u5713\u73FE\u503C");
8 L m. K4 {; S6 {; M jl2.setBounds(20, 63, 53, 15);8 k$ k" H1 k4 ^2 V6 }2 _
frame.getContentPane().add(jl2);* U# A, F9 ^" v5 Q N
$ N9 F* o6 J X9 D
tf1 = new JTextField();9 r" O- a+ G) \# |$ Z0 v* ^
tf1.setBounds(83, 24, 96, 21);
5 ^1 E! n! V# H6 L3 u4 | frame.getContentPane().add(tf1);* n3 n S" n" ?6 w
tf1.setColumns(10);) o M& F* @& `
: P: J/ M3 n- y/ f# \- h* _9 o3 D JLabel jl3 = new JLabel("\u6E2F\u5E63\u73FE\u503C");/ s" [' W2 C$ W; s" Q. Y' m
jl3.setBounds(20, 102, 53, 15);
% r U# o7 k7 b% o frame.getContentPane().add(jl3);) t: z& e. i8 X: \2 l
5 V% H5 f" n7 @- P; P( f JLabel jl4 = new JLabel("\u82F1\u938A\u73FE\u503C");
7 X6 Y. P) R) j( } jl4.setBounds(20, 141, 60, 15);9 T+ D! C0 _/ s% ]
frame.getContentPane().add(jl4);
& }( _7 w/ M. e
, r" x% z1 `& m- ]4 j$ i2 Z JLabel jl5 = new JLabel("\u6B50\u5143\u73FE\u503C");
2 I# u8 F8 s# l \) ^ jl5.setBounds(20, 180, 60, 15);
; e4 V; |0 L+ o1 q frame.getContentPane().add(jl5);# t& A8 D9 y9 P3 q
4 t# l4 S# S$ Z) Q2 U tf2 = new JTextField();4 V- ?; A3 \) j$ p; L
tf2.setBounds(83, 60, 96, 21);
0 }* t$ K. |' q$ N" q c" s frame.getContentPane().add(tf2);4 J8 L9 o7 Y4 @$ `! q- Z
tf2.setColumns(10);
4 r3 ?. w7 n$ ^$ s5 _4 j. j
$ R, U6 g5 v# u6 Z tf3 = new JTextField();
) m* P# }, T0 ~ tf3.setBounds(83, 99, 96, 21);
' [/ C! E" S) M6 e+ O' C frame.getContentPane().add(tf3);
( g$ h! s! i$ z- B4 R( A0 N8 [ tf3.setColumns(10);
- u s J. u4 U# G5 P- O8 Y 7 _* _. U& q1 ~
tf4 = new JTextField();
) u* y1 R' ]! E" Z tf4.setBounds(83, 138, 96, 21);
9 F1 x, O' m a5 U frame.getContentPane().add(tf4);/ p0 r) q/ N% |+ ~
tf4.setColumns(10);: u1 j4 d! ~& ?" I# ]
: n# @( ~/ q: N3 x% b6 U. V2 Y
tf5 = new JTextField();
6 v' [# ]: |/ m1 `2 ] tf5.setBounds(83, 177, 96, 21);7 D2 K) [" T, I+ ~7 U# \
frame.getContentPane().add(tf5);1 V4 R2 G8 k* t/ g
tf5.setColumns(10);
. J& E" B9 c" C `% t% \
# U2 F4 p- D: w5 W b answer = new JTextField();
! w. V. P. O7 v3 x( F( Q$ h answer.addKeyListener(new KeyAdapter() {! u. p7 m! _$ z. e
@Override
0 N" y/ g% [) `6 T8 z- t5 a0 k0 [ public void keyReleased(KeyEvent e) {
3 L8 m9 y9 ?& W6 e% }7 ` System.out.println(answer.getText());! ]5 ^% O% ?& a7 ^1 d. s
) a+ t9 X) B) P( O! J8 e0 L
try{
' s' B6 [" V% ]- O$ _. P H% }. }9 ? double num = Double.parseDouble(answer.getText());
/ {9 Q F6 [0 _; @ % k2 y. Q# L2 h1 D5 ]& y5 ?
( D* ]9 I6 q9 ~, u9 `. t tf1.setText( String.valueOf(num * 0.029) );
( W4 W6 @ Y! ^6 p9 y tf2.setText( String.valueOf(num * 33.53) );/ j H/ H" T9 A* [5 ]
tf3.setText( String.valueOf(num * 0.22) );
! w1 E& K7 A% L4 _3 H# D tf4.setText( String.valueOf(num * 0.018) );$ F: F: C% Q% M/ S5 [" D9 Y
tf5.setText( String.valueOf(num * 0.03) );
1 }6 ^! B# C, ?; X }catch(Exception ex)
$ l% ?! @$ M6 ~+ v# n: ] {; d* f6 i3 L! d
tf1.setText( "請勿輸入非數字的字元" );2 u7 @: z# k; Z/ c9 u/ V" R
tf2.setText( "請勿輸入非數字的字元" );5 f8 J, s& I: u3 j
tf3.setText( "請勿輸入非數字的字元");" r- ^4 f$ k7 V& c/ V
tf4.setText( "請勿輸入非數字的字元" );7 F9 A" g7 u$ c9 ?. V' |
tf5.setText( "請勿輸入非數字的字元" );
) s% a# O+ g3 g }
* l8 ~" I- A5 k5 l* z Z0 m4 q4 i3 D5 q4 o% D
}
4 y7 V: r4 u) Q# ?$ S });8 I8 U, k% D2 X! d6 q ?( n
5 Y3 C o* r0 V/ X Y/ d5 A4 D answer.setBounds(20, 224, 159, 21);
+ `& @0 b, r: U* J% Q- _ frame.getContentPane().add(answer);
@# j( q8 D, j9 [7 { Q6 e9 A, b answer.setColumns(10);
4 F7 F6 Q t6 N5 m4 q$ B/ T o }2 _, C$ |4 O- Z/ C( p3 Z _( h
} |