import java.awt.EventQueue;
- B9 t2 K, f, f. Q; W$ N) O0 l5 x' o/ [ J. d. V8 P
, [# ]: Z) S2 n) `- A8 J `" P' _
public class TQC301 {
, K, o( t/ T4 `4 J1 C+ g/ @% a: L& k7 ?" s- i' |
private JFrame frame;8 O$ s& x8 V# e6 H6 \' z
private JTextField tf1;7 C+ ~/ z6 @: I' ^* R7 G G
private JTextField tf2;
& M% O3 f- |: ?1 H8 T- K; q private JTextField tf3;1 e+ t- n& W( Z& n0 A
private JTextField tf4;& d0 X( n1 G8 _6 T& ?) P+ d
private JTextField tf5;6 J4 V; b- D; ]- a) U' G! Q
private JTextField answer;
/ y" {2 F d1 d1 K) \% [% F) S0 t7 b' M
/**' Z4 R5 b8 {" q7 I8 y
* Launch the application.
7 e [; b( H* w: B$ b */# a6 Z& T& |) }- {& p! I
public static void main(String[] args) {
7 F6 y8 ?+ s& x( W5 T9 n EventQueue.invokeLater(new Runnable() {
+ a* D' r9 F) r5 p public void run() {
6 @* u7 d. l5 m9 M! D try {; H- I' P3 k0 V& t' V( s e
TQC301 window = new TQC301();% P5 j n2 j) Y' T
window.frame.setVisible(true);
0 ^+ u9 W- ^4 ? _: ~* }( i } catch (Exception e) {* I* q. W1 u5 H. q5 p0 X
e.printStackTrace();0 T( {9 Z/ E9 G" @* j w8 I
}# K2 H8 A& f# A9 p3 J9 d
}
- }" R/ I" [' y' ]8 u }); O5 ~+ Q5 p# ~0 y: r$ p; E
}
/ O$ |8 d: t+ a$ x) y
h3 Z$ y( N/ W. D( l8 n0 U+ c) G' b /**
1 V$ a# X8 z! h3 ` * Create the application.
1 r q: S4 }! l: _# M */8 L& S+ \- X. h2 \5 i3 |
public TQC301() {
. R5 T* F2 Y. U+ s initialize(); [* E# S) ~* _. p8 y3 ^$ F. E
}! n. s( Z0 o$ ~, y
( l7 S" ^. }! ~& a /**- l4 Q9 k1 o* h1 H$ m9 s6 I
* Initialize the contents of the frame.0 b) V9 l! h! o% R! y% @
*/0 i" [* `: o9 w) f4 L& Y
private void initialize() { K! E7 x$ C4 {* j% t' y
frame = new JFrame();
" Z2 w9 {2 l, Y: |5 R R7 p frame.setBounds(100, 100, 450, 300);
1 |# X7 e4 [1 i! @# D frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- h$ P3 w6 e# g2 y, I9 v- e frame.getContentPane().setLayout(null);
$ o# @4 H; ?5 D8 f4 d
( l' z& @3 Y& y. P$ M/ A JLabel jl1 = new JLabel("\u7F8E\u91D1\u73FE\u503C");( @8 ^; A2 c1 g' [6 h, z) @7 @
jl1.setForeground(Color.BLACK);' j) ?2 z. j' l) e6 c7 {% ~
jl1.setBounds(20, 27, 60, 15);
5 E! j9 e+ f& W' g8 o frame.getContentPane().add(jl1);
0 p6 r6 \. m$ f% r. F3 y j 2 D! ?) I) C' u. B0 R- B
JLabel jl2 = new JLabel("\u65E5\u5713\u73FE\u503C");; E# i$ D% R% X$ w4 ?
jl2.setBounds(20, 63, 53, 15);- M* Z7 E! H6 a/ C% v
frame.getContentPane().add(jl2);
/ R V5 [. x2 t6 J0 n d4 B $ y( y! |& S& M4 [* r n
tf1 = new JTextField();
% b& D) P2 T" W. q tf1.setBounds(83, 24, 96, 21);
: M; o. t6 |9 Z frame.getContentPane().add(tf1);/ V! b/ D& o H4 v: |
tf1.setColumns(10);* S h. H5 G# l3 `7 @( ^2 B9 O8 D
6 O5 s( Z( X: x5 i
JLabel jl3 = new JLabel("\u6E2F\u5E63\u73FE\u503C");1 ?7 I2 f- m6 g' ]3 D
jl3.setBounds(20, 102, 53, 15);
( V, T2 Y# e" a5 H: e; L* h0 ~ frame.getContentPane().add(jl3);' ]) V ?1 |7 N x1 q* h: |
M- t. |1 v8 T: [$ F' Q {3 S. G
JLabel jl4 = new JLabel("\u82F1\u938A\u73FE\u503C");
: a( P! [2 ]. X( m4 ^ jl4.setBounds(20, 141, 60, 15);% T4 v* O e. {: B! A) x( E
frame.getContentPane().add(jl4);
& x, Z2 e+ r* F' ?1 J
6 C4 e6 [: W9 P6 ]$ Z/ `5 i- X JLabel jl5 = new JLabel("\u6B50\u5143\u73FE\u503C");5 w( L' ^. @* H
jl5.setBounds(20, 180, 60, 15);7 H1 M6 O$ d- E3 o$ N! A3 X! B9 ^
frame.getContentPane().add(jl5);, g% `( I T |9 }7 j( t/ ~
& I# `' V p3 V0 L5 e) v6 ` tf2 = new JTextField();% P: e7 n" Q5 }6 K
tf2.setBounds(83, 60, 96, 21);' d8 R4 L1 R0 T2 O; D
frame.getContentPane().add(tf2);
" {6 p; I% t5 Z) r0 F( x) f tf2.setColumns(10);; X8 S3 R: a+ F& b/ Y4 R% M& ~
# W6 f; P* e1 p$ }8 k R
tf3 = new JTextField();/ t; n1 i+ ]2 k4 I7 Z t
tf3.setBounds(83, 99, 96, 21);
* J& T! O" E# Z frame.getContentPane().add(tf3);. F, J! E) J% |/ r; a
tf3.setColumns(10); u9 e! e: h8 Z* t; X3 U
" a: T! n/ ]" f3 t) i$ }# ^ tf4 = new JTextField();
6 ]2 y7 X: p1 _6 n tf4.setBounds(83, 138, 96, 21);) P, r9 d2 Z8 I$ H& n7 G
frame.getContentPane().add(tf4);
8 N& E2 b0 b& Y) b/ X @0 p tf4.setColumns(10);
j9 D; J7 V# a, E3 s* ^
4 U5 r* m$ S' h0 }. Q* \ tf5 = new JTextField();/ M; {" [3 J& q# d& x. I
tf5.setBounds(83, 177, 96, 21);& B4 Z* ^. y+ I' f
frame.getContentPane().add(tf5);
2 g W+ q r+ E( F9 \8 F tf5.setColumns(10);
! J& F8 d$ V0 c2 [& o , J' H( K( U8 j8 l" P7 ]9 k
answer = new JTextField();5 {# ^7 d( O- o
answer.addKeyListener(new KeyAdapter() {
% N; o; |9 c# q6 F5 _, j @Override8 `* A+ Y/ F) `. w
public void keyReleased(KeyEvent e) {
% ]2 l: |2 Y2 X9 K t* Y& s System.out.println(answer.getText());
/ Z! ~9 _, S1 @7 X
6 G" R T# `/ ]4 s* e8 N+ `8 X try{* a# z' ]" d/ v) V( {4 F1 A C+ |- i
double num = Double.parseDouble(answer.getText());3 n2 B l" K4 @! T, G6 ^6 T
$ [6 i$ I5 B$ N
& q: k. Y6 s. P" C5 t
tf1.setText( String.valueOf(num * 0.029) );9 K) H6 J) W& m
tf2.setText( String.valueOf(num * 33.53) );# q# E; [$ v3 E4 k2 d+ K# |6 g
tf3.setText( String.valueOf(num * 0.22) );
) [* ? ]. ]+ c3 v# x* U+ Z tf4.setText( String.valueOf(num * 0.018) );
! L& p" z P( N7 ^1 u tf5.setText( String.valueOf(num * 0.03) );7 |+ Z3 d# u8 N3 O* Q6 }
}catch(Exception ex)
( `/ C: n( {6 n A* K& D {
+ T, ]9 @8 _) x4 U tf1.setText( "請勿輸入非數字的字元" );0 J) D. C( J( V- V: G
tf2.setText( "請勿輸入非數字的字元" );* [) [- O" r& U( T
tf3.setText( "請勿輸入非數字的字元");
% {: K( d" f6 h1 j4 R tf4.setText( "請勿輸入非數字的字元" );
) r: n% n& p) x7 t tf5.setText( "請勿輸入非數字的字元" );5 Q5 ~5 B; R. Q# i9 D- S
}' T. V+ A6 p' q5 D% s$ i
$ w# P' w! w( _; j }
: y3 s. [ Q* @& Z! i7 T* _& p });5 E" M7 @, o. [% M- W& \% {% k
6 j7 o+ }. P. k3 s
answer.setBounds(20, 224, 159, 21);
8 G9 c3 U4 c( o( I3 g) F frame.getContentPane().add(answer);
2 U1 @( l7 t9 S8 N5 d9 P answer.setColumns(10);
2 N$ p3 _3 t6 W$ d9 ~: a }; R4 w' Z& t0 i4 \
} |