import java.awt.EventQueue;& s1 R( B( Z- T) L
9 w7 V# o& n q* l$ f& o) m# w4 {
& C& y, g2 j* V2 Lpublic class TQC301 {7 m j1 {; q2 B7 [9 L, E
- ~% B i3 Q0 `; y
private JFrame frame;- [7 H- l+ X; M' x. f
private JTextField tf1;
' k B. O$ N3 N) ^; q private JTextField tf2;
8 E& D: W4 M& y- v9 ^ private JTextField tf3;0 q# z/ Y- y2 ~' o9 a2 G' Z* x. [
private JTextField tf4;* J' ~" \" y! f( ^; K
private JTextField tf5;
' l2 o) B7 W7 p$ O private JTextField answer;& u9 A7 K U" e9 O0 Z2 l4 T
l m3 U0 I' N /**" y$ @! J- {$ e- @3 P% l) ^
* Launch the application.% J% |; p0 M( W2 B
*/ K- L8 z- s* y ]3 b$ Y
public static void main(String[] args) {
b- d. \% p& r, A( B! P0 h& X8 g EventQueue.invokeLater(new Runnable() {
F9 i" U* p6 N' M public void run() {
2 x% ^" d& `- y try {% l: z" D# R' N2 F |- E! W
TQC301 window = new TQC301();8 Q7 C' o2 \6 x/ W
window.frame.setVisible(true);
5 a/ R3 M, q+ e1 T } catch (Exception e) {
8 D& c1 G; R2 Q9 e. l3 b7 T e.printStackTrace();4 s6 v2 M3 i' P8 `
}
% u8 F! m4 T3 p0 l9 @ }
# x# b" z9 Z- E/ P/ j1 z });# d% z7 Y# \9 s4 ?' Y3 a
}
8 ^! H5 m b) v) x! Y( j C9 Y
, \2 m7 D2 u; u/ U; i /**
) _6 K7 _9 T6 d) b0 W: a( |5 o * Create the application.# w. m* b$ {) O$ W" t
*/+ B: [# m' g8 |3 z
public TQC301() {6 x7 ?+ E) h! l5 f2 ]2 G
initialize();: J; Q6 Y3 ~0 G* _/ H
}) V% H; x' P( a
0 O& |( J1 J& J4 `8 R( ?
/**( \* A: G# b( R$ I" ^
* Initialize the contents of the frame.7 T$ w, c8 `1 y& w- ]4 q- `
*/
& \1 ?2 }, t F: D6 u# e% Q" [ private void initialize() {
; u4 M, y! z$ F5 N1 s/ j* h. J6 k) K frame = new JFrame();
% p8 A: g. M8 _& Q frame.setBounds(100, 100, 450, 300);* L5 [1 T& N' f% P/ C1 E) u* D
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
' Z$ u2 k! ?" @; t frame.getContentPane().setLayout(null);
( I/ q7 v9 t4 z( l7 N
# r1 }* T5 R; W! u JLabel jl1 = new JLabel("\u7F8E\u91D1\u73FE\u503C");% G5 U8 N$ c, M. Z
jl1.setForeground(Color.BLACK);. x' a8 e6 Q+ w0 n+ W( f. n
jl1.setBounds(20, 27, 60, 15);" r$ l/ @, ?% H0 o
frame.getContentPane().add(jl1);/ w- y" ~. V2 D: E4 e, d- r
" ]2 [; R/ h/ w% \# j
JLabel jl2 = new JLabel("\u65E5\u5713\u73FE\u503C");
8 V9 b: A$ E# D1 j% N jl2.setBounds(20, 63, 53, 15);
: L" u0 u$ y) [# @" R. E frame.getContentPane().add(jl2);! k. M8 Y7 [" G9 s3 N; Z
* n1 w4 M5 s. }" ] tf1 = new JTextField();9 Z. M0 O, Q5 g6 L8 m6 v, k
tf1.setBounds(83, 24, 96, 21);
8 L p7 f5 a d0 d frame.getContentPane().add(tf1);3 C5 I7 j4 F2 f& S8 j
tf1.setColumns(10);/ w+ Y9 C; k% |3 c; |
5 F. G2 }& E0 r
JLabel jl3 = new JLabel("\u6E2F\u5E63\u73FE\u503C");/ G, c; U1 u: |! M, N" J7 h' Z
jl3.setBounds(20, 102, 53, 15);7 [3 s7 ]* S k0 s5 X6 L
frame.getContentPane().add(jl3);& T& U5 m8 n# k' u' u
2 ~0 v9 Z d( ^4 _, H
JLabel jl4 = new JLabel("\u82F1\u938A\u73FE\u503C");6 p" U j# X9 `' A+ d6 C
jl4.setBounds(20, 141, 60, 15);
9 e) k; q; G. o" r5 v1 J frame.getContentPane().add(jl4);* Z8 |; `. g) E& A
4 _; P2 Z, N8 d: L+ s8 \) { JLabel jl5 = new JLabel("\u6B50\u5143\u73FE\u503C");
: M7 N; o5 F% K' @) S7 Z jl5.setBounds(20, 180, 60, 15);7 S! w" J- e; a3 i, L# N% R
frame.getContentPane().add(jl5);
1 n$ W' f1 C r* S$ J$ X" Z: e. ] 9 C3 j) D" v) I2 e
tf2 = new JTextField();
7 u9 [. E9 t2 {, m tf2.setBounds(83, 60, 96, 21);% s0 B7 i6 N- k& A. [7 r
frame.getContentPane().add(tf2);8 M& ~6 M y6 r6 _& w, V
tf2.setColumns(10);
7 h6 `5 c! M* R4 E4 U : H8 V" k: Z# g0 |! y0 i# P- p
tf3 = new JTextField();$ M. ^2 E; _" l- \2 ]
tf3.setBounds(83, 99, 96, 21);" A$ U; t. s+ f+ B
frame.getContentPane().add(tf3);# p4 e1 g" U4 g+ S( K
tf3.setColumns(10);
, p0 W/ y. d4 l- [2 w7 W
0 _5 P, T/ _1 T8 Y tf4 = new JTextField();& ~" a. y- k# J: F/ V
tf4.setBounds(83, 138, 96, 21);# {- ]! I- C( ^! y# @7 u
frame.getContentPane().add(tf4);& h' ~' K/ ?# e
tf4.setColumns(10);
N4 P& ]; V/ v" t8 V ! \5 x7 T8 W" o2 w3 n( D4 D5 H. m( {2 G
tf5 = new JTextField();
8 n7 z2 z' f/ o+ G* P tf5.setBounds(83, 177, 96, 21);
' N6 \2 C, ^; D* U8 @ frame.getContentPane().add(tf5);: G5 T/ {- Z( H' }4 n0 @2 U. Q7 ^# B
tf5.setColumns(10);/ o/ F! V! F% j5 B, K. ?/ K% s/ B' `
1 Z( v9 a( t8 S% m' d9 ~ answer = new JTextField();7 ~7 O( E& M7 H& [
answer.addKeyListener(new KeyAdapter() {
$ e& q3 w/ o. n( C @Override! Z- y$ p( d' R) w/ \4 g
public void keyReleased(KeyEvent e) {& j' @; ^! o- j7 A6 b
System.out.println(answer.getText());
; C b$ d) X3 X
+ c5 N! V V$ q# Q& I1 Q4 ` B try{
7 h# u4 }) C8 @/ R8 G double num = Double.parseDouble(answer.getText());8 ?3 M+ V# s; j# h) m
- i2 w: c3 D/ G7 H
h: `0 e8 i4 n% B% G: J" h0 J P
tf1.setText( String.valueOf(num * 0.029) );% P2 I% F! l/ ]+ J3 O+ W$ X# O
tf2.setText( String.valueOf(num * 33.53) );
. s$ @4 l, Y9 }" M# M# h+ h" V- @ tf3.setText( String.valueOf(num * 0.22) );0 Y& f; ]: T: s6 K
tf4.setText( String.valueOf(num * 0.018) );
; w7 `# y" c% N) ? tf5.setText( String.valueOf(num * 0.03) );
4 |4 {) Z6 D" t0 r }catch(Exception ex)6 Q9 Q' u- S% a
{- C+ r0 ]% x! z! P. r
tf1.setText( "請勿輸入非數字的字元" );. k2 J: ?1 w. [3 T" x8 x4 [( {- f3 ] {
tf2.setText( "請勿輸入非數字的字元" );
' C3 O" X5 t" u# v" x3 Z C5 W# {4 t tf3.setText( "請勿輸入非數字的字元");3 T' z0 Y8 j$ S8 a' o# h
tf4.setText( "請勿輸入非數字的字元" );
6 `8 r& f/ E+ a, c6 y' t4 { tf5.setText( "請勿輸入非數字的字元" );* @8 ^. c+ n ]6 Z" p ]
}
* s9 t( R G; z ~' ? I9 @& |
) A% Q% }+ ^/ E5 { }
/ e9 P% B- d& L! l0 q5 N* F: U });. N, \- L) M+ y' O2 j# p# l& K
r6 @) P, V" h1 u Z( @
answer.setBounds(20, 224, 159, 21);
2 ?$ h# V7 U* ]( `' W frame.getContentPane().add(answer);
( z+ I- X% h, Q& L3 ? answer.setColumns(10);" u; A3 a. a m C6 z4 n! @( l
}; \) @: e9 z& y: @8 W
} |