01.
package
com.java.myapp;
02.
03.
import
java.awt.EventQueue;
04.
05.
import
javax.swing.JButton;
06.
import
javax.swing.JFrame;
07.
import
java.awt.event.ActionListener;
08.
import
java.awt.event.ActionEvent;
09.
import
javax.swing.JTextField;
10.
import
javax.swing.JLabel;
11.
12.
13.
public
class
MyForm
extends
JFrame {
14.
15.
16.
17.
18.
public
static
void
main(String[] args) {
19.
EventQueue.invokeLater(
new
Runnable() {
20.
public
void
run() {
21.
MyForm frame =
new
MyForm();
22.
frame.setVisible(
true
);
23.
}
24.
});
25.
}
26.
27.
28.
29.
30.
public
MyForm() {
31.
32.
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
33.
setBounds(
100
,
100
,
362
,
249
);
34.
setTitle(
"ThaiCreate.Com Java GUI Tutorial"
);
35.
getContentPane().setLayout(
null
);
36.
37.
38.
final
JTextField txt =
new
JTextField();
39.
txt.setBounds(
103
,
41
,
144
,
20
);
40.
getContentPane().add(txt);
41.
txt.setColumns(
10
);
42.
43.
44.
final
JLabel lbl =
new
JLabel(
"Result"
);
45.
lbl.setBounds(
103
,
120
,
144
,
14
);
46.
getContentPane().add(lbl);
47.
48.
49.
JButton btn1 =
new
JButton(
"Button 1"
);
50.
btn1.addActionListener(
new
ActionListener() {
51.
public
void
actionPerformed(ActionEvent e) {
52.
lbl.setText(
"Hello : "
+ txt.getText());
53.
}
54.
});
55.
btn1.setBounds(
128
,
72
,
99
,
23
);
56.
getContentPane().add(btn1);
57.
58.
}
59.
}