import java.awt.EventQueue;
3 u) E5 r8 q/ J. m+ `6 _) Y+ Y4 m3 k" t7 P4 ? C
r, T5 g& x2 X7 B$ P& U, Fpublic class TQC301 {9 f5 J K- f/ k1 }, J1 b
( n( N& A& h6 u$ y) K
private JFrame frame;
7 n0 O/ R& [4 T) q! \ private JTextField tf1;
6 e! S4 b$ X9 b1 [" R private JTextField tf2;& B! e) o1 `; v& g' `" P; _* R5 `
private JTextField tf3;
- a5 E$ |! t% s( g3 u( S# ?' t9 i private JTextField tf4;# k$ K$ {0 W/ N0 u- G# o9 C. q
private JTextField tf5;; k6 s1 f5 Q5 v9 x
private JTextField answer;$ U6 V2 L v6 x9 [) q, S/ y. N
, k( }% }1 m# L/ L# b+ H8 {7 |$ f# |. E8 M
/**
/ F* x/ L3 o* ]0 a( b' O: p0 \# U- V * Launch the application.' j" \! j4 q$ N
*/7 G: u$ g/ \2 p6 D4 e. M6 w
public static void main(String[] args) {6 S- O. r, |# t
EventQueue.invokeLater(new Runnable() {# n5 `; R3 n. \5 }3 D. v" D& @1 q6 P* r
public void run() {
7 J R% p5 {& h4 X try {: k( L4 c% r |/ M: v: p+ X
TQC301 window = new TQC301();
1 F! j8 ~* Y2 _ window.frame.setVisible(true);
" z; {2 i k4 z/ W' ]6 D } catch (Exception e) {
6 U: n# R7 a, k& y5 U' M e.printStackTrace();4 r( V. k% e* q0 i
}5 v( t o+ g% t8 Q! h/ P' W
}
- I; A# g. x1 i });' ^( f; A4 G/ f/ E, ]0 U
}& U, Z3 F: L5 B$ O
' e! E8 l5 k7 U4 A, \9 C$ a
/*** m4 ~7 t r H7 B5 W
* Create the application.9 `* T+ | \5 N, B8 y6 \% n. J
*/
. Q& H) m, z6 v0 u7 q$ { public TQC301() {. J2 S1 ]+ Z3 f+ w# D
initialize();
0 Q0 b; ?: V- K5 ^. j) c }
* E) a& T* J4 X; z: B! k5 O( S; O1 U# W6 t1 ?' J
/**
% o. b6 E" D) K * Initialize the contents of the frame.
8 J2 ?1 t4 O8 ? *// } x0 @/ |. p. d* Y4 V! k
private void initialize() {
/ W3 r& x1 R: L% u8 @ frame = new JFrame();2 L9 e# @' G* a
frame.setBounds(100, 100, 450, 300);
! x7 c/ W: W+ |1 q h; ] frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);! t. k) e6 [+ u1 s/ z' A) z
frame.getContentPane().setLayout(null);
' w) z1 G& |( k/ g# R
/ G3 J8 c+ O9 Y1 F" j. P/ b, E JLabel jl1 = new JLabel("\u7F8E\u91D1\u73FE\u503C");! R/ i& y+ S7 `: l+ K
jl1.setForeground(Color.BLACK);
. c) N' K: B1 r/ ~ U+ y& j jl1.setBounds(20, 27, 60, 15);
+ m! f# w: }- p frame.getContentPane().add(jl1);
5 J! F5 q k9 O: V' ?1 V1 t/ g C 2 ^% o1 \: Q- [
JLabel jl2 = new JLabel("\u65E5\u5713\u73FE\u503C");( g5 o0 N6 c9 g$ Q% S8 |
jl2.setBounds(20, 63, 53, 15);
4 x4 B# }- w. ?/ F: {$ _9 ? frame.getContentPane().add(jl2);6 y0 L S6 U3 P
( S6 u3 E7 k+ U- B; D3 f7 [0 b tf1 = new JTextField();
$ |. Z7 H& t/ J* W/ ?1 I tf1.setBounds(83, 24, 96, 21);: H7 t( j- w& ~2 |3 Z U
frame.getContentPane().add(tf1);; X5 ]8 _+ H' z6 a0 \; b
tf1.setColumns(10);% K/ Y; t7 K0 N! T: n
l6 f% p0 b6 X/ F JLabel jl3 = new JLabel("\u6E2F\u5E63\u73FE\u503C");
% Y! [" P/ G3 D8 c- d5 x jl3.setBounds(20, 102, 53, 15);; S! s; H/ J; l- M* e j- J1 K
frame.getContentPane().add(jl3);
8 \+ S1 B# R. g
. H9 F& ^: c0 v JLabel jl4 = new JLabel("\u82F1\u938A\u73FE\u503C");" i1 t* H) Q7 R6 j6 n7 L
jl4.setBounds(20, 141, 60, 15);
4 K) C, i/ }/ ?" Z, A T! E- F' | frame.getContentPane().add(jl4);
( ?+ P2 {: i: V) B5 o M 6 E9 h; Q" Z* L# B% K k# Q8 x
JLabel jl5 = new JLabel("\u6B50\u5143\u73FE\u503C");
. [0 D1 T8 o v jl5.setBounds(20, 180, 60, 15);0 w l3 Q, w2 S9 ~1 Z) h
frame.getContentPane().add(jl5);8 w) |3 S6 ^/ @: M1 L
9 l8 w P: Z% O' h4 J tf2 = new JTextField();' s9 Z$ ^- F% N7 Y
tf2.setBounds(83, 60, 96, 21); A7 n2 F f6 b
frame.getContentPane().add(tf2);
4 O' a3 f6 e& V7 X9 A tf2.setColumns(10);
9 l& X; S' u9 r- ?0 A ' r6 c1 J' e# B: q- X
tf3 = new JTextField();
# X+ @" f2 w3 r% n* }) L tf3.setBounds(83, 99, 96, 21);
6 {- J S5 }1 V& l. a$ ]7 ^* n frame.getContentPane().add(tf3);
\ {# u/ j0 z9 `% N) X9 D' c" X tf3.setColumns(10);
( E: x- n( X4 m$ B( T% T, J 2 K0 i& q0 U) }: o% u
tf4 = new JTextField();; Q2 s1 k7 C& V7 P7 ]4 v# m8 x3 ?$ n0 m
tf4.setBounds(83, 138, 96, 21);& V1 p; R1 n. u- W
frame.getContentPane().add(tf4);
/ M$ I: M$ q/ _1 i4 j* U* U ` tf4.setColumns(10);4 @! _) y6 X3 l! f. J! e
* z6 h% T* b% H& A
tf5 = new JTextField();
7 S0 Y: n U& @( s, {0 O' j tf5.setBounds(83, 177, 96, 21);9 o9 l) U/ E0 o' O3 Y J$ @
frame.getContentPane().add(tf5);
& n# @5 Z$ ~) d) ] tf5.setColumns(10);4 U6 Q4 w. o" q
- O. X) Q! o) p' l! D
answer = new JTextField();
0 g, r% H; O! l7 W3 {4 H answer.addKeyListener(new KeyAdapter() {
1 S+ ^& e. w2 @* ~! R @Override
$ A8 h2 i( ?. W7 ` public void keyReleased(KeyEvent e) {
) d0 i% z/ ~' O4 d9 U" Z System.out.println(answer.getText());
8 Y: U D3 }2 Q
9 {( a+ h+ _: B try{
# \5 k7 B* P4 W9 ? double num = Double.parseDouble(answer.getText());+ }1 O1 S+ @( p7 _% S
: t0 d, S2 l" l; A! I 2 ?4 A9 O; D0 N
tf1.setText( String.valueOf(num * 0.029) );! t# k! f% y* u r( L$ a
tf2.setText( String.valueOf(num * 33.53) );
2 |: D: k( f0 X tf3.setText( String.valueOf(num * 0.22) );
! _2 @. x3 H* F tf4.setText( String.valueOf(num * 0.018) );9 X! H% r# S7 ^- Y' i
tf5.setText( String.valueOf(num * 0.03) );
% J' n7 g! h1 {5 |" a }catch(Exception ex)/ z" U0 W, H, t
{3 S7 ~' S$ \7 v f8 ^
tf1.setText( "請勿輸入非數字的字元" );
/ ?4 O4 v' ]( n7 [6 O) u- { tf2.setText( "請勿輸入非數字的字元" );
( M& o3 M5 U, ~ tf3.setText( "請勿輸入非數字的字元");
. Z. s' Y6 ^2 c3 f& r h/ \( d tf4.setText( "請勿輸入非數字的字元" );% u8 w3 l9 B: R
tf5.setText( "請勿輸入非數字的字元" );* t! a4 s: d- K% A# }
}
9 u% Y1 A: q$ [2 m+ r
# y! O0 Y% r _4 z6 I }8 ]0 I# z8 J$ y ?7 a4 U
});
8 M. P$ l1 B) e4 P1 j
) ^8 ~& M" Y/ F" C. o answer.setBounds(20, 224, 159, 21);% z) N' u0 v: A, ^; U8 E. [. O
frame.getContentPane().add(answer);3 h3 G+ r* a; ^. X# j, A: r
answer.setColumns(10);
" G7 I5 _, C- ~$ F% C$ N" s }
' [6 v& W' T8 |; Q4 w: H$ ]* C- }} |