import java.awt.EventQueue;+ W5 m$ n1 B5 s U3 r) ?, F+ @$ F6 W- a
+ `3 y( k4 s, ~4 G$ u* X1 T, L2 B, ?( {
public class TQC301 {) y5 {5 y6 Q1 x O' _4 u
4 P7 @2 t& x. o: u2 \4 L- c; f private JFrame frame;0 f- h* q, Z5 k. v9 Q2 K% U4 s
private JTextField tf1;7 r( e+ Z- _- ~1 t/ Y. ^/ N2 Z
private JTextField tf2;; Q' T( I- X: W; H1 o" E
private JTextField tf3;% u; d, y' L8 i. _
private JTextField tf4;
$ j. ~4 d4 `- l5 H0 L9 K private JTextField tf5;% f+ N! I; D' w# {- O4 V6 B, L" l
private JTextField answer;& _% n- I W) o& Z- K$ p
8 _! A1 F$ L u$ F) e$ N, O
/**$ x) @) f" }$ i3 v! L! l5 G
* Launch the application.& P% h& x5 q7 O2 g# S$ K
*/
' C' B+ v5 L7 u" M$ T* ] C+ X public static void main(String[] args) {* Q. f7 d$ P' K, D
EventQueue.invokeLater(new Runnable() {
# i( V$ W0 \, M" ?, s( e$ y public void run() {
, Q1 q! ?% w' E try {
2 V2 }. W% t, V& q, h% V TQC301 window = new TQC301();
0 O4 t/ {1 G7 {; Y) Q window.frame.setVisible(true);
1 i6 P, Q& P5 Q0 t Z1 ] } catch (Exception e) {# Q W2 m7 \) G8 w0 h( Q5 C
e.printStackTrace();
& r& ^) L% e/ C3 i% j$ q5 g }3 T+ Y( e0 a; U8 \' a
}
* \# V! Z6 U2 J x4 l });8 K( Z* B, z4 k6 U# p. d
}
1 |4 i/ {# k9 z& L1 y3 K3 ]- v6 e8 t! v1 @/ q$ D
/**
0 B0 S% Z5 b7 o# w* L o * Create the application." U3 U; d+ w$ `: E- A4 m
*/2 f1 v! N/ i. p8 g2 d. B- m
public TQC301() {( e: R; K5 S! L9 i9 ]! A4 \
initialize();
) [) @+ M5 l( A& _+ r }
" f1 n4 D3 l- S2 Y
- n; r# g2 A. ~+ I7 n: X* G /**3 j T7 H F5 W3 [4 S4 b
* Initialize the contents of the frame.
4 r g4 O0 H; }9 j */% W/ a9 I/ a$ y* I6 V
private void initialize() {3 _ a" b: c2 c' `& _
frame = new JFrame();$ _4 o! ^5 S& E7 O: f7 ~: a
frame.setBounds(100, 100, 450, 300);' P: h( H# |% N; D$ j, G4 _$ Q3 a
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);7 H! A+ K7 d7 e9 I; c6 _
frame.getContentPane().setLayout(null);# r. n0 ^' s ?& j1 n9 O* O
* {/ ~5 r7 O6 h4 \
JLabel jl1 = new JLabel("\u7F8E\u91D1\u73FE\u503C");$ _. N( A7 `9 @* X$ I
jl1.setForeground(Color.BLACK);
" S5 X4 Q# h3 T* l# h# q jl1.setBounds(20, 27, 60, 15);. \! P; T+ u' _* B% s8 R
frame.getContentPane().add(jl1);: u8 v" X9 w2 Q C
+ O& \2 E, g; ?: i- {5 P JLabel jl2 = new JLabel("\u65E5\u5713\u73FE\u503C");) I$ E0 S- z% }. |/ j& Q
jl2.setBounds(20, 63, 53, 15);1 s9 H. G& y8 w) l9 t: ?1 c5 e
frame.getContentPane().add(jl2);3 U- b. I* G: V" O9 \: M
/ t9 @( B/ p! X* J7 X# C tf1 = new JTextField();$ r% D% h: t+ [! x& C7 }; Q/ J
tf1.setBounds(83, 24, 96, 21);$ N6 k3 @3 d( A8 _2 Q) V
frame.getContentPane().add(tf1);
% k Y3 W! Z! P2 d& Z) W3 I1 U$ J) ` tf1.setColumns(10);
8 [2 N7 m$ v. j
( T- J* W% _3 ^ r JLabel jl3 = new JLabel("\u6E2F\u5E63\u73FE\u503C");
; A8 k. i M4 D( p& }3 F. ~ jl3.setBounds(20, 102, 53, 15);
+ |& T% ~0 m2 |/ L7 j: b+ F. K! D frame.getContentPane().add(jl3);
4 A: X+ [: ^2 X) w" `& D' b7 j 6 t9 U4 p. ` I4 s) n' L7 g
JLabel jl4 = new JLabel("\u82F1\u938A\u73FE\u503C");# y' \9 H: J" c7 s8 Q
jl4.setBounds(20, 141, 60, 15);
5 L. y+ ~" V! t( B% A# Q+ C2 Y2 y4 I' q, U frame.getContentPane().add(jl4);
3 L! c# b2 |. c# m. Y" S
8 U2 y# n/ [6 m- g! ^5 o JLabel jl5 = new JLabel("\u6B50\u5143\u73FE\u503C");% N. p7 M' U, s# G2 C
jl5.setBounds(20, 180, 60, 15);
: Y$ k5 g& }: t# w" B frame.getContentPane().add(jl5);
3 ^6 P; ]9 K v) t1 ` , \' {, U: }1 F f
tf2 = new JTextField();1 x9 }" p4 p# f$ Z4 a1 D( X
tf2.setBounds(83, 60, 96, 21);
0 M c: o5 M0 h/ S frame.getContentPane().add(tf2);
8 c3 r; a+ c2 W* f tf2.setColumns(10);
9 ?+ p d* d- X! ~ ! q v# L$ L3 C1 Y5 {# D
tf3 = new JTextField(); `8 J8 Z& e4 ~3 _4 C" A
tf3.setBounds(83, 99, 96, 21);
5 T* h. [- c7 i* U2 t6 }8 r4 Q) H frame.getContentPane().add(tf3);0 u/ ?7 A" G* e9 G2 j
tf3.setColumns(10);
* c0 W r: [0 p4 i' {5 K
2 P& Q* b0 T' F2 ]- Z tf4 = new JTextField();/ D8 C. ~% y9 b( B' E" s
tf4.setBounds(83, 138, 96, 21);
: M6 A* y! w* R( m+ }+ |: U$ R frame.getContentPane().add(tf4);0 _/ i& a! O4 a
tf4.setColumns(10);. z& |0 k0 F& f( T' a. @7 F+ s/ P
9 u+ m9 a [. ~+ x
tf5 = new JTextField();! H3 ~( l- N% l& \
tf5.setBounds(83, 177, 96, 21);
4 i- [4 v/ I6 j& g7 q frame.getContentPane().add(tf5);5 Y# e: G/ U9 R
tf5.setColumns(10);
. f1 r# h3 V5 d, z% u 5 a+ J+ y G3 _9 z5 |1 b+ {
answer = new JTextField();2 I$ Y, Z9 c' b9 o. |
answer.addKeyListener(new KeyAdapter() {
8 j* o# g l, m$ j s5 X, ] @Override
) N% n2 V/ N) ?( a" p public void keyReleased(KeyEvent e) {/ Q2 ^' X6 t, s+ u
System.out.println(answer.getText());" z7 @- F; ^1 l2 _3 y5 [
! k- h, w: ^ X; o try{
~ u* `. W, ` y, o9 [ double num = Double.parseDouble(answer.getText());( ?, p s5 ^) G3 g: w' q
" K( l5 E# c! \9 G- d K( K7 B
7 W4 f8 n4 a( l
tf1.setText( String.valueOf(num * 0.029) );
% d' b, N, \5 X. k% B# j, r3 _ tf2.setText( String.valueOf(num * 33.53) );
' z8 k# l0 q- x tf3.setText( String.valueOf(num * 0.22) );
6 I7 a: m/ G; r8 o* K2 O2 v8 t- I tf4.setText( String.valueOf(num * 0.018) );
' L8 s7 Z7 m! E1 b' D# x! g9 f4 s tf5.setText( String.valueOf(num * 0.03) );
; T. g& T+ b# Y% ^- A ?( P }catch(Exception ex)
g0 W2 Z% b0 O( {) J" E) |8 _2 f {" R1 f$ _0 ]: a/ b
tf1.setText( "請勿輸入非數字的字元" );
, v" `! x! N$ }7 t2 k tf2.setText( "請勿輸入非數字的字元" );
% D% ^+ T2 e' f% t; N# ]2 |3 D tf3.setText( "請勿輸入非數字的字元");2 y6 a9 e/ D. R0 {4 n* d
tf4.setText( "請勿輸入非數字的字元" );) U: m( V6 n* m
tf5.setText( "請勿輸入非數字的字元" );
# h, P" H1 N. ~) n }4 B' U* [- f) w/ z5 ~. h7 {7 w
: a# x: Z; Z% _7 s' X
}
1 U3 ]3 f9 s8 a7 J: E });
! k+ [: g6 Y# ^, t, C1 c, `* |. }; K
answer.setBounds(20, 224, 159, 21);, H8 q* g) c7 F( n5 S8 e
frame.getContentPane().add(answer);
9 h8 ^- M7 Q3 E* |" u: D7 z' q+ v answer.setColumns(10);" h j* X3 _/ G; m' M9 i7 t( F
}) Z' S1 H7 I0 j: ?3 G1 J) [, q
} |