import java.awt.EventQueue;5 B# f+ A. e8 S m# S- i
# U, s1 x, [. e9 A
" z. B! N" H& e6 _, ~public class TQC301 {
V0 T- N& }0 E9 ^0 @. v2 g: V
1 S, ` x& V$ i0 `* Z2 G3 } private JFrame frame;
; \0 n' S4 t9 y' x/ w) x$ _1 H# _ private JTextField tf1;& O4 [% j& }5 f6 _9 O3 S- {& t8 b
private JTextField tf2;
- m7 m3 {& Y6 }) h2 v { private JTextField tf3;
: o1 j0 i- r* a, T, Y4 ~% n private JTextField tf4;# w* j) M5 E: n5 u+ I+ c+ y9 t
private JTextField tf5;
) q' Z# L& S8 `/ {3 V& i private JTextField answer;( G9 p, K) N8 N) l- G
8 h' O, d% s7 j8 P% |& i /**
0 i/ Q) w: e/ K3 |9 p7 @" w * Launch the application.$ O) O6 f9 r/ K
*/
. S- ^+ e* j( O( _9 I' e" o public static void main(String[] args) {
6 |0 `7 f q4 W6 h, l EventQueue.invokeLater(new Runnable() {, b5 A) E2 z; s3 |# E+ D
public void run() {
: ~5 Z6 t5 U) o7 ]! W try {) q" o+ B! V S/ o: n
TQC301 window = new TQC301();
2 l2 b6 S* |& `+ x9 { window.frame.setVisible(true);
+ t3 y3 q- O" Q" h# \& Z } catch (Exception e) {0 y' ?; ^3 V8 X3 q1 I! i6 D0 }+ B, T
e.printStackTrace();! H7 u7 h, ^! G; E6 ], C8 n; R" v; T& v- J
}2 G- H: U" q: }/ ~& A3 F; L
}
7 Y, u4 }9 b9 F$ ? });
+ d- f: f+ K, W1 C, H }
$ b6 f8 j0 I) o
9 H/ N6 F/ t7 u3 M /**: Z V! O& T& T6 ?6 u r
* Create the application.
+ i% b& F6 f& Y: h5 \9 v */
7 X, O2 b* H: K% ]* j d+ h public TQC301() {
: w; x( V4 _3 e- m3 f' W4 R initialize();
7 H( d3 w; h- v! F/ R/ G9 Y }; N/ K) y" c5 U, N
3 J8 s" |/ v4 _8 G' {6 `' a" D
/**, X% T& ~( ]% y6 [
* Initialize the contents of the frame.
- C/ F: z" {3 k0 C) ` */
. l! _9 y- \& G8 h# q2 g: m private void initialize() {
1 N ~) z& n4 j' ~$ R, f frame = new JFrame();
+ f$ N# p# M2 [4 q frame.setBounds(100, 100, 450, 300);
7 W( W' I; S7 L8 f" }$ `/ e frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);3 W3 |6 t- u( G+ w! P. a2 j7 M
frame.getContentPane().setLayout(null);9 L Q. V4 z! J
) D, e& [. n: J! I7 M) ~: s JLabel jl1 = new JLabel("\u7F8E\u91D1\u73FE\u503C");3 R& X8 Q2 M3 f& ?, e* }
jl1.setForeground(Color.BLACK);. f c3 S: b G R& l# o1 }4 t
jl1.setBounds(20, 27, 60, 15);
0 f. h! }+ |4 T) C- I( r frame.getContentPane().add(jl1);! x+ k& T# M, @
6 M7 H" T+ x' C* I8 |
JLabel jl2 = new JLabel("\u65E5\u5713\u73FE\u503C");$ b2 G ^4 D( Q& A- L+ F
jl2.setBounds(20, 63, 53, 15);
# q% D4 |$ e: J/ A. ^3 j' w frame.getContentPane().add(jl2);* Y/ N: u$ o7 h; v, F! o5 X
d% F; s) w$ @5 _8 F8 |& [ tf1 = new JTextField();" \* L: E# Q; G _
tf1.setBounds(83, 24, 96, 21); _' h8 g ]$ m
frame.getContentPane().add(tf1);0 P# V) a; X V7 e7 @5 |9 x# ~
tf1.setColumns(10);5 E/ i# B% u* x0 M* L. u R
5 D/ y" p. U( j: S
JLabel jl3 = new JLabel("\u6E2F\u5E63\u73FE\u503C");6 I% D3 Q! L" v$ k! B1 u1 P1 p
jl3.setBounds(20, 102, 53, 15);/ c. B- |$ i5 i* u! R7 F! g, V) m
frame.getContentPane().add(jl3);
" t3 f, D2 V- z
' Z' X: ~/ ]% w5 x JLabel jl4 = new JLabel("\u82F1\u938A\u73FE\u503C");7 i% P5 q) d$ V2 f
jl4.setBounds(20, 141, 60, 15);: N8 b% [/ ?' x4 f1 W7 [) B
frame.getContentPane().add(jl4);6 @7 K% J* U7 H1 ]; i; P
2 s( o9 `1 r; Y7 g JLabel jl5 = new JLabel("\u6B50\u5143\u73FE\u503C");
5 q2 ~/ N4 `+ O( y/ ^' D3 Y% {# {, C jl5.setBounds(20, 180, 60, 15);
; a6 \+ c) R+ L" x3 B8 e frame.getContentPane().add(jl5);; e. z2 M' K- O: a% T4 h
, G1 T4 P7 k! g/ f, _
tf2 = new JTextField();
1 n# H5 a3 k# l K* U5 L* @ tf2.setBounds(83, 60, 96, 21);
% O$ Q' w! o! P2 @: d/ T) b frame.getContentPane().add(tf2);
. `- A; f) z: i% M tf2.setColumns(10);
, }% d9 q* Y6 n. K 6 s) E2 B0 X( f! u1 Z! _" z4 @, \
tf3 = new JTextField();
5 a6 J. b. F; H3 e4 U3 A5 }1 Q9 y, { tf3.setBounds(83, 99, 96, 21);
: p& D0 T W! t2 u4 ` frame.getContentPane().add(tf3);
' [# z- ]4 X: _+ o' K; x! l tf3.setColumns(10);
0 X$ O$ ]3 _. i, t. } " i, Z, @% S0 H) j4 ^+ W4 L. t
tf4 = new JTextField();
6 Y/ J- x; o7 }* ?- ~4 s tf4.setBounds(83, 138, 96, 21);
, {& O/ g) O B4 Q7 W frame.getContentPane().add(tf4);. G$ D$ c3 J D0 }! z
tf4.setColumns(10);( n) W2 n7 D: I. @
/ q4 @! A' m" |2 H# @5 K* |* ` S
tf5 = new JTextField();
# x0 m9 ?( n2 S$ l- e tf5.setBounds(83, 177, 96, 21);9 |6 A" L6 T! @ A
frame.getContentPane().add(tf5);7 j* { ]! l1 Q9 j; e
tf5.setColumns(10);
* X5 j0 s# H a1 `8 M) ^& Z
( [5 Q) Z% c) _) H answer = new JTextField();
H9 W8 `; E( `1 O& F& | answer.addKeyListener(new KeyAdapter() {
% b5 O# { u" Y9 J6 R0 w+ a @Override
) ]. W) l ]! A4 h public void keyReleased(KeyEvent e) {$ j1 q6 h1 K) k4 [! c( E+ F) p
System.out.println(answer.getText());
, M: N1 b* c; Q/ l8 ^$ q % y; r- B1 g# @! `6 Y' z0 g
try{
- x1 h" O& d' S, h, [( T, V! M2 T double num = Double.parseDouble(answer.getText());
& g. A) m' G" P' [. U/ f( ^7 ^
# V! F% j1 Z. F5 Y' y! L4 K7 P f4 G1 }
" H) c/ r' ?# | tf1.setText( String.valueOf(num * 0.029) );
' |+ ]8 c# W) C5 Y tf2.setText( String.valueOf(num * 33.53) );
* ~& k8 J7 k6 k' }% ~* E tf3.setText( String.valueOf(num * 0.22) );
0 t' Y; U/ B9 X tf4.setText( String.valueOf(num * 0.018) );
a, Q1 C+ C L3 q3 d tf5.setText( String.valueOf(num * 0.03) );# {. K5 R* e, Q @
}catch(Exception ex)! l4 E; d& m4 I. G. e2 K( h# K, _
{
( g) B: }: I! ~% v tf1.setText( "請勿輸入非數字的字元" );
. l- i- ^+ [. ]3 ^ tf2.setText( "請勿輸入非數字的字元" );2 x% R. a3 n% R e' g
tf3.setText( "請勿輸入非數字的字元");. C' b1 o/ U8 ~- T5 D
tf4.setText( "請勿輸入非數字的字元" );2 c% d2 k4 D, y4 D# o! \: U3 V, S5 G5 e
tf5.setText( "請勿輸入非數字的字元" );
! E4 p9 G2 w% `9 e) U }
0 c9 T, E3 I8 e; e: O& W! x
+ U9 Q5 }4 n1 y D" q* H }
$ O7 B2 p5 y q( J |0 D });
+ }3 R" G$ f+ R/ T F
6 ]! ]% a: r- ~. {" U/ u answer.setBounds(20, 224, 159, 21);
: ~0 k8 y) v: J/ N1 v frame.getContentPane().add(answer);
! j" n- u+ Q# H: E( }: [ answer.setColumns(10);9 r1 C& J: o5 y! H( U& e
}( E5 t0 o7 j* s+ F, S' Y0 @
} |