import java.awt.EventQueue;9 `& M9 d4 A3 T. h' e
8 Z0 h& w$ v8 F" Y
0 m5 Z& [0 V" P
public class TQC301 {
/ S" i& _2 j6 o9 p% @" y& j9 h: _6 i" R2 H d1 I5 G* g) D
private JFrame frame;
1 O) N" o! f* ?3 Y private JTextField tf1;$ m7 R+ P' I8 p
private JTextField tf2;
3 l. A9 w, s0 b! X+ @8 b5 o private JTextField tf3;/ |6 Y( l9 w$ y/ u
private JTextField tf4;7 M8 d: v" j! e7 }0 t, K& v+ f
private JTextField tf5;
9 M9 u6 l$ U8 @ private JTextField answer;3 Q" }. d: Y& k' ^
* S% {4 P5 k) @) O% [0 ?1 p /**) z# Y k; ^$ m% C4 k. E
* Launch the application.
7 C# ^4 X4 C: @) e( V */" O; B- @7 M) l
public static void main(String[] args) { @. E* v* p: c U
EventQueue.invokeLater(new Runnable() {
' ~) I$ e2 s D. G7 h4 ?4 u public void run() {/ A6 S+ P4 I9 [0 r$ r- O
try {! P$ ^$ W# Q! s! b
TQC301 window = new TQC301();
" k, T" h9 T6 T$ S window.frame.setVisible(true);! s z4 [" a3 X! v# D1 J8 J2 [, a. [7 F
} catch (Exception e) {
; c0 N5 K* t4 U+ r e.printStackTrace();7 v8 P. ]3 j$ C# H9 O
}
* T; b* l7 w7 f$ { }- g9 R/ E0 @& Q3 I8 Z
});8 O. f0 O1 H: N- c" C$ T
}, c( \- M4 d0 P$ j- @0 J
0 _6 ~7 Y- i2 R G# g# ~
/**
& R2 x/ u- @5 F0 u7 h * Create the application.+ g9 S* d# b+ X* N8 ]
*/
* h" y! G5 C7 Z' B" [ public TQC301() {' A2 p. |5 X" T. L+ [/ i
initialize();8 R3 q) H' M, k5 v' W
}
& s7 d2 s; ]' \7 l3 m& ~7 j# C; [. V" n0 m0 A
/**
$ ^. U) [( M, z; \; |! a3 p * Initialize the contents of the frame.
9 _, a- r0 S# z */
; h j- k5 c3 b# {2 h private void initialize() {
1 \5 j2 \# @/ F4 W- b) [/ @ frame = new JFrame();
+ ^0 K1 C' G1 b8 n4 S frame.setBounds(100, 100, 450, 300);
0 ^3 v8 P: I/ a* j* ] frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
, m9 V! N% E& m* [' F. i7 {# G; `. } frame.getContentPane().setLayout(null);. e) T8 O% v2 S M; W" n! R
' a( M- B! k9 r" D' Q JLabel jl1 = new JLabel("\u7F8E\u91D1\u73FE\u503C");
% I- r' L# W* O) l' T: @ jl1.setForeground(Color.BLACK);
$ u# L* T; i; i, _* n2 U0 F! E$ r" X jl1.setBounds(20, 27, 60, 15);
. r/ D4 R6 A( ~) R frame.getContentPane().add(jl1);3 s3 ~9 o1 T# |; x: F3 r | |
8 C! ?/ J3 |8 b JLabel jl2 = new JLabel("\u65E5\u5713\u73FE\u503C");2 ? J' J$ k5 [( y" y
jl2.setBounds(20, 63, 53, 15);8 C6 R4 p/ Z& D8 D: t" V
frame.getContentPane().add(jl2);
& t( A" d3 d/ K7 G m7 B* S
% J* R" t$ o/ }, B% H' a tf1 = new JTextField();
8 N5 k: b3 Z+ T tf1.setBounds(83, 24, 96, 21);
, b+ [6 w5 H; y, D: o frame.getContentPane().add(tf1);
: p3 c; x7 a8 @1 C tf1.setColumns(10);1 o% G5 y' j- ]. O& ?0 e6 U* R
+ d6 O3 H. i3 D9 F: c JLabel jl3 = new JLabel("\u6E2F\u5E63\u73FE\u503C");* \* y1 U4 E+ N' S: r
jl3.setBounds(20, 102, 53, 15);' I3 V) o' \" C$ ^! H
frame.getContentPane().add(jl3);* \ W9 e0 i) K; g
) T, q* y3 w# ]9 ]9 N( W6 ~; I& x2 i JLabel jl4 = new JLabel("\u82F1\u938A\u73FE\u503C");% Y( j; {: |! L' p8 F; X
jl4.setBounds(20, 141, 60, 15);* G; F1 i# T' w( K
frame.getContentPane().add(jl4);
& c# q2 `- w8 l6 L# x0 I2 P
5 F* S. {. i g0 z! P JLabel jl5 = new JLabel("\u6B50\u5143\u73FE\u503C");
3 w; @! n0 _& F/ y2 U( J( v jl5.setBounds(20, 180, 60, 15);
0 F+ c3 e4 f6 b frame.getContentPane().add(jl5);
* w' Q; U2 u4 y; n & s7 V) L! u& I1 S
tf2 = new JTextField();
0 }: o7 E6 c$ R tf2.setBounds(83, 60, 96, 21);; r% |/ r1 x" V/ G3 D
frame.getContentPane().add(tf2);1 V8 [7 z' B; a; V$ g
tf2.setColumns(10);& ~! q8 T0 A% h, G" ?8 f6 L4 S5 K
" K9 Y2 D) E2 E" R8 J# f
tf3 = new JTextField();5 _7 B3 n* F9 ]7 `
tf3.setBounds(83, 99, 96, 21);
, c/ |. `/ l! @: F& C frame.getContentPane().add(tf3);
$ l3 g& Y; i( x4 P! u tf3.setColumns(10);. I7 Z! D! s5 q5 a- c, B
1 k7 r; U. e" V7 k tf4 = new JTextField();
! g- X) P; Q X4 ^. }6 M& f, [ tf4.setBounds(83, 138, 96, 21);7 `8 `& f$ O* W5 `
frame.getContentPane().add(tf4);
4 a4 k* ~" K& N2 B3 ] tf4.setColumns(10);
8 n1 B( W5 T" Q0 Q , n3 s$ ?/ [# s
tf5 = new JTextField();4 o5 f7 E; m4 A
tf5.setBounds(83, 177, 96, 21);3 U9 ?* C5 E( i, Z' n0 @
frame.getContentPane().add(tf5);
, x) n* f# _+ _ tf5.setColumns(10);
0 O! |+ V/ X* d3 O" Y
, q% o: Y0 U M& ]( p answer = new JTextField();/ u2 x, y, `8 P# A
answer.addKeyListener(new KeyAdapter() {5 _- {: n {! D
@Override; S n4 w% D( S" i/ s+ h( z4 o+ z0 X
public void keyReleased(KeyEvent e) {: f7 U8 h) d3 A) t" i! K6 o5 ]
System.out.println(answer.getText());. L7 ] i4 B+ b: P/ v
& A6 H5 q( j% C, ^6 N" S4 M6 ` try{- S r4 V/ V4 y
double num = Double.parseDouble(answer.getText());8 }" S, d& ^) {# k' V7 ?( H4 y" M
9 U/ A: m/ \1 P9 r
& j9 B( [. D V4 }0 R tf1.setText( String.valueOf(num * 0.029) );# r6 v# e) l1 u" y$ X) m' [
tf2.setText( String.valueOf(num * 33.53) );
9 H" d* N( I* L- C tf3.setText( String.valueOf(num * 0.22) );
: ?; z$ s9 \; n/ m: O. P+ Q% q/ W0 m tf4.setText( String.valueOf(num * 0.018) );/ w4 ? h U/ |5 X8 j# s1 I" M
tf5.setText( String.valueOf(num * 0.03) );: I8 S! G U, `: v
}catch(Exception ex); G9 X* }$ N, ^1 d! Z+ m9 k# P4 t
{
% M- {9 V/ M4 j+ [6 Y5 X. ]+ Y/ @ tf1.setText( "請勿輸入非數字的字元" );3 N+ `3 ~7 A- s* R/ s
tf2.setText( "請勿輸入非數字的字元" );
% I# D6 Y, Y( n. @( G2 t tf3.setText( "請勿輸入非數字的字元");3 ?3 ]. A3 |0 j6 r2 t7 G
tf4.setText( "請勿輸入非數字的字元" );# F, S% f6 c% I5 [( W7 a; |
tf5.setText( "請勿輸入非數字的字元" );
& s" D1 P1 a" i" d1 n' o }
; e% s1 p: J N; M
( P3 K1 V* }7 `: ~/ F8 X$ `* w9 f }
' t* @" [0 x. r9 ^5 f% P });
7 C' i% u0 C! D8 c4 a5 I U2 @- |
answer.setBounds(20, 224, 159, 21);4 H6 x$ P6 t9 v9 B) s. d
frame.getContentPane().add(answer);* }- H9 G* S* ]. U2 S
answer.setColumns(10);
$ e" {$ l6 L) }* h4 k5 i }
; R, t6 N! F# x1 a} |