import java.awt.EventQueue;
* [+ ?+ T& r0 P8 A2 K8 E. J" z& n" O9 {7 O* H+ Q' b! l: J% G
/ v. A+ |$ U6 M0 n: npublic class TQC301 {$ H: Q. ~& i% T% B: ]
% z& x6 I% y" g) K$ s
private JFrame frame;( ?. ~# S9 |4 |2 v. \1 I
private JTextField tf1;+ p! |8 Y* A4 A3 X8 R
private JTextField tf2;4 r9 ?' {7 n2 X2 n0 V. v4 z
private JTextField tf3;
3 W" _8 ~% a" t. g' A private JTextField tf4;
* D) m+ K2 L; m% t+ _1 | private JTextField tf5;
5 e+ D1 {0 w3 X7 B& q) h! p. \ private JTextField answer;
0 k8 U! Y1 g2 g3 Y+ E m! | W. ^& k8 ^$ s+ n# X4 Y2 X
/**: P7 Q5 W( C0 L2 ]% A* u# |7 n
* Launch the application.- f! Y% A; `6 D
*/! a0 E! X% W1 U! A
public static void main(String[] args) {9 v* c+ T7 C) Z/ Y* V: q C% ]+ Q! l
EventQueue.invokeLater(new Runnable() {$ F$ d. ?. E( j- g
public void run() {
7 V: U0 m1 m3 \8 p+ F try {+ W2 S6 z" v1 h; b$ ?! r
TQC301 window = new TQC301();
" K) w* b# Q# d2 C. K4 C* m2 z$ M window.frame.setVisible(true);/ L: A' N$ J" k$ d0 \% X9 U" Z1 T- }
} catch (Exception e) {* R8 v! e) S( P+ D/ m
e.printStackTrace();* G9 O4 I k7 p1 Z' _
}
1 V) j+ {% L' T z6 U; n' X }
* T8 c4 I' S Q });
3 Y5 s1 c! O6 B | }1 A2 t# d1 W) i; s7 G! ?
! Z/ m( E! ?& L4 J /**
- G- \3 H( `4 l; B. w; o * Create the application.* V& R/ L0 e' p
*/& c6 \$ r* y8 O/ E" w: p4 f
public TQC301() {
; F: o' H+ ]6 h- }- _! n# W initialize();. b5 t9 y) G4 X M: h; X
}( v2 h7 m8 d: G1 E
4 P+ }7 V+ D: `7 | /*** C+ N1 ~6 A) ~3 f6 s
* Initialize the contents of the frame.
4 L2 R6 H6 z: o- b- H) ^% L K */
3 \0 s; j6 h2 A8 l: i0 J private void initialize() {
1 o& _6 e* k$ R& @ frame = new JFrame();
1 B6 V: |9 U' [$ b& p frame.setBounds(100, 100, 450, 300);
- U) p- I# q9 M' D1 m- L frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);/ O, N) z4 w" N1 P
frame.getContentPane().setLayout(null);
h. D; o$ d3 M3 ^
1 R3 n# `7 E1 T$ g5 q JLabel jl1 = new JLabel("\u7F8E\u91D1\u73FE\u503C");- T# q5 A' o5 c
jl1.setForeground(Color.BLACK);, x: `, T# Z7 b. V" `0 r3 y
jl1.setBounds(20, 27, 60, 15);0 C c' o6 `$ S" U
frame.getContentPane().add(jl1);4 Y; H: {* J: _2 C
: o+ A7 Q8 m5 j R JLabel jl2 = new JLabel("\u65E5\u5713\u73FE\u503C");! O. n' O- x/ x- u& {
jl2.setBounds(20, 63, 53, 15);/ v5 h! B+ ?1 W& u1 A5 @
frame.getContentPane().add(jl2);! G6 q# `4 N$ c; n3 X
; v v& N& t7 {; d+ U; Z- I
tf1 = new JTextField();
V/ ^' z0 m3 B6 v# a tf1.setBounds(83, 24, 96, 21);
7 W! z9 T9 v1 h/ P7 P& ~7 X/ j frame.getContentPane().add(tf1);1 k, \( e8 k- Y+ H3 e
tf1.setColumns(10);- [* l5 {' Q% B: s1 p. }
" A- H8 W, r9 [# ]# H9 i JLabel jl3 = new JLabel("\u6E2F\u5E63\u73FE\u503C");
4 G% S. H9 H6 @: z r jl3.setBounds(20, 102, 53, 15);8 H0 t; r6 l) k4 g' [* J! f" p; A
frame.getContentPane().add(jl3);
' P" t- y& @5 T+ P/ h 9 v" G3 [ B2 Q1 c$ t6 j
JLabel jl4 = new JLabel("\u82F1\u938A\u73FE\u503C");9 \2 D8 L/ I: d( p# J
jl4.setBounds(20, 141, 60, 15);0 M+ a. B( ?1 }) g C
frame.getContentPane().add(jl4);- R# l5 f& I: S3 e% [
/ u% L+ p) {( p2 c$ f! `( A% R JLabel jl5 = new JLabel("\u6B50\u5143\u73FE\u503C");
( o. E$ ~; I9 Z6 Z2 x jl5.setBounds(20, 180, 60, 15);
# b: M- v: T; |/ T+ ] frame.getContentPane().add(jl5);
& T7 j$ v0 k. h* x {* X5 d, _1 x, o
5 C) I5 f0 L$ `9 S9 K8 e; w tf2 = new JTextField();, c* D. K+ q/ J+ [* j
tf2.setBounds(83, 60, 96, 21);
- F& {$ H& H: C3 v frame.getContentPane().add(tf2);2 Y* c/ R, L! D9 H2 s$ Q
tf2.setColumns(10);+ h4 D+ z4 }* D Z' P+ u3 L7 w
: [1 M S' u2 H. e; e$ s- q% N
tf3 = new JTextField();
@8 x _# b7 }5 _ tf3.setBounds(83, 99, 96, 21); B" W- L/ {/ ?- v6 |0 N
frame.getContentPane().add(tf3);
- [( y% E# N3 q4 m9 V tf3.setColumns(10);# a; V s: x/ [8 p l5 J% G
3 K! P$ \7 I- ]
tf4 = new JTextField();$ G0 d) w+ E! V" X) k; r
tf4.setBounds(83, 138, 96, 21);. T3 Z/ ]9 h/ @# g
frame.getContentPane().add(tf4);. g1 ~4 U# V2 T2 S2 K% [
tf4.setColumns(10);, ~1 H3 b7 }4 U4 ^9 y. `# Y
7 c5 Q" \$ d% E* A% Q
tf5 = new JTextField();- k0 A2 j8 I( }! f
tf5.setBounds(83, 177, 96, 21);
" q( F1 t% C* W( R$ f A$ g frame.getContentPane().add(tf5);4 L- ?' q8 o" m/ H3 `
tf5.setColumns(10);1 g' v) c9 ]4 z$ }# \& ^' T
' O* h, g9 H) S: ?5 r7 S
answer = new JTextField();
3 W$ ^) c5 F8 @0 ^; K; f answer.addKeyListener(new KeyAdapter() {
: M: p$ b) _0 g* z: ^ @Override
* d4 E) D P! H- G) I* H$ _' ~% i' i public void keyReleased(KeyEvent e) {6 y! [5 I% b5 _
System.out.println(answer.getText());/ p- m, {1 `6 N2 i( [
) [, `/ i) P2 W ~ B7 o; O# C try{
" ~: Y, ^; ^& N, |1 j: Y+ n; c double num = Double.parseDouble(answer.getText());2 @/ j" h. O6 A. T2 e
/ [* c% Q( r0 y$ {/ N6 h4 y
2 {5 d+ ~( v0 W7 H tf1.setText( String.valueOf(num * 0.029) );
. Z8 ~8 c5 u4 V' N tf2.setText( String.valueOf(num * 33.53) );
( m9 \; a0 a! ]2 { B9 H1 O" | tf3.setText( String.valueOf(num * 0.22) );
( N* Z+ z% y: j9 b tf4.setText( String.valueOf(num * 0.018) );
1 v3 Z$ q$ R6 u f tf5.setText( String.valueOf(num * 0.03) );) f- S0 H' s; Z
}catch(Exception ex)
H" A) b S2 A8 k {+ G7 j# l/ t) C2 `4 S% }$ b- ?
tf1.setText( "請勿輸入非數字的字元" );0 S" u8 Z1 A- I& }8 ]+ Z
tf2.setText( "請勿輸入非數字的字元" );3 y3 p: p$ ~5 q
tf3.setText( "請勿輸入非數字的字元");
9 ?+ \: k& Q8 X2 v9 ? tf4.setText( "請勿輸入非數字的字元" );
) ^, Y2 [; \& A& t tf5.setText( "請勿輸入非數字的字元" );
" }. L; N8 L% e- Z9 V5 ?3 H. [ }, c; ^5 `5 q( R' u, z; C
0 O( z* }3 t2 v/ E' U% v }7 X' X) G0 s6 l4 c2 F
});- _, b9 E+ X( T, h9 {* c# Z
" D3 H }0 a& ~' U. K8 M2 i
answer.setBounds(20, 224, 159, 21);
# T: Y) ]) Y4 _ frame.getContentPane().add(answer);, ^* c" u& ?, O+ t0 N* |! \) [6 A
answer.setColumns(10);
, b# q* `# Q; z, x0 j6 @4 ? }
3 T) ^' D0 C+ B: k9 V4 d0 h; t9 L} |