01.package com.java.myapp;
02.
03.import java.awt.EventQueue;
04.
05.import javax.swing.JFrame;
06.import javax.swing.JLabel;
07.import javax.swing.JOptionPane;
08.import javax.swing.JTextField;
09.import javax.swing.JButton;
10.import java.awt.event.ActionListener;
11.import java.awt.event.ActionEvent;
12.
13.public class MyWindowsForm {
14.
15.private JFrame frame;
16.private JTextField txtName;
17.
18.
19.
20.
21.public static void main(String[] args) {
22.EventQueue.invokeLater(new Runnable() {
23.public void run() {
24.try {
25.MyWindowsForm window = new MyWindowsForm();
26.window.frame.setVisible(true);
27.} catch (Exception e) {
28.e.printStackTrace();
29.}
30.}
31.});
32.}
33.
34.
35.
36.
37.public MyWindowsForm() {
38.initialize();
39.}
40.
41.
42.
43.
44.private void initialize() {
45.frame = new JFrame();
46.frame.setBounds(100, 100, 450, 300);
47.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
48.frame.getContentPane().setLayout(null);
49.
50.JLabel lblPleaseInputYour = new JLabel("Please input your name :");
51.lblPleaseInputYour.setBounds(158, 54, 130, 14);
52.frame.getContentPane().add(lblPleaseInputYour);
53.
54.txtName = new JTextField();
55.txtName.setBounds(121, 79, 180, 20);
56.frame.getContentPane().add(txtName);
57.txtName.setColumns(10);
58.
59.JButton btnClick = new JButton("Click");
60.btnClick.addActionListener(new ActionListener() {
61.public void actionPerformed(ActionEvent arg0) {
62.
63.JOptionPane.showMessageDialog(frame,"Sawatdee : " + txtName.getText());
64.
65.}
66.});
67.
68.
69.btnClick.setBounds(170, 125, 89, 23);
70.frame.getContentPane().add(btnClick);
71.}
72.}