001.
package
com.java.myapp;
002.
003.
import
javax.swing.JDialog;
004.
import
javax.swing.JLabel;
005.
import
javax.swing.JButton;
006.
import
java.awt.event.ActionListener;
007.
import
java.awt.event.ActionEvent;
008.
import
java.sql.Connection;
009.
import
java.sql.DriverManager;
010.
import
java.sql.ResultSet;
011.
import
java.sql.SQLException;
012.
import
java.sql.Statement;
013.
import
javax.swing.JOptionPane;
014.
015.
public
class
MyDetail
extends
JDialog {
016.
017.
018.
019.
020.
public
MyDetail(String sCustomerID) {
021.
setTitle(
"ThaiCreate.Com Java GUI Tutorial"
);
022.
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
023.
setBounds(
100
,
100
,
385
,
266
);
024.
getContentPane().setLayout(
null
);
025.
setResizable(
false
);
026.
027.
028.
JLabel hCustomerDetail =
new
JLabel(
"Customer Details"
);
029.
hCustomerDetail.setBounds(
144
,
21
,
132
,
14
);
030.
getContentPane().add(hCustomerDetail);
031.
032.
033.
JLabel hCustomerID =
new
JLabel(
"CustomerID :"
);
034.
hCustomerID.setBounds(
100
,
51
,
89
,
14
);
035.
getContentPane().add(hCustomerID);
036.
037.
JLabel hName =
new
JLabel(
"Name :"
);
038.
hName.setBounds(
100
,
76
,
89
,
14
);
039.
getContentPane().add(hName);
040.
041.
JLabel hEmail =
new
JLabel(
"Email :"
);
042.
hEmail.setBounds(
100
,
100
,
89
,
14
);
043.
getContentPane().add(hEmail);
044.
045.
JLabel hCountryCode =
new
JLabel(
"CountryCode :"
);
046.
hCountryCode.setBounds(
100
,
123
,
89
,
14
);
047.
getContentPane().add(hCountryCode);
048.
049.
JLabel hBudget =
new
JLabel(
"Budget :"
);
050.
hBudget.setBounds(
100
,
146
,
89
,
14
);
051.
getContentPane().add(hBudget);
052.
053.
JLabel hUsed =
new
JLabel(
"Used :"
);
054.
hUsed.setBounds(
100
,
171
,
89
,
14
);
055.
getContentPane().add(hUsed);
056.
057.
058.
JLabel lblCustomerID =
new
JLabel(
"lblCustomerID"
);
059.
lblCustomerID.setBounds(
207
,
51
,
89
,
14
);
060.
getContentPane().add(lblCustomerID);
061.
062.
JLabel lblName =
new
JLabel(
"lblName"
);
063.
lblName.setBounds(
207
,
76
,
89
,
14
);
064.
getContentPane().add(lblName);
065.
066.
JLabel lblEmail =
new
JLabel(
"lblEmail"
);
067.
lblEmail.setBounds(
207
,
100
,
162
,
14
);
068.
getContentPane().add(lblEmail);
069.
070.
JLabel lblCountryCode =
new
JLabel(
"lblCountryCode"
);
071.
lblCountryCode.setBounds(
207
,
123
,
89
,
14
);
072.
getContentPane().add(lblCountryCode);
073.
074.
JLabel lblBudget =
new
JLabel(
"lblBudget"
);
075.
lblBudget.setBounds(
207
,
146
,
89
,
14
);
076.
getContentPane().add(lblBudget);
077.
078.
JLabel lblUsed =
new
JLabel(
"lblUsed"
);
079.
lblUsed.setBounds(
207
,
171
,
89
,
14
);
080.
getContentPane().add(lblUsed);
081.
082.
083.
Connection connect =
null
;
084.
Statement s =
null
;
085.
086.
try
{
087.
Class.forName(
"com.mysql.jdbc.Driver"
);
088.
090.
"?user=root&password=root"
);
091.
092.
s = connect.createStatement();
093.
094.
String sql =
"SELECT * FROM customer "
+
095.
"WHERE CustomerID = '"
+ sCustomerID +
"' "
;
096.
097.
ResultSet rec = s.executeQuery(sql);
098.
099.
if
(rec !=
null
) {
100.
rec.next();
101.
lblCustomerID.setText(rec.getString(
"CustomerID"
));
102.
lblName.setText(rec.getString(
"Name"
));
103.
lblEmail.setText(rec.getString(
"Email"
));
104.
lblCountryCode.setText(rec.getString(
"CountryCode"
));
105.
lblBudget.setText(rec.getString(
"Budget"
));
106.
lblUsed.setText(rec.getString(
"Used"
));
107.
}
108.
rec.close();
109.
110.
}
catch
(Exception e) {
111.
112.
JOptionPane.showMessageDialog(
null
, e.getMessage());
113.
e.printStackTrace();
114.
}
115.
116.
try
{
117.
if
(s !=
null
) {
118.
s.close();
119.
connect.close();
120.
}
121.
}
catch
(SQLException e) {
122.
123.
System.out.println(e.getMessage());
124.
e.printStackTrace();
125.
}
126.
127.
128.
129.
130.
JButton btnClose =
new
JButton(
"Close"
);
131.
btnClose.addActionListener(
new
ActionListener() {
132.
public
void
actionPerformed(ActionEvent arg0) {
133.
dispose();
134.
}
135.
});
136.
btnClose.setBounds(
161
,
204
,
69
,
23
);
137.
getContentPane().add(btnClose);
138.
139.
}
140.
141.
}