import java.awt.EventQueue;7 k$ A0 A1 n! T% j3 f8 Q
2 L! e7 M9 E0 ^
( E) A' k. |" z" C0 f! h
public class TQC301 {
* P+ U( Z0 \6 u! o8 ^0 S
3 g$ Y* Z& }; y; A private JFrame frame;
# O4 ]& D3 e* t6 R9 c private JTextField tf1;
4 \2 s: Q. r3 n! @2 r private JTextField tf2;! m" j5 R# ?% N; p) w4 P2 Y I1 m
private JTextField tf3;" n# I2 N5 U* V, d: K8 m
private JTextField tf4;, `# Q; y- k" n* f: C/ s
private JTextField tf5;
1 S# T* j' Z( j! Y- M+ y5 Y0 g2 N private JTextField answer;! Y# }8 W' g2 O% ]
" |% k' X1 B) Z+ W% \
/**
- [. @. r1 C2 i1 ^; E* v) b/ { * Launch the application.
i0 J" `+ J! ^/ i7 h */
- O% \% J( N3 e( ? public static void main(String[] args) {4 S- a* o: a' [0 ^ A/ ~
EventQueue.invokeLater(new Runnable() {
/ R4 ]; q$ ?+ E. ?7 Q% Z public void run() {
* {7 H; v9 M7 x- {+ S9 ?; [ try {
2 J/ g6 C* w6 Q+ m9 U' q) g TQC301 window = new TQC301();
2 c1 J, ~' U& r9 W window.frame.setVisible(true);' L( A; Z4 _# o5 J! s
} catch (Exception e) { Z' }% F& v+ L9 O
e.printStackTrace();
5 @, E- y. O7 d+ O. E7 y9 {9 I+ E5 A }
" U+ \" d4 r, E; }. ^ o* A& u" { }
. f( |! X# |% y& v; C& W5 P! ` });
+ v" h8 U+ a8 v( _: G9 c }
! j/ _! x% l) t' p+ \3 n' f6 Z/ j% W1 k7 ^# E
/**
: M: \7 m; T) { * Create the application.
5 S/ p2 g- y& `& Z9 ~' J% }& V, L */9 I5 f8 x d2 H% Y9 y
public TQC301() {0 z" ]8 k8 W; v& Q! W
initialize();
1 N9 T; C$ v2 ~ W }
4 K: F+ _! \# l' g
% H( j3 \- V# u5 B$ U/ R! O+ p/ M. C /**
' O7 L! \3 }% R1 b * Initialize the contents of the frame.
; c! I2 B2 I X2 Y4 S* ^( | */& ^8 C$ O. j7 B2 ?( C6 b
private void initialize() {: @ h6 [ i$ D/ S2 r
frame = new JFrame();/ g4 ^( w. m% ~8 v- ?( q
frame.setBounds(100, 100, 450, 300);
! ?% Z" C- v: y q& G* M. q9 f frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); L; u) t& v. w/ g
frame.getContentPane().setLayout(null); {8 p' G2 [, A& \6 M! x* k
1 I0 B7 ~7 b' \" s JLabel jl1 = new JLabel("\u7F8E\u91D1\u73FE\u503C");; z, ~- C0 p, d+ B
jl1.setForeground(Color.BLACK);
- l0 \3 f, S# A' l% g jl1.setBounds(20, 27, 60, 15);
9 ?" K9 E# d: q2 F& m+ O- z" u0 D frame.getContentPane().add(jl1);
* W/ f) m* y( _3 ~. ^ ! r% g1 ~, e h h9 _7 r
JLabel jl2 = new JLabel("\u65E5\u5713\u73FE\u503C");
( ~7 O' A# @$ {3 ~$ @2 y: I jl2.setBounds(20, 63, 53, 15);) d: N& p* h5 x! x5 f7 E
frame.getContentPane().add(jl2);
r! D% K5 ^! b " h9 X, x7 P0 D* x* a/ W
tf1 = new JTextField();, w0 i2 Y/ n3 @
tf1.setBounds(83, 24, 96, 21);3 T* a A# D7 l' m3 @3 X' G
frame.getContentPane().add(tf1);
& d1 z/ r2 Z2 X) q9 O tf1.setColumns(10);
5 g+ g2 r3 V. _. a" G. N/ X3 s0 g
3 Q+ V+ r- P, O& l. I JLabel jl3 = new JLabel("\u6E2F\u5E63\u73FE\u503C");$ N" K, p: p0 S9 q* K/ J/ R9 @
jl3.setBounds(20, 102, 53, 15);
# Z* U- Z# ]1 P$ t frame.getContentPane().add(jl3);, e" @) Q9 y. {; h% }5 s9 R# N# j
7 V2 H& F3 Y3 n6 l
JLabel jl4 = new JLabel("\u82F1\u938A\u73FE\u503C");
& i) S; J5 U% T( `/ A- q, t jl4.setBounds(20, 141, 60, 15);
" ~. F% }7 G8 ~: o" J8 z; n4 H9 _3 a frame.getContentPane().add(jl4);
& Q5 e2 h' k" k: A# M
# ]3 Q) A" k7 b2 u8 w JLabel jl5 = new JLabel("\u6B50\u5143\u73FE\u503C");3 ~3 ^- k$ o8 ?5 h* _
jl5.setBounds(20, 180, 60, 15);$ i! ]% |+ b& E1 g+ R
frame.getContentPane().add(jl5);+ L- P) X, Q# ^/ F+ H+ J% ?3 l
8 ]$ Q ~" Y) r1 E9 | tf2 = new JTextField();
, f$ j% R5 `9 m# A tf2.setBounds(83, 60, 96, 21);
/ A3 i$ G* V6 C' j, Y3 s, f! w frame.getContentPane().add(tf2);5 r, o4 |0 z" x4 E& ?- \% D) x2 ~
tf2.setColumns(10);9 {$ D+ ]3 M; C/ b+ B' B
5 j E' H' r2 B2 a% F* `, i/ @- I
tf3 = new JTextField();% ?1 }6 G0 L( X$ C9 p1 s2 p& O. S
tf3.setBounds(83, 99, 96, 21);, A# T& S) N6 v' l" h) {
frame.getContentPane().add(tf3);
, \9 T9 U7 I0 ]6 U1 H6 a. H$ `2 _4 ` tf3.setColumns(10);
6 L. h+ f! R9 I; u; v& K6 T8 o( }
$ P# \0 E3 e! Z1 A0 x! r* ` tf4 = new JTextField();) J. T0 w& F8 k3 O; o3 ~
tf4.setBounds(83, 138, 96, 21);8 ~' F5 D3 x3 G8 g2 Z8 @' O
frame.getContentPane().add(tf4);
! G V$ I1 J' F! U, X- R% t ?1 f tf4.setColumns(10);
5 ?& i' t' g# F" A3 W9 M; m: x * N' y2 A3 J- o1 o3 U/ ~' h
tf5 = new JTextField();
5 F. N! [2 V4 a N0 K tf5.setBounds(83, 177, 96, 21);
. | H" n' T& t frame.getContentPane().add(tf5);8 H, T6 @1 m! ?6 N% x0 R
tf5.setColumns(10);
6 T `# w, h. q3 u# y- Q* c c2 f; [' @% B3 n
answer = new JTextField();1 U* |! ?; k5 @9 J' {6 K
answer.addKeyListener(new KeyAdapter() {1 u, p: O6 @# @! `/ n
@Override
( q6 w" }0 S; v8 c3 u2 h, M public void keyReleased(KeyEvent e) {
6 d% w- P/ F: y) V System.out.println(answer.getText());
6 S2 c: h2 M- j) _
; x" N, v$ m/ z0 S& Q0 n; }) q try{/ B. u1 Q+ N0 g# s: L- n M
double num = Double.parseDouble(answer.getText());
7 b& \7 ~5 q$ L# M5 H1 m7 E) c
7 S9 z7 s' y' a$ R 0 x3 r5 E4 n. J: E' Z
tf1.setText( String.valueOf(num * 0.029) );
2 x* \- ~% [* c l+ ], I8 f tf2.setText( String.valueOf(num * 33.53) );, ~% E( ~, D7 q P$ L
tf3.setText( String.valueOf(num * 0.22) );- K, [8 i& q& H1 l% E8 |, M* q
tf4.setText( String.valueOf(num * 0.018) );
: H {; ^5 J# G' c+ ?; ` tf5.setText( String.valueOf(num * 0.03) );
1 v$ E/ O# H5 g/ z }catch(Exception ex)8 U* W2 e/ c$ C( n3 c% A' B
{
`) m2 v V! b( z6 X: Y' Y tf1.setText( "請勿輸入非數字的字元" );
% Q( j5 ^" M2 F. W3 j tf2.setText( "請勿輸入非數字的字元" );
7 h! X" k8 n* y$ u5 a" M# t+ T tf3.setText( "請勿輸入非數字的字元");# B( P% Y! w1 q! U& b
tf4.setText( "請勿輸入非數字的字元" );, z9 d8 _4 ~- M! g3 k: z8 t7 Z* H
tf5.setText( "請勿輸入非數字的字元" );
% E. J- M3 P: {- f }
( F, v/ E- I6 V0 E6 R' }! P
/ N# Q. e; \' ]9 c; W8 } }5 P |5 d" v7 K) N
});! b$ u! Q0 ^6 m! }9 d* b
% R g* ^" m) k( x answer.setBounds(20, 224, 159, 21);5 z8 p$ z- ]+ W2 N0 b
frame.getContentPane().add(answer);
; X3 t* R, d7 a1 f K$ x! t answer.setColumns(10);
# V }! a) V7 S5 c0 X: ^ }5 u' \7 I7 l5 Y" W0 c8 [
} |