import java.awt.EventQueue;) E, x: Y% F" `- I4 y6 D; V {0 ?
' `9 E' h% T! w0 I: J
. t6 l# X8 r6 }; a! \3 v) U
public class TQC301 {3 a0 ^. L! ]9 `' }
- }3 w a( S: } v5 l1 p private JFrame frame;. F, G# o1 M3 a
private JTextField tf1;
- V. J0 e( V7 f private JTextField tf2;
0 A0 x) Q" }" n, p x private JTextField tf3;0 C; x* N- m- j7 a6 `9 r; r
private JTextField tf4;! [5 Q/ F3 o- {. w3 m6 Q2 r
private JTextField tf5;
7 b K5 j& B+ @* F, b* X private JTextField answer;5 `) t$ d v; G% Z9 t" ]+ N
" p0 y' G; u+ R1 f
/**
1 {1 g3 @5 o- a! O * Launch the application.7 g, K6 e: ]/ V5 H6 s8 I( \& v0 B# u
*/
6 @# m, B( ^5 }+ n, I6 I( r public static void main(String[] args) {
0 U7 d/ i6 I* ~1 a5 u4 Q# f EventQueue.invokeLater(new Runnable() {
6 K/ h1 Z/ |9 n- { public void run() {3 Q: H6 F3 b/ i" K A; ^
try {
, n: r. D8 t5 X2 h( a. m/ a TQC301 window = new TQC301();5 }! B/ ^ Y! I4 ~5 V% V2 G* G( v
window.frame.setVisible(true);7 ^; y- H( C3 q. I# b Q7 Z
} catch (Exception e) {+ O' N! L1 Y2 l3 y/ e& [. H
e.printStackTrace();
1 {+ U' y6 w7 e7 I5 @ }
1 u& |9 X' f: G7 @ }( I, G. v+ Q5 v C1 {
});7 J0 C- d+ w' w7 p
}+ V' B% F; j" ^
: \/ y+ j7 k; ~8 e /**6 K$ ^- j Q! w% d; D Z
* Create the application.0 c% d0 x( }1 F( ^" u8 Q" X! x9 L, o0 w
*/
9 J6 Z1 Z4 W+ \& r3 [ public TQC301() {
* l7 L4 F4 Y; q7 ~- @ initialize();
$ C+ l6 H8 G: p- @5 N: ~ }
9 G, k6 e/ X, J7 a2 C8 w; A1 C: t" G* h! o- I2 u
/**" y) s5 K; F9 @$ b- B- a# u
* Initialize the contents of the frame.: Z8 k' j6 `( C9 A3 O+ a9 Q% l
*/
9 ]) t8 M% B: m$ [2 v/ F private void initialize() {
6 z# l1 a4 ^' Q2 P& v7 E+ N frame = new JFrame();# t' F7 J8 W9 W/ r1 e
frame.setBounds(100, 100, 450, 300);; g6 q9 Y) k+ l
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);, s- t z! { v0 ^
frame.getContentPane().setLayout(null);
: S6 x; C3 P( g6 Y" v4 R1 e6 X ' c+ ?' z# Y) v, w. c2 k" G; g+ D
JLabel jl1 = new JLabel("\u7F8E\u91D1\u73FE\u503C");
5 Z2 Y4 z9 j% v# p jl1.setForeground(Color.BLACK);7 Y% g; G- T* `# l$ W, w
jl1.setBounds(20, 27, 60, 15);
! w/ g9 t$ \) ` frame.getContentPane().add(jl1);
. z5 \1 \* Y3 H9 F: J" t" b 2 h& b, Q% ^& Y% D7 t7 Y
JLabel jl2 = new JLabel("\u65E5\u5713\u73FE\u503C");2 i, ?; r% V! h U0 g
jl2.setBounds(20, 63, 53, 15);& s9 B- J+ b4 T! N
frame.getContentPane().add(jl2);
% X: r/ m/ r6 [ 2 Y: p) S: Q! Z4 j) J" h
tf1 = new JTextField();
% _+ }; d& a& D7 r- z1 P tf1.setBounds(83, 24, 96, 21);
- i& D8 w- G+ s0 J3 k frame.getContentPane().add(tf1);
6 [- b% N i& X$ d6 b5 X9 e6 _* x6 \ tf1.setColumns(10);# ~" F7 Z. ^ ?; H1 ?+ y+ w! X( t
' S1 B& z9 M( r, C JLabel jl3 = new JLabel("\u6E2F\u5E63\u73FE\u503C");
. ]4 j) {! n+ c9 Q jl3.setBounds(20, 102, 53, 15);0 K( J' S( M. [0 }
frame.getContentPane().add(jl3);, E7 }1 E6 e+ i. L' r$ }$ T
, u8 ^+ h! b5 k2 s. Z9 {# _: N
JLabel jl4 = new JLabel("\u82F1\u938A\u73FE\u503C");
4 Q+ V, ^" c+ h% H# k4 [ jl4.setBounds(20, 141, 60, 15);4 G, M5 ~# K$ f3 P& v7 r
frame.getContentPane().add(jl4);" @- U; o( ~9 @5 o- D- _" {" l
! Q* N- X* ~! S2 u- N; t0 P
JLabel jl5 = new JLabel("\u6B50\u5143\u73FE\u503C");
, M T) G7 M- x# E) O jl5.setBounds(20, 180, 60, 15);; I" R e; [7 U4 f2 h
frame.getContentPane().add(jl5);4 i+ | r% W0 \6 S2 g, M9 K& [
0 V% j. |- w2 {1 F tf2 = new JTextField();& u0 f( @; s7 {' [, ]! V2 O
tf2.setBounds(83, 60, 96, 21);) ^0 {3 I# ]4 [6 ]3 s
frame.getContentPane().add(tf2);
4 m/ w8 F4 i# ?8 G tf2.setColumns(10);
2 L, c7 D/ O8 i% N( S4 @ - ]& d, Z5 P6 T6 q& f
tf3 = new JTextField();
* }0 m5 _- H# W+ z7 ^ v tf3.setBounds(83, 99, 96, 21);
1 ~) ] ~9 c5 B+ K frame.getContentPane().add(tf3);! Q, Z) x! s2 \; x
tf3.setColumns(10);9 F3 a% f: x2 x3 `# ^! [$ Y9 C
6 z. X( m, r. d7 |4 x tf4 = new JTextField();! S) |- x3 f3 x- Y
tf4.setBounds(83, 138, 96, 21);8 G" j. e$ V* o, a
frame.getContentPane().add(tf4);$ |) O& ~1 U$ E
tf4.setColumns(10);& |1 u2 }3 e' O0 b! O* c- \5 K
/ G( T7 j# W0 [% m% S* [( F2 u tf5 = new JTextField();- e$ \2 u$ L. x. X) g8 I
tf5.setBounds(83, 177, 96, 21);* d/ N! K4 ^$ W; R. F7 Z
frame.getContentPane().add(tf5);
, e: q# E3 K, H4 G tf5.setColumns(10);
! ^1 i' c) c; _' E9 L 6 a" l5 u$ U' Q; W5 @ E
answer = new JTextField();# V. y; @' \2 @( v8 p5 B
answer.addKeyListener(new KeyAdapter() {
2 k- B$ g+ g) f2 Y, W @Override& ~/ r2 C/ _( ~* O; q# g( W
public void keyReleased(KeyEvent e) {
9 h" J3 K; ?: o$ G7 z8 q6 w6 D; g' \9 o4 U System.out.println(answer.getText());# Z% T5 e& ]. K+ r" q9 \0 K9 ?% d
; O, a2 e1 H6 F$ X% I% l& k# K- \7 _
try{4 b# F: x* O! T; x& n
double num = Double.parseDouble(answer.getText());$ J, W" G. {! y% I0 y9 T. ?! i
6 l2 d2 @ y2 U
! {6 |6 f3 o( m6 c0 V$ U# Y tf1.setText( String.valueOf(num * 0.029) );
) |) `+ @8 h! h! S E( K- i tf2.setText( String.valueOf(num * 33.53) );. j" @: g$ k) P6 ^1 j' T6 R2 `5 ^
tf3.setText( String.valueOf(num * 0.22) );
; }' @1 c- L1 p% a7 } tf4.setText( String.valueOf(num * 0.018) );& J8 M& [5 J0 S4 \2 {6 w
tf5.setText( String.valueOf(num * 0.03) );$ ^. x* Z7 l Z# z2 L
}catch(Exception ex)9 w6 J j' I7 G9 ]6 u0 |% g
{
1 z3 v" g4 F9 v( }: [+ K# S tf1.setText( "請勿輸入非數字的字元" );$ q+ p4 ?8 m( \/ ]' y" j \' q
tf2.setText( "請勿輸入非數字的字元" );# {" k9 b( E4 i. [
tf3.setText( "請勿輸入非數字的字元");
1 v1 m2 V, E1 Y4 j tf4.setText( "請勿輸入非數字的字元" );8 p. D0 s2 m. N5 X# u1 {4 i$ w
tf5.setText( "請勿輸入非數字的字元" ); @( @4 i- ?2 d9 | R' I$ i: d' O
}
& \: I" [ s; F
6 H& T8 ^% R$ [" t7 h }
; O8 r& [! u" F+ b/ v/ t });7 a0 Q) \5 K& Z @0 W
! m! G( E. Z: ]) C( P5 \/ k$ g answer.setBounds(20, 224, 159, 21);0 l$ W# I+ I( f: t
frame.getContentPane().add(answer);
- h; B8 B4 h$ j answer.setColumns(10);
8 |. Q4 \3 x4 Z/ p* j/ y }
+ x/ G I H6 h} |