import java.awt.EventQueue; [; w( W8 a5 u4 P
2 P, n: `% T& c
5 \; Q) d" C% f, B& {0 \
public class TQC301 {
. l; k( b: L4 l1 M3 r- H+ q: w S+ e# K
8 h$ [4 |+ W/ h private JFrame frame;, Z" a; W- Z! V- Y; T
private JTextField tf1;
. i: ?" v7 ~1 H* a1 b private JTextField tf2;
0 V6 r$ m; m7 K u4 G' L private JTextField tf3;. [3 P: y/ c$ m; k7 k
private JTextField tf4;
7 @. T+ F# T1 T# Z private JTextField tf5;* `4 o. f/ H8 Y$ x+ |
private JTextField answer;
5 @* B" V; z' A# N# F7 s+ j5 N4 x, U/ }
/** z) |, S4 K6 u- n
* Launch the application.# W+ I0 a; r% f0 O* n1 P$ V
*/! e# @ S, n7 U. V$ f( W
public static void main(String[] args) {
. I4 f) `% m, X4 S! s EventQueue.invokeLater(new Runnable() {
, h$ D2 b2 R0 @! r public void run() {. a2 E5 u2 a ]+ `) J* n
try {
8 {8 ?1 y! t) Q8 M TQC301 window = new TQC301();4 _2 p% V, L6 Y: ~5 \" H+ d( F
window.frame.setVisible(true);8 q5 _- i& z: z% Y5 L9 g
} catch (Exception e) {' R0 z8 u/ x& U
e.printStackTrace();+ l$ Y2 D# ` k' @& \# U9 w- }- D
}/ S4 ]. b# B$ f! Z* _
}
, {3 p( U/ l7 l });
# {6 X$ D+ g# I& z }4 i; u8 G: |6 t7 Z" m0 j
: R9 f1 G {" J: U& y3 e
/**0 R7 P/ w* Z v. k% I* ]
* Create the application.
$ ]9 p- w* W C1 f: E0 l, e5 H8 H */) u) v" o$ `9 y4 ?$ u
public TQC301() {8 p& q5 _( _) E3 C8 C& P" [
initialize();
, d$ q$ X$ L$ J A } _7 \+ R! |# u/ Z% S. F* X3 ?! C! h
, H" b6 c- W7 B* _, g o- x/ _ /*** }) f% U6 ~* g7 a
* Initialize the contents of the frame.) j/ m' m- ^' J
*/
* ~1 S/ ?9 c. K private void initialize() {
! I6 A1 K0 a1 |, \) n; S frame = new JFrame();
6 t8 A/ E( {2 T9 y' l5 L3 M# f4 c& O frame.setBounds(100, 100, 450, 300);
( t3 P6 D2 ]* _+ J5 C9 t$ O5 y frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
9 d' L/ Y. y8 ]0 J frame.getContentPane().setLayout(null);
/ F7 Q( F2 y1 t- U + e. M, c5 y) w
JLabel jl1 = new JLabel("\u7F8E\u91D1\u73FE\u503C");
: I) G6 N& t( ?1 x jl1.setForeground(Color.BLACK);% ]. X, X# ?6 Q. Q- N/ A. ]
jl1.setBounds(20, 27, 60, 15);
6 G& ^ }# ~! Z l; m& x5 s frame.getContentPane().add(jl1);/ D7 m; O; l1 W# a0 S8 p
( t- m* C' y0 s7 Q- ~' S
JLabel jl2 = new JLabel("\u65E5\u5713\u73FE\u503C");
, x; W; [0 L6 ~. {" }& M f jl2.setBounds(20, 63, 53, 15);
( Q! `! |3 X: S frame.getContentPane().add(jl2);* k7 q5 ?8 W# d8 Y7 O Y0 s
" W+ u! G2 [/ b3 ~ tf1 = new JTextField();: O# t3 w5 m1 M
tf1.setBounds(83, 24, 96, 21);
2 V5 U9 ?( b( n* @% A frame.getContentPane().add(tf1);
3 O( H% o4 U) i) ] tf1.setColumns(10);( c+ ^4 H* G5 b! V9 I$ Z9 J5 N
r$ J0 L, x9 F4 M3 l8 e$ C JLabel jl3 = new JLabel("\u6E2F\u5E63\u73FE\u503C"); f) C4 N. ^5 {( P
jl3.setBounds(20, 102, 53, 15);
5 p. B2 u. h6 T1 K3 A( a/ k6 Z+ v frame.getContentPane().add(jl3);
& u% r+ X8 l. f! `6 k
9 S- U, d+ N- B* X: N JLabel jl4 = new JLabel("\u82F1\u938A\u73FE\u503C");
& p0 a+ ], P, T+ A9 K5 w$ G' c: [: H jl4.setBounds(20, 141, 60, 15);6 v# G e/ h3 |9 N. }% i# l% Y
frame.getContentPane().add(jl4);
4 d& T, K$ N' } # e# w/ [/ [. B# q; o
JLabel jl5 = new JLabel("\u6B50\u5143\u73FE\u503C");( o6 n- u; q6 d: j, r1 d1 }2 e- P
jl5.setBounds(20, 180, 60, 15);+ W) j9 n4 c6 P: d2 R+ T
frame.getContentPane().add(jl5);) K8 c( l1 E: o, a, \/ j
8 }: a' f+ a. t5 Z% S tf2 = new JTextField();
) k: Y6 V5 m: m, e tf2.setBounds(83, 60, 96, 21);5 O$ k3 U. K/ E$ Q% M
frame.getContentPane().add(tf2);! K5 ^$ D5 t8 B' M" u! s. S) {9 n
tf2.setColumns(10);
/ L/ D3 q. W* V4 F: O) B' M/ ?& j- Q ; p8 j+ u; |) u/ T3 \# L$ U& A. p# i
tf3 = new JTextField();7 a! c3 J' T7 r
tf3.setBounds(83, 99, 96, 21);, j1 X+ n, K- {! k K
frame.getContentPane().add(tf3);8 v9 c6 L; r/ }+ C8 ?2 s
tf3.setColumns(10);7 T# P( o0 ?0 R8 D% t
( M& h- [ H8 o! _6 X
tf4 = new JTextField();
7 K! t) o1 n$ z4 }1 F tf4.setBounds(83, 138, 96, 21);
# a) }3 X. D, I2 N# Z9 `! ~0 g frame.getContentPane().add(tf4);. i" D# y7 {8 D) ]
tf4.setColumns(10);/ B1 |' s* @& y; m( Q# g9 t1 V2 o
- ~3 C C* G: L4 ]# G! [8 d tf5 = new JTextField();/ I4 H% Z$ z5 d; c
tf5.setBounds(83, 177, 96, 21);
! H- K2 y% d- p( m frame.getContentPane().add(tf5);( C6 j* @$ c' U6 L: W
tf5.setColumns(10);1 Q+ {2 }: ^/ E) U6 L# Y, ^3 b. G
7 {- V) w" ~3 R; T answer = new JTextField();
2 {& v/ N M# m) _* ^ answer.addKeyListener(new KeyAdapter() {' }& c/ C# `$ I9 O" H2 ^. l' X; |) z
@Override9 n- x' a$ y9 x
public void keyReleased(KeyEvent e) {6 h3 n7 |% i9 e% N3 ^/ M4 g- W$ B
System.out.println(answer.getText());
[: J# h' p: x, y 6 s) ?6 ?1 y! u9 l5 J/ V
try{
9 q B7 Q! E9 A, P, B9 o double num = Double.parseDouble(answer.getText());4 V9 C1 t, P8 i$ ~$ U
" G2 w3 U% J- `- E, H- L. N5 A
6 Z: d2 W4 x& W0 c) p6 z
tf1.setText( String.valueOf(num * 0.029) );
. S6 `& H0 G. V- ]7 V4 A; R tf2.setText( String.valueOf(num * 33.53) );# T0 c- z( ?& x9 l. Y9 @! D$ W
tf3.setText( String.valueOf(num * 0.22) );: _7 K, L5 W; }5 f
tf4.setText( String.valueOf(num * 0.018) );
$ g$ O4 O. `+ B" E2 `* ? tf5.setText( String.valueOf(num * 0.03) );
6 [) |3 P) S# h8 y+ e; Y }catch(Exception ex)% E: W+ Y0 L; b2 V8 E+ ^
{
' L6 U. G$ F# B" n0 }6 z1 G tf1.setText( "請勿輸入非數字的字元" );& w0 n9 s! G4 d2 g6 {7 _. G3 ]
tf2.setText( "請勿輸入非數字的字元" );
6 c* T3 w+ e. j9 p tf3.setText( "請勿輸入非數字的字元");! l# V: E& \! k: h. E
tf4.setText( "請勿輸入非數字的字元" );
2 q9 l" C; h- k8 s* r tf5.setText( "請勿輸入非數字的字元" );
7 t. F, b6 I. x }6 c$ }2 V2 q$ j2 a( `2 L
( X- V2 y: Q1 N5 N% i }3 \/ [' O; H$ w3 {# l
});
+ I7 j; h! F3 `9 n1 E7 s* \
2 ~+ H8 I4 d! v( Z7 F answer.setBounds(20, 224, 159, 21);
- {% \* I/ M# Y: {/ i( N frame.getContentPane().add(answer);
, _8 x" B d3 Y) [* x9 f/ c- V answer.setColumns(10);
9 j- y7 J6 d) d8 ] }
7 R, _' b4 ?5 T/ R3 j5 n0 V} |