import java.awt.EventQueue;) n( A& _( x$ a0 y+ e9 q
' q& g# I! x; u e& F3 ^- h
3 R# }+ ^/ |5 m$ J. F
public class TQC301 {! f' h W0 C y1 `! `& w
/ R' _& F6 c, u private JFrame frame;0 \. b( S% h3 F; l6 m
private JTextField tf1;; x8 F0 m9 L! y6 e! d
private JTextField tf2;) X5 z. T& @4 R+ f* F( I, o$ E6 ?
private JTextField tf3;( c' `0 I" {* K/ \; b2 v
private JTextField tf4;
+ V' V# u5 T5 V. M) I private JTextField tf5;6 [! \5 @; R2 R4 n" v( p
private JTextField answer;/ P, @$ E- l& F) K
; m6 ]( r ?4 B- w7 `( C7 ^! x
/**/ r9 l% V0 t5 t+ @
* Launch the application.
1 F4 c. P; r* K8 J- q) F) Y! K */( R/ H1 L9 T. ?$ j- R; g
public static void main(String[] args) {) }. l' |3 d* k m5 Q
EventQueue.invokeLater(new Runnable() {
: D$ A/ b- F3 P9 D8 ~& K public void run() {
4 T1 z1 J* s' L& @' z" Z6 x( C4 ] try {3 ?3 {' X- ^4 C1 u! I
TQC301 window = new TQC301();
& Z$ @. |1 o- c& X) W, k window.frame.setVisible(true);% t5 U4 U' d4 L' w" r
} catch (Exception e) {
6 y9 A1 q- T2 v4 R- ^! ?. i) p e.printStackTrace();
. V* o/ Z2 l* U' q }* p# M1 x; O% ^( q; ^2 I- z) ]
}. k0 a4 s8 |7 z* ~$ i, e
});
6 y$ \8 V- ^( V: d" y6 Q1 ^ }1 n9 L, A3 ?1 B* j
4 O, M% _' T9 { /**$ D X# J9 w0 O) B& ?, e
* Create the application. j* o3 n9 G: I2 \; }! P3 a
*/* c" l7 d2 ^+ k7 L2 I
public TQC301() {
0 B6 t( O$ f3 A initialize();/ n1 J- I( v8 c8 x8 h
}
' ^( q/ v5 M# T! l8 {& t. ?% b% R. @
/**
$ C, i5 x) ^# m+ p1 W! |( m * Initialize the contents of the frame.
: }1 U! h4 J; e6 P. K5 Y9 V */
0 d4 \) i1 X" T0 B+ Y; R) m private void initialize() {+ @/ K) J) y. d, e
frame = new JFrame();
7 M/ \* k/ S# b: u frame.setBounds(100, 100, 450, 300);. ]& F* g# S* P5 z, D' s
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
5 O" {6 g$ A s* b0 g7 v frame.getContentPane().setLayout(null);* r' a- X! I7 D3 u- [# d0 J+ N, D
, K3 X% N5 a! G U" G |
JLabel jl1 = new JLabel("\u7F8E\u91D1\u73FE\u503C");
! U( |$ K3 m+ T# o jl1.setForeground(Color.BLACK);( y" }, _9 d$ b: o% X/ }- z+ I
jl1.setBounds(20, 27, 60, 15);
" b& y6 m. P. T7 \$ c frame.getContentPane().add(jl1);
. n2 h/ ~& k7 }6 e- w; {( p. a
* U7 p/ ~" `3 k. Y JLabel jl2 = new JLabel("\u65E5\u5713\u73FE\u503C");
! E% H& K# M. F3 e6 T( {8 l3 w4 K jl2.setBounds(20, 63, 53, 15);
8 F- P" z* f+ H2 [5 M( f# h) ^ frame.getContentPane().add(jl2);& B$ G2 }: I* c
% B( V. e5 b8 ]8 {9 @# z6 g
tf1 = new JTextField();, K/ t( p2 t; P( L/ _
tf1.setBounds(83, 24, 96, 21);9 T- J0 V6 X% e% w
frame.getContentPane().add(tf1);, p3 t: L p$ b) s Q! r: ^8 l; {
tf1.setColumns(10);
5 Y5 Q$ X9 }- S9 L% A , Y+ V, ^1 M$ a3 e: b" V2 x4 i d
JLabel jl3 = new JLabel("\u6E2F\u5E63\u73FE\u503C");+ c9 U& L& ]" `' Z
jl3.setBounds(20, 102, 53, 15);
" y- Q0 h4 `) h$ x frame.getContentPane().add(jl3);
1 Q3 R! k3 u2 b0 {+ I7 L " s+ t5 F; n5 U U8 `
JLabel jl4 = new JLabel("\u82F1\u938A\u73FE\u503C");
0 W1 N W- q# ^ O; x jl4.setBounds(20, 141, 60, 15);
! Y+ ~1 g, b- f% o1 z frame.getContentPane().add(jl4);
: u8 @+ }2 w; T9 H# O8 n
. V; f @* ~# c9 ^& z JLabel jl5 = new JLabel("\u6B50\u5143\u73FE\u503C");* E( g" E* k; N9 o$ _* P
jl5.setBounds(20, 180, 60, 15);* m6 \, q* f# `6 l
frame.getContentPane().add(jl5);1 j/ b) d" k9 o- x" q6 O3 ^
1 D' Y' l. ~7 [$ i% T* L$ i tf2 = new JTextField();
9 u, w! \6 ?5 v* f) K tf2.setBounds(83, 60, 96, 21);
8 E. L8 c' z2 w$ i frame.getContentPane().add(tf2);
* T: F) {) i. G' d tf2.setColumns(10);
l! \# k) w5 Q$ U, S3 U $ S1 T" V3 S3 ]: l
tf3 = new JTextField();" w( z2 e) y2 Y' _ |3 k0 u8 }: L
tf3.setBounds(83, 99, 96, 21);
7 `0 v( T% m1 T7 w4 ` frame.getContentPane().add(tf3);
) ]( A3 k2 Z/ |% K8 M- S4 \ tf3.setColumns(10);$ y* n; _) c/ |% U
2 L4 T# U7 i8 N1 m' E E! `& ]/ }: ?) Q
tf4 = new JTextField();
/ X+ W* x7 T& S8 ~' T6 | tf4.setBounds(83, 138, 96, 21);
; i X# h; }( I. L frame.getContentPane().add(tf4);
4 S1 O9 x* c1 I9 I3 A( |& j6 S1 _ tf4.setColumns(10);# [1 B3 D. \3 P9 {/ J
3 S# l: w4 v: x1 h5 d
tf5 = new JTextField();
% o7 `! b/ V* N4 ?* U) R; t1 Y tf5.setBounds(83, 177, 96, 21);
" A k3 E: u/ d4 b( {2 V frame.getContentPane().add(tf5);
# q! f. r# q# _# g tf5.setColumns(10);
" S3 e1 r) R. b9 ?) \
$ n4 D# R/ {1 U. n; N answer = new JTextField();' H" Y ^7 x& X ^; y
answer.addKeyListener(new KeyAdapter() {; | ^, d8 ?7 L# C* i+ v5 K
@Override
. M# q6 o2 q! ^* _0 o& g S public void keyReleased(KeyEvent e) {
1 U% F4 }% {4 T8 t1 c System.out.println(answer.getText());
U: {- |& j/ K; Y2 Z3 u- D
) N1 h) b% |1 B) H4 ~8 O1 o try{
2 q1 v' W5 s! T( p+ m; I& @5 X double num = Double.parseDouble(answer.getText());
2 r# ~* O4 y H# M0 p - [: P9 Q1 S2 \6 P5 T, ]
3 u# j2 Z2 e( @! }: F. \. f1 n
tf1.setText( String.valueOf(num * 0.029) );% W0 |& p1 n' @2 ^( F4 Y/ K2 q
tf2.setText( String.valueOf(num * 33.53) );) e: Q# ^+ {& g5 N+ r
tf3.setText( String.valueOf(num * 0.22) );( {2 ^" u0 n2 d' h4 }* @6 e# y0 W
tf4.setText( String.valueOf(num * 0.018) );4 | W5 o5 ~% i+ p, `+ O, @
tf5.setText( String.valueOf(num * 0.03) );. J, b, V0 b- J, L) R
}catch(Exception ex)
7 U( N4 c% k7 X, Y ~ {* P0 W" _8 P/ w) m- E+ P0 {1 n' k
tf1.setText( "請勿輸入非數字的字元" );
$ ~4 y. C M' @- k tf2.setText( "請勿輸入非數字的字元" );
& j: h# G+ h9 @ {5 k tf3.setText( "請勿輸入非數字的字元");4 e, `) }1 |5 T1 x0 i
tf4.setText( "請勿輸入非數字的字元" );
4 a" ^8 z) P8 Q$ H- ?/ t! n2 r tf5.setText( "請勿輸入非數字的字元" );5 p5 _5 j1 S8 r! O, a
}
8 l1 r& S# X4 S( h' d. @3 l
1 n2 |7 \/ A* c/ k9 y1 Y }
$ ~( @8 Z6 c2 Z- X; ? });
9 O; ~8 y4 n2 t, A3 l( S$ G
5 ^. T# a5 h1 K( [# j" b answer.setBounds(20, 224, 159, 21);
' j# l+ R+ j( n frame.getContentPane().add(answer);
1 T9 G) \2 m' L6 N" I9 c answer.setColumns(10);/ ^* S' e% p* i, d/ r
}! a0 H) k& q8 [ b6 Z
} |