import java.awt.EventQueue;4 B! z. w5 Z, T' j: b( ?
* m1 Y* p7 Q9 h l* l
: t/ B6 f( _8 M( Npublic class TQC301 {1 J' k/ U" [7 N
2 M, l" }' ~! s. Z8 v2 p8 U: d. S4 ^
private JFrame frame;
; X& |$ v8 F1 t3 H( s private JTextField tf1;# t3 X- G7 {5 O% u, H7 ?/ h: ~1 Q
private JTextField tf2;
" ~6 }# g4 W) P4 F2 j' O private JTextField tf3;
) ] E, [) H. e( ]3 r) x private JTextField tf4;
' g, m; m7 m% b1 H private JTextField tf5;( x' m& R \( e3 x% q* i" d
private JTextField answer;# K+ j( X2 L; h9 X! o4 o
( t- o! P$ {; s- p0 B! u /**7 `7 N z# u9 |: ~& p
* Launch the application.
4 ]4 D& B8 w( G/ L4 W3 Y4 J */. v- C0 C. s8 B9 ?. ~! @
public static void main(String[] args) {
2 s0 x' a4 v q- C3 w E' y EventQueue.invokeLater(new Runnable() {
& j7 I) @" }9 }0 x6 s5 x public void run() {, ^! q) ]+ \; z1 \5 t
try {
/ u& J t4 E" d# o1 ` TQC301 window = new TQC301();) a/ {2 f+ o7 `6 P9 r
window.frame.setVisible(true);+ c3 ^/ r8 N% j7 ^: i
} catch (Exception e) {
) q; A( H. L& o" q7 o e.printStackTrace();- K6 U# e# B/ |7 a, Z2 w
}
6 F6 F* a3 b- p Z }
4 y' e$ W. a* I, @ });* O/ g! g" t4 l8 Y, C* i, L$ c
}
9 y) O$ ]9 G& Y; ?4 ~& S& X9 E- ?: \- ?7 s
/**& D8 \7 t% l5 b3 u6 |
* Create the application.) F# w! ]) e7 L- y
*/
" w9 O$ D/ g$ x& G0 n public TQC301() {
3 K. \7 p' o- f8 ~9 @$ P* } initialize();
( E- o" s1 p4 d3 X" x }, ^7 z [. X+ Q+ j$ ?: L4 M
`. s# v$ J0 Z5 o9 s. g# R
/**
. M/ S1 _7 e+ [: ^5 f3 M" f- K * Initialize the contents of the frame.
2 V' |* i6 v! g, U */: A8 A5 m6 V3 U1 z' e
private void initialize() {& {8 D' d; \* x* w! b( F# y, T
frame = new JFrame();
0 @4 T0 Y+ T& @ frame.setBounds(100, 100, 450, 300); h- ?. G0 k1 r; [ @, j
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
; P. ^% l# f% B, J/ U5 p frame.getContentPane().setLayout(null);
0 _: |1 H* Q9 p6 |
6 T4 i6 E' _5 ~! M m: A JLabel jl1 = new JLabel("\u7F8E\u91D1\u73FE\u503C");. A. U: J8 o4 Z$ E% S# C7 b
jl1.setForeground(Color.BLACK);
3 I3 U! ^( q5 J9 v' R% {4 w9 b+ A jl1.setBounds(20, 27, 60, 15);' {: w# C [- J4 ?/ `
frame.getContentPane().add(jl1);
, m. F" P- O0 }0 A7 |
4 O0 a3 s) x+ m9 m* H JLabel jl2 = new JLabel("\u65E5\u5713\u73FE\u503C");
# v8 S* v: g6 ^: P$ l jl2.setBounds(20, 63, 53, 15);
. J9 M L! `1 `$ q/ ` frame.getContentPane().add(jl2);
6 C& m1 E1 A4 |( Q( V 1 Q z/ G5 X" ^. c$ q
tf1 = new JTextField();
) V' c5 i; A$ n tf1.setBounds(83, 24, 96, 21);
, L; q7 k5 n7 {; R# R# n frame.getContentPane().add(tf1);
9 J& ^9 V: x3 x7 k7 k! j* j tf1.setColumns(10);3 t" z7 m j, F5 C$ X2 N, \% _! Q
^: _8 b" ~4 g, B JLabel jl3 = new JLabel("\u6E2F\u5E63\u73FE\u503C");
8 [2 O9 C( g8 [& k4 B: y4 m$ w jl3.setBounds(20, 102, 53, 15);
, r# b. `$ K! U0 O frame.getContentPane().add(jl3);: U5 l n# Q- H. A) }$ Z$ R' {$ x4 B" s1 ^
7 k$ k3 [2 A0 e- j9 g' t
JLabel jl4 = new JLabel("\u82F1\u938A\u73FE\u503C");
- p3 b1 E& N7 B* y9 F9 \! k jl4.setBounds(20, 141, 60, 15);
! X! i- |( q( T0 s) J3 `& D frame.getContentPane().add(jl4);
( d6 S# K6 Z2 v1 o0 W* q% }6 p 9 Q4 ?# O, i* F' P6 Q
JLabel jl5 = new JLabel("\u6B50\u5143\u73FE\u503C");
- S' x5 e# {9 [& p; W4 Z# D! ` jl5.setBounds(20, 180, 60, 15);
1 _! q4 @% _3 |. l$ X frame.getContentPane().add(jl5);
; s4 r0 a D* S. @- W* \
0 ]- ~! X4 t: u3 c6 i" b9 l tf2 = new JTextField();
" K; [! s6 y1 v# [ tf2.setBounds(83, 60, 96, 21);
+ e; [' n0 C7 ^( q9 P/ k7 W. b) @ frame.getContentPane().add(tf2);
9 {; d5 o# u/ S# v tf2.setColumns(10);* ^, E# r- s2 a. t. k
+ M0 S4 \9 \1 b0 j6 S
tf3 = new JTextField();& x o6 w- L/ j- c/ N, I
tf3.setBounds(83, 99, 96, 21);% _: N' Z9 x* D" j; d; ?7 h4 D0 x; E
frame.getContentPane().add(tf3);
& s/ p$ `& i% t5 i; M/ G tf3.setColumns(10);* M* h6 s n7 c( s0 U3 V9 ?& ?. `
' a9 O$ ^! k* z+ F5 z k
tf4 = new JTextField();
- E7 b; w4 J, r: w0 u( M tf4.setBounds(83, 138, 96, 21);, @% H' _: T0 P" @( {
frame.getContentPane().add(tf4);2 f( `8 `! ], k5 L
tf4.setColumns(10);
- j/ c. c' U/ V" Z! x - B% s+ E# K* U: k! k3 Z+ Y. U
tf5 = new JTextField();
$ T/ P2 `; F+ {* `4 ]: v4 c tf5.setBounds(83, 177, 96, 21);
: L1 _; f+ f3 G; F frame.getContentPane().add(tf5);/ ~8 }. F( _3 ?. u+ T3 Q
tf5.setColumns(10);
2 P9 H2 k- p9 @; F @9 \ + ^" s' |" f: [$ @1 ^" {
answer = new JTextField();: }& F/ B p# A7 N
answer.addKeyListener(new KeyAdapter() {" N |# E8 b6 Q
@Override
* r2 t+ X9 M* t4 _* K1 x$ } public void keyReleased(KeyEvent e) {
! @2 n9 M9 w% @8 e3 n System.out.println(answer.getText());' a& b. A) i0 g! @) R% j
8 M" B6 P) o: F, f- u try{# K8 s) B: \: A$ C$ J
double num = Double.parseDouble(answer.getText());; H1 b# n+ N7 L5 W+ X7 F
. o# I2 O# ^5 y* A2 K$ q
3 \5 _; p& N. [( @
tf1.setText( String.valueOf(num * 0.029) );
9 p3 }# T) v9 i m' n! e tf2.setText( String.valueOf(num * 33.53) );: e5 r S- t# h! W( S+ X4 v u
tf3.setText( String.valueOf(num * 0.22) );
! _4 |, B$ ^7 |2 J5 ] tf4.setText( String.valueOf(num * 0.018) );
+ s1 V+ ]) W" w6 d. q, j ]3 k9 B tf5.setText( String.valueOf(num * 0.03) );
1 G5 M! G5 }4 v, g; B6 N# e }catch(Exception ex)8 d! G7 B$ i3 ]0 a
{
: y7 |8 _/ v& Z, I* ?( H$ k tf1.setText( "請勿輸入非數字的字元" );- [- L2 m8 ?) L# Y* L: @
tf2.setText( "請勿輸入非數字的字元" );
2 i) P, C, T5 z( {; v5 ^ tf3.setText( "請勿輸入非數字的字元");( S- Y, d! x/ Q6 n. b1 S
tf4.setText( "請勿輸入非數字的字元" );4 R1 [) Y* C4 t8 a& e0 @3 D
tf5.setText( "請勿輸入非數字的字元" );
8 X! t. w* x2 Q# e3 {7 G }0 ^) L" T9 N$ c8 X' C6 c# ^% Z' E
' ~7 T1 u5 A# ^. i7 ? }
( N7 q3 I: r( v: F. F });
3 Y8 \3 f. Y; M% w0 x5 N! C5 i `) `$ {6 W
answer.setBounds(20, 224, 159, 21);
! F4 e& R3 E$ F2 P9 e4 { frame.getContentPane().add(answer);! c% Z5 | T6 t) o" G: W6 Y7 a
answer.setColumns(10);
+ `. W: @* P7 T9 q& u }
- v" [$ H$ _* @: e5 `2 ]+ s} |