import java.awt.EventQueue;
( ?1 d+ b) \2 D
9 B' y% Q* i* E# ~; [) r/ [: h4 f* q! Z$ v
public class TQC301 {
# G6 z) d% K( u' y* u M0 r6 o! z8 ~3 Z) q
private JFrame frame;" r% T; G9 R- [& y( H( E/ \1 w
private JTextField tf1;
0 n% @+ l) K: {& U% L private JTextField tf2;& S' h7 Q& ]" z
private JTextField tf3;
) ?) W# w: D$ b; l: F private JTextField tf4;
0 q- c' b1 U4 u) n s private JTextField tf5;$ v: {* W$ r& y/ e2 X3 a
private JTextField answer;$ Y/ a* a1 Q) @8 o
4 }! l- K! r P- P2 W! Y! O /**
1 `' B: Q) Q! U. b4 j * Launch the application.# C8 g+ [; d$ b6 u! ?/ D8 g& a5 ~
*/
# q( N" B% w E* }+ I; p public static void main(String[] args) {
8 A5 D0 P7 x+ i EventQueue.invokeLater(new Runnable() {
$ S7 c" \/ G! M9 E public void run() {7 p2 ]" ^% O3 {! N. e# M2 n
try { X0 {& s' |( W4 v4 Z; c
TQC301 window = new TQC301();$ J( `9 b: Y( N( E* N+ {6 O
window.frame.setVisible(true);
& ^% e$ h: g2 d4 ^& v0 \& q6 A } catch (Exception e) {; E! ~) S$ ^1 U' {& f9 j$ _+ }
e.printStackTrace();
9 W+ W B$ A' t% k" h }) G3 a0 h. G C8 H& h' u
}
4 J6 m2 B6 J& n& `2 l: @# G });
# {: D1 q3 H" Z, A! \ }0 \& R- l$ Q6 q- `! Q
; A* J% l6 s! e6 T /**
/ J# G; H3 L0 d# I- f) J * Create the application.
; M* f5 V( A* m5 {7 B */" ]5 E$ z+ f N& s& c) z
public TQC301() {
1 t8 X# M+ m! K+ y E+ }# J; q3 a% v initialize();) E2 |4 H5 P. ?
}
/ m8 N; B6 u* }$ p! L E7 z m* ^6 f) U7 t% t
/**
T5 [$ t; b# _: k$ c" X * Initialize the contents of the frame.
3 r6 p3 c: {+ [7 T8 M/ \" ` */2 J( p# J# s/ s( K: I. t
private void initialize() {
* X: k6 {- l8 E( o$ `8 ]: X/ V# e frame = new JFrame();
- G+ U: a0 |4 {* | frame.setBounds(100, 100, 450, 300);
. k4 P8 o( H: {2 Y+ } frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);9 I O9 [" |$ B2 |+ I* ~3 E% Y
frame.getContentPane().setLayout(null);: E h( n3 _1 {7 n$ A2 u$ L
/ [; K F9 j+ J- N' ~
JLabel jl1 = new JLabel("\u7F8E\u91D1\u73FE\u503C");* I% }8 Q9 g$ l' R" P, O1 j
jl1.setForeground(Color.BLACK);9 M; p9 N+ M# f$ b4 ~. c2 i" V& d: q" L
jl1.setBounds(20, 27, 60, 15);. i: a; B+ ?( e# H) D% [
frame.getContentPane().add(jl1);
7 _: n# ?8 x, n' T ^ ; S# v. D4 d; L/ F2 p1 M' g/ i6 X" Y
JLabel jl2 = new JLabel("\u65E5\u5713\u73FE\u503C");
, ~" \& C+ K# G" {) G+ B& N2 f jl2.setBounds(20, 63, 53, 15);0 Y& C7 g0 }$ h8 j! n' A
frame.getContentPane().add(jl2);
, l; o* m; I/ P 6 m5 S3 P2 r1 g w' V" ~
tf1 = new JTextField(); `, [7 e9 }9 `5 P0 f
tf1.setBounds(83, 24, 96, 21);
3 P" Z/ Y' _7 L2 K$ |4 _ frame.getContentPane().add(tf1);$ a$ V6 F8 } L$ b! s0 P8 n. |
tf1.setColumns(10);8 J. c3 l S) H6 @1 h1 o
7 Q6 |6 L Z) j( T JLabel jl3 = new JLabel("\u6E2F\u5E63\u73FE\u503C");
' I& s+ l: E5 V# C+ { jl3.setBounds(20, 102, 53, 15);
5 T! y4 J# e M5 i6 N( B frame.getContentPane().add(jl3);1 G0 r' K7 v2 |' g* M
2 m G- K3 m% {0 F% m
JLabel jl4 = new JLabel("\u82F1\u938A\u73FE\u503C");$ ]! m( t+ O% {9 b" [' ?
jl4.setBounds(20, 141, 60, 15);
3 U% a( m: J4 d9 J frame.getContentPane().add(jl4);7 @7 I6 R8 f e- h
: M; G' S% A. w( `7 ~
JLabel jl5 = new JLabel("\u6B50\u5143\u73FE\u503C");
7 ^- h2 h" w7 b) p jl5.setBounds(20, 180, 60, 15);$ G% v8 u' ^/ t, i
frame.getContentPane().add(jl5);
$ x; l" d7 S& ]! j. D' ^ % A. U, n4 Y4 K4 d' j$ f
tf2 = new JTextField();
6 B! @3 l/ g: B q5 M( m# v, b tf2.setBounds(83, 60, 96, 21);
7 N) M& ^) ]5 j- s! x frame.getContentPane().add(tf2);
h( U: ]* _0 F# L tf2.setColumns(10);
9 Q3 G3 `/ {( d) {! L" l
$ o: e& m4 |5 }8 C3 ~ tf3 = new JTextField();0 F- w( G* \: l
tf3.setBounds(83, 99, 96, 21);
. i# a0 |$ ?8 p' r0 Q( N frame.getContentPane().add(tf3);
5 b- o' l" k' a: k A5 n; n+ [ tf3.setColumns(10);8 o( D( e: t; }8 M; A
* z5 G8 r6 f6 e+ x* D( h& |5 B tf4 = new JTextField();1 Z; @! M. y, P0 l/ C/ y
tf4.setBounds(83, 138, 96, 21);2 E* y# p- {0 c/ e8 ~0 L, J& R9 `4 I
frame.getContentPane().add(tf4);
( J! N" L! @, \. P tf4.setColumns(10);
: \0 ^/ w& f7 ~) S. z6 X - @" L: k/ N3 ?! B2 s4 x
tf5 = new JTextField();" O! ]# k+ y' L% q, Z; K
tf5.setBounds(83, 177, 96, 21);2 |& R% s$ h/ ]3 u( {
frame.getContentPane().add(tf5);" g) R3 K* E, H
tf5.setColumns(10);# H/ |! Z) y. \/ C ^
* X( Y4 E$ ^& b( y& A! L
answer = new JTextField();' g% b& l7 O- ~$ K
answer.addKeyListener(new KeyAdapter() {! R6 K6 ?$ @: s8 J( }
@Override
( g+ ~8 I7 o+ w+ A% l public void keyReleased(KeyEvent e) {
9 y* u/ c% w% M" u8 d: T+ b System.out.println(answer.getText());. S4 I+ r1 n# S
% `& G8 c& a' w
try{6 w" m9 N8 K' s3 S: X; i
double num = Double.parseDouble(answer.getText());
, w' D$ _$ d) {8 ^( a 3 X% R- d$ `) t) E. H' ?2 d
* R9 N8 n4 a- Y, b9 {' W0 O" n2 A2 d) A tf1.setText( String.valueOf(num * 0.029) );& p# v0 o# ~' [
tf2.setText( String.valueOf(num * 33.53) );
/ F8 P5 I3 y0 I$ q R* y tf3.setText( String.valueOf(num * 0.22) );
$ T9 e* `$ H3 ^. @ tf4.setText( String.valueOf(num * 0.018) );, s0 N( G) ]0 b! ?# Y9 I
tf5.setText( String.valueOf(num * 0.03) );1 \: \1 j: G3 k! B- m8 a
}catch(Exception ex). ~& U2 y/ [3 k; _4 {
{! o6 F5 e& _/ d# Y5 Z
tf1.setText( "請勿輸入非數字的字元" );$ |/ G" G+ z! j; I/ C9 g# e
tf2.setText( "請勿輸入非數字的字元" );
/ p3 J% e4 P, ^- j* D0 I8 N+ V tf3.setText( "請勿輸入非數字的字元");* _7 W9 n' c4 f+ `
tf4.setText( "請勿輸入非數字的字元" );, I; D3 Z0 b. `0 ~! _% N
tf5.setText( "請勿輸入非數字的字元" );
( ^" I1 X l# x, R/ X5 z6 ]* @ }
' I, @4 V, w/ ~( e# n# { Z 7 c8 g# h# s6 l) x4 }7 ^/ [
}
2 H8 D" T6 `5 R& {! g });
4 H% F0 ~0 l, {$ I
' ?8 {7 E; P. F# x; h2 U) g answer.setBounds(20, 224, 159, 21);% u( f4 U* J) t
frame.getContentPane().add(answer);& f6 x* q" j& t3 f2 H+ H
answer.setColumns(10);
" q7 m- p5 J/ S' F( |! G0 } }* v3 T" {* y2 n: c5 @# G
} |