標題:
TQC301
[打印本頁]
作者:
may
時間:
2012-8-18 12:11
標題:
TQC301
import java.awt.EventQueue;
. B9 X3 X1 E" \: J( g
2 j8 Y" h1 q) D5 e0 T
5 D+ s& J- q3 b
public class TQC301 {
) b5 ]* I2 \( Z0 H( |5 i6 ]
4 E, j- i; u: p5 o: e2 `
private JFrame frame;
0 ]2 M, M. U+ z: [2 t ~
private JTextField tf1;
: y+ d+ J; i8 ^1 D C
private JTextField tf2;
7 g- @' c0 j3 T4 B+ @ L2 G, V
private JTextField tf3;
2 C, y- _$ d: ]* _* T( \
private JTextField tf4;
! }' Y1 ^/ Q) q; J
private JTextField tf5;
' M& v& \/ y; G- G# e: f9 H
private JTextField answer;
' n" ?9 O9 H6 W) {5 k
6 x& C# k! \# f" S. ~
/**
$ i9 Q' }4 a+ c( N! t$ f o0 J. K7 o4 Y
* Launch the application.
9 p* y$ g# P5 K3 _3 Q
*/
, c4 b9 v8 Y T5 |/ _- U* D) l
public static void main(String[] args) {
# S5 g6 W7 b9 ^
EventQueue.invokeLater(new Runnable() {
S* _/ X4 J0 x
public void run() {
3 K7 m" ?# l( E, g0 g/ p
try {
" U: o$ o& G, q( e& U" `
TQC301 window = new TQC301();
. T' k! r6 u: r {3 |
window.frame.setVisible(true);
* s C1 Q4 ~5 X/ U0 ?
} catch (Exception e) {
1 B# h# _! N4 r7 v* N3 Z
e.printStackTrace();
- T8 S1 C0 _0 l* [2 z2 W% n- y/ B
}
- w, M, n* _5 M! Z3 e% x; Z
}
- o; c; a2 R1 a' z9 c8 u; a& k
});
: j% C' P+ w/ b6 x$ u: o9 T9 Y% F
}
4 U- ]. f" s( ?6 y8 N# |8 r, p" G: s+ c
3 L# o1 n1 j) h1 K" n: s
/**
( z. j6 L2 i, [) G( ~1 z7 ^
* Create the application.
8 }! x9 c) q4 a z% `% |
*/
# {- [1 `. f0 L! x$ L+ {; g
public TQC301() {
/ u% m4 A$ p+ n
initialize();
+ }' w6 S8 [2 s. t8 X; T
}
. [7 ]2 Y4 z6 b4 g
7 m, m. P% Q6 p. I
/**
/ A0 G: k/ ^3 L, u# i
* Initialize the contents of the frame.
: m3 c) o- z; O3 e
*/
: f7 N# E" k* `4 c0 e
private void initialize() {
" j/ N1 F! a+ i; @4 g s
frame = new JFrame();
0 Z5 I, Z& E4 e W2 r) Y! ~
frame.setBounds(100, 100, 450, 300);
4 e9 M# M8 s3 C: E. Q: I" `$ V4 ?
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
. g" R' v% Y9 |
frame.getContentPane().setLayout(null);
; G; J( `* f6 h0 b
- P' L( }- {, `& b
JLabel jl1 = new JLabel("\u7F8E\u91D1\u73FE\u503C");
9 C$ V. ]# u0 o
jl1.setForeground(Color.BLACK);
* \; W2 }8 w( I6 Z( I
jl1.setBounds(20, 27, 60, 15);
3 y' [" w+ z! \
frame.getContentPane().add(jl1);
; u# f1 J2 j; Q+ E' ?
_. d" Y9 A' r+ N% c+ n; J
JLabel jl2 = new JLabel("\u65E5\u5713\u73FE\u503C");
5 n" X1 p; F) i
jl2.setBounds(20, 63, 53, 15);
H2 b5 X3 Y9 q ^
frame.getContentPane().add(jl2);
, s( u" _* P. a; ^
7 k0 Z+ B6 [" l% t$ c& S# m% c
tf1 = new JTextField();
& |$ e" C; w+ K! t: C" I
tf1.setBounds(83, 24, 96, 21);
1 K( F, k8 t- |. Q/ z
frame.getContentPane().add(tf1);
( E3 ~* a$ S7 W0 m7 w
tf1.setColumns(10);
9 F7 X. G7 y7 C" V, K6 H
" y. f( M! |( E2 z- w0 ^
JLabel jl3 = new JLabel("\u6E2F\u5E63\u73FE\u503C");
0 p/ m% c1 C* h7 X8 i$ ^
jl3.setBounds(20, 102, 53, 15);
( H1 }; t8 z: q6 W1 c$ R+ y
frame.getContentPane().add(jl3);
3 f7 I4 Y' M: t9 U0 s5 v
1 X: }/ _6 l `5 B- o
JLabel jl4 = new JLabel("\u82F1\u938A\u73FE\u503C");
6 J% H7 y' d* n9 M9 M0 j$ a
jl4.setBounds(20, 141, 60, 15);
# m& a1 X X5 D" b K- J# K, n
frame.getContentPane().add(jl4);
* f0 d# B& v" ^4 J" k' j, w0 U5 z
- b# W2 i2 s/ ]2 |* }' X0 i: v
JLabel jl5 = new JLabel("\u6B50\u5143\u73FE\u503C");
; w0 f- V/ D; n
jl5.setBounds(20, 180, 60, 15);
; s5 K: J& H5 R& R6 T# [1 D7 |
frame.getContentPane().add(jl5);
8 p* J. G4 U* F- ?2 j( e" c
* H& K0 d8 O0 s9 Q4 Y! |
tf2 = new JTextField();
# r& _* K3 G" v; C6 b
tf2.setBounds(83, 60, 96, 21);
2 w, N( X" t6 x1 W- D3 f0 Z4 `& {
frame.getContentPane().add(tf2);
1 y+ r2 ^2 S8 ~7 c7 Z/ R( \' g7 W+ X
tf2.setColumns(10);
4 N* N$ J4 J4 t" r/ Q5 M" C, ?
( s3 J; e( F4 n3 ]4 l
tf3 = new JTextField();
* T( ~# B2 k9 g
tf3.setBounds(83, 99, 96, 21);
r- A& M. o/ }
frame.getContentPane().add(tf3);
* a8 k# }& W+ p/ Q
tf3.setColumns(10);
. W& \2 E( G( ^; t @( D/ P6 j
; U0 v8 O0 s, R0 T# j, q
tf4 = new JTextField();
2 O1 ~4 C$ b- ~' ~5 o
tf4.setBounds(83, 138, 96, 21);
3 i5 l. N# Y9 H9 R5 @; q' g
frame.getContentPane().add(tf4);
o* o4 R) O& z) |" r3 G7 t7 G' Y
tf4.setColumns(10);
9 E, f3 [ o* P
3 ~$ H$ L# D6 T
tf5 = new JTextField();
: h3 Q' A! J: U, l4 D
tf5.setBounds(83, 177, 96, 21);
- \9 ]4 l# M9 C; [# Q% k1 c
frame.getContentPane().add(tf5);
0 D9 e5 K/ t% |6 f
tf5.setColumns(10);
* o7 e- j' N$ B+ `2 F- c e. H
* I1 X0 y2 L3 \' i
answer = new JTextField();
S3 y( J( A# S
answer.addKeyListener(new KeyAdapter() {
6 l: }& J( f" K, v9 L- U
@Override
1 S0 E+ o+ F1 ?, Q# u
public void keyReleased(KeyEvent e) {
3 g0 F/ u% Q# H! _* ?% ?# X
System.out.println(answer.getText());
6 D* d" V( j+ D. r' ^
* n. I- N1 w, e3 k, j3 c; f
try{
5 N- i1 Q( A) h& L$ U2 @
double num = Double.parseDouble(answer.getText());
* T( z/ E4 f. b' m" Q7 h0 {8 D& Q2 w, C
, x6 q' e7 v% Q
: c- y$ L1 Z v
tf1.setText( String.valueOf(num * 0.029) );
! W. [) Z* R+ t& ~- B
tf2.setText( String.valueOf(num * 33.53) );
. h# c, H$ Y9 s- ~+ l) S) r
tf3.setText( String.valueOf(num * 0.22) );
! m9 c' G" u! E8 z7 J
tf4.setText( String.valueOf(num * 0.018) );
& T; ]8 P* R% S8 A6 Y1 `3 r" ]
tf5.setText( String.valueOf(num * 0.03) );
& l& i3 C2 Q5 a: d1 H2 z
}catch(Exception ex)
; Z, z. b- w" b
{
: N- L6 J: B: Y4 d
tf1.setText( "請勿輸入非數字的字元" );
; C, ?5 w- y" V. k+ P n. T2 M
tf2.setText( "請勿輸入非數字的字元" );
$ r. B. @9 ^: i9 T0 J) z% B
tf3.setText( "請勿輸入非數字的字元");
. `4 L2 v; x x* z2 Q
tf4.setText( "請勿輸入非數字的字元" );
" D' y1 L8 H5 d& ]# m3 z, v* c9 f
tf5.setText( "請勿輸入非數字的字元" );
7 q! `6 h9 B& T, w7 x4 t6 L* _% u
}
/ C3 c% t. ~' X
4 S9 a/ n* k! l2 L; B' i7 m f0 F1 ]
}
5 Q- l( l3 n0 `0 k
});
6 N) X, I# ^1 C9 `7 ?
* C2 o5 o, p0 j$ T5 V
answer.setBounds(20, 224, 159, 21);
& n% i3 ?$ |1 L4 _! I8 @2 d! P' Z6 U
frame.getContentPane().add(answer);
, z n ?# b& W7 l! B0 V
answer.setColumns(10);
x. g4 Q8 G* \. r- V$ @3 D
}
p- i/ a# j8 Z4 E
}
作者:
johnson
時間:
2012-8-26 17:46
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.Font;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
public class JAVA301 {
private JFrame frame;
private JTextField textField;
private JTextField textField_1;
private JTextField textField_2;
private JTextField textField_3;
private JTextField textField_4;
private JTextField answer;
private JLabel label_5;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
JAVA301 window = new JAVA301();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public JAVA301() {
initialize();
}
void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 594, 385);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JLabel label = new JLabel("\u7F8E\u91D1\u73FE\u503C");
label.setFont(new Font("新細明體", Font.PLAIN, 15));
label.setBounds(10, 36, 80, 15);
frame.getContentPane().add(label);
JLabel label_1 = new JLabel("\u65E5\u5713\u73FE\u503C");
label_1.setFont(new Font("新細明體", Font.PLAIN, 15));
label_1.setBounds(10, 87, 80, 15);
frame.getContentPane().add(label_1);
JLabel label_2 = new JLabel("\u6E2F\u5E63\u73FE\u503C");
label_2.setFont(new Font("新細明體", Font.PLAIN, 15));
label_2.setBounds(10, 138, 80, 15);
frame.getContentPane().add(label_2);
JLabel label_3 = new JLabel("\u82F1\u938A\u73FE\u503C");
label_3.setFont(new Font("新細明體", Font.PLAIN, 15));
label_3.setBounds(10, 189, 80, 15);
frame.getContentPane().add(label_3);
JLabel label_4 = new JLabel("\u6B50\u5143\u73FE\u503C");
label_4.setFont(new Font("新細明體", Font.PLAIN, 15));
label_4.setBounds(10, 240, 80, 15);
frame.getContentPane().add(label_4);
textField = new JTextField();
textField.setBounds(100, 238, 476, 21);
frame.getContentPane().add(textField);
textField.setColumns(10);
textField_1 = new JTextField();
textField_1.setBounds(100, 33, 476, 21);
frame.getContentPane().add(textField_1);
textField_1.setColumns(10);
textField_2 = new JTextField();
textField_2.setBounds(100, 85, 476, 21);
frame.getContentPane().add(textField_2);
textField_2.setColumns(10);
textField_3 = new JTextField();
textField_3.setBounds(100, 136, 476, 21);
frame.getContentPane().add(textField_3);
textField_3.setColumns(10);
textField_4 = new JTextField();
textField_4.setBounds(100, 187, 476, 21);
frame.getContentPane().add(textField_4);
textField_4.setColumns(10);
answer = new JTextField();
answer.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
System.out.println(answer.getText());
try {
double num = Double.parseDouble(answer.getText());
textField.setText(String.valueOf(num * 0.03));
textField_1.setText(String.valueOf(num * 0.029));
textField_2.setText(String.valueOf(num * 33.53));
textField_3.setText(String.valueOf(num * 0.22));
textField_4.setText(String.valueOf(num * 0.018));
} catch (Exception ex) {
textField.setText("請勿輸入非數字的字元");
textField_1.setText("請勿輸入非數字的字元");
textField_2.setText("請勿輸入非數字的字元");
textField_3.setText("請勿輸入非數字的字元");
textField_4.setText("請勿輸入非數字的字元");
}
}
});
answer.setBounds(139, 294, 437, 21);
frame.getContentPane().add(answer);
answer.setColumns(10);
label_5 = new JLabel("\u8ACB\u8F38\u5165\u9700\u63DB\u7B97\u4E4B\u91D1\u984D");
label_5.setBounds(10, 297, 119, 15);
frame.getContentPane().add(label_5);
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2