import java.awt.EventQueue;
( J7 |+ L5 r- u# F3 L* e* T" H! q+ A0 p! Q0 ?- P
9 j. t$ K1 `! ]9 g4 i* Apublic class TQC301 {
% G0 T( k9 s1 v3 Q) Y: g. c3 {! `
# |- ~8 n A: y; p/ v5 s$ g private JFrame frame;% r. L6 T7 S& v) w% z, e4 l e+ G5 ~
private JTextField tf1;3 Z, X: \: c4 x1 _
private JTextField tf2;
- u9 k& h. y1 v, P+ o: T h. { private JTextField tf3;+ P' k6 W+ m( d0 F8 _# v
private JTextField tf4;
$ F# j5 b! l- L1 j1 `2 S: K private JTextField tf5;
! O3 R! ]" K- v9 S private JTextField answer;9 Y* Q3 f/ {* F8 W' I0 U
9 G0 y7 V3 L9 p/ {6 V+ d+ Y4 Y3 h
/**
; n0 x. M& B# i/ R; e * Launch the application.0 w# p/ |7 B# y$ `0 h. R' R' l' O! P
*/
8 U/ ?9 E* e" l; P# {1 U) m public static void main(String[] args) {* x4 G% Y# N( V( R" I0 h+ n
EventQueue.invokeLater(new Runnable() {
W7 s% p/ M$ t# K$ b8 @: f. D public void run() {
! D& c) O o, P try {
9 _6 t: M5 }2 L/ Z# x/ P' A. s TQC301 window = new TQC301();
0 M3 Z- W) |, K% l1 b1 q$ a window.frame.setVisible(true); M# f5 @1 u" i# V8 w% ]# g) F
} catch (Exception e) {/ R! p( p7 C- b# ^) a
e.printStackTrace();
9 P) x! i3 [% S }
4 o- v# u: R# J6 S }
6 S7 g- f- o$ m0 g5 i! \, q });9 e3 U( N; s) l& i
}' c0 H9 H: ^7 C: F
$ F7 ~; Q% @ X7 ?( L( h$ H
/**
, C0 i4 \; i5 h% |% t9 p2 j- V * Create the application.% {# o% j1 a' Q# r/ W) A+ Q
*/
) M* G0 J5 c9 Q d% L5 W public TQC301() {
8 M( j7 |7 o2 A initialize();! k0 O% b- w2 i' Q, G
}
. r1 M6 C7 n* @: ]
7 l7 `+ V. `' [1 E /**
4 X" c3 h; M, z$ m! v9 ^ * Initialize the contents of the frame.
7 ^7 l+ ^' k% t5 a2 m */
1 z5 r" ^% j, f L private void initialize() {
. t- t9 ]( V3 c3 U frame = new JFrame();
. b" F! K3 o" H frame.setBounds(100, 100, 450, 300);& b* `8 i! }( M# q6 e
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);) ^/ s. j: T8 H$ V/ y
frame.getContentPane().setLayout(null);
+ ~% d. F9 {) I1 R7 D- X
6 q" o4 Q7 x5 w$ R4 F2 I: d, `8 F+ R JLabel jl1 = new JLabel("\u7F8E\u91D1\u73FE\u503C");
- P# Y8 v! I! O9 V! h! V. V5 y) E4 ^ jl1.setForeground(Color.BLACK);" x3 j) z* s0 Y: V5 e; L* P) ~7 L
jl1.setBounds(20, 27, 60, 15);
6 v' P! ~! c, ^4 k7 @9 M. j- p frame.getContentPane().add(jl1);9 X- k% |& T9 W: S) R
# D: B' s2 i8 o+ q. T* S/ Z
JLabel jl2 = new JLabel("\u65E5\u5713\u73FE\u503C");
9 ]7 O- H; N/ _7 }' w jl2.setBounds(20, 63, 53, 15);
9 k# _6 |& p8 S* j, \) P2 c, t frame.getContentPane().add(jl2);
7 ]( m; T% ~/ q2 v7 K; B: U; B4 ] ( ^9 K' h+ ~1 a& a* S) @
tf1 = new JTextField();
' e+ g" X J+ r* Z0 a0 l tf1.setBounds(83, 24, 96, 21);+ ?) w6 K) a7 Q
frame.getContentPane().add(tf1);/ e- A9 v/ P; D; y
tf1.setColumns(10);
- e6 x3 f; w( F, w6 O9 }% F3 E
9 A& ^3 T5 }) [* w JLabel jl3 = new JLabel("\u6E2F\u5E63\u73FE\u503C");
8 I h4 p4 B1 p$ |2 |; @5 N jl3.setBounds(20, 102, 53, 15);. j7 F- [$ D o, Q& n8 y& ^ k" n
frame.getContentPane().add(jl3);
: m' ?/ B1 s2 [: w
( H/ J s! ]" B JLabel jl4 = new JLabel("\u82F1\u938A\u73FE\u503C");3 j% n4 H1 ~$ d x( j
jl4.setBounds(20, 141, 60, 15);9 x0 Z% `- J' F K
frame.getContentPane().add(jl4);
4 o; d- o$ z; y7 k- L/ u
$ d9 i; U0 Q9 M JLabel jl5 = new JLabel("\u6B50\u5143\u73FE\u503C");
5 h# W& N/ Z! H" R' A. W3 f jl5.setBounds(20, 180, 60, 15);
# D. H2 ^$ Q2 c- d3 \4 r frame.getContentPane().add(jl5);
- X' W% ^- t$ x x% p8 @ * a5 ~" _. \: S( C3 P
tf2 = new JTextField();: R5 p8 E' c. y; J/ d% S) ^
tf2.setBounds(83, 60, 96, 21);% Y: w6 p* _) d' ?6 a( x- h& o
frame.getContentPane().add(tf2);) N& i% ^) Y5 \
tf2.setColumns(10);
4 M* E' _3 A) U: F; t
( t; ~' T. {4 p0 d. [- y tf3 = new JTextField();
4 `% X# U4 S$ T1 l! Y( P& L2 V tf3.setBounds(83, 99, 96, 21);
: |8 |/ C8 b% _4 ] frame.getContentPane().add(tf3);
6 T9 `, v; X! ~, J/ M- w7 s' D0 H* r tf3.setColumns(10);
2 ^8 J8 @ F* `& g2 H ]1 [2 [: s % a% m9 K; }9 O/ h
tf4 = new JTextField();' q0 g4 w( m) y' L
tf4.setBounds(83, 138, 96, 21);& f) i+ n' h. ^8 O; U3 y5 Y* F) X( O
frame.getContentPane().add(tf4);& t6 [$ h- D& k% C
tf4.setColumns(10);1 Y& b! |5 V7 U& ]$ r* p
2 `; \2 ?( r" H tf5 = new JTextField();
) h+ @" o- M- T/ E( {0 ]: } tf5.setBounds(83, 177, 96, 21);* J! w, h8 r/ z* v- Z. N- ~1 A
frame.getContentPane().add(tf5);
4 O3 V/ O, b! n( Q2 P- I tf5.setColumns(10);
" Q5 L! K0 ~! a, h" O- n 6 u4 \+ I! x) t4 o3 h
answer = new JTextField();
+ a$ n2 H' R: X% k answer.addKeyListener(new KeyAdapter() {$ a% d3 w2 W$ a+ y! S; H
@Override8 q0 k$ \5 Q! P
public void keyReleased(KeyEvent e) {2 L7 c- p% C$ K
System.out.println(answer.getText());
( P2 q9 G% e6 x9 I7 K + L' U9 M% R" M- R
try{
' M, s8 N5 X" C1 w9 g' ? double num = Double.parseDouble(answer.getText());
8 X; C6 ^6 W* Z2 A z
$ p2 I/ J! `! M$ Q! v) T) }" a 2 ]9 u3 A$ Q0 ~& O
tf1.setText( String.valueOf(num * 0.029) );
! |* ~6 C* k2 T/ j4 g e+ y4 G5 a tf2.setText( String.valueOf(num * 33.53) );
0 y- j) }; x7 B8 ^: _6 c, {2 w tf3.setText( String.valueOf(num * 0.22) );
& q0 d- e: k3 R+ G tf4.setText( String.valueOf(num * 0.018) );
2 B9 e+ i) U5 `" K1 V, I) h tf5.setText( String.valueOf(num * 0.03) );- y; g: r `8 ~ W
}catch(Exception ex)4 r3 W% n7 `" ~8 ^1 h
{) z! M6 R5 o" c+ U+ {" ~6 ]
tf1.setText( "請勿輸入非數字的字元" );3 M& }' \' G5 V6 s
tf2.setText( "請勿輸入非數字的字元" );
' s0 g1 z" x' m1 k tf3.setText( "請勿輸入非數字的字元");# V! ?" K7 _/ `) o. `* o
tf4.setText( "請勿輸入非數字的字元" );
" b' e* x/ S# u* t! d tf5.setText( "請勿輸入非數字的字元" );
6 L2 h& j0 i: ^: S }* G! n; j! F9 }9 |0 }5 l; u
* b2 Y1 i6 r; y0 J5 } }8 W5 V8 G$ c5 A
});2 H2 l0 Q8 P: m' A) b' ^9 a) t
0 @4 {: A) A6 g+ X0 O0 W answer.setBounds(20, 224, 159, 21);) Z$ R6 {* o: ~8 D5 t8 U0 f$ o
frame.getContentPane().add(answer);
1 a f+ [- a" u w6 @. y answer.setColumns(10);; o/ X9 S! I$ G
}
A% ~8 T4 U% S! F, E} |