package mymember.main;
import java.awt.EventQueue;
import java.awt.event.*;
import java.sql.*;
import java.util.List;
import javax.swing.*;
import mymember.dao.*;
import mymember.tools.*;
import mymember.vo.*;
public class MyGUIMain extends MyMemberSkin {
MyMemberDAO dao = new MyMemberDAO();
JTextField[] jtfs = new JTextField[] { textFieldId, textFieldName,
textFieldPassword, textFieldRemark };
public MyGUIMain() {
MyDaoGuiTools.setTable(table, jtfs, "select * from mymember");
btnInsert.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
MyMemberVO vo = new MyMemberVO();
vo.setId(textFieldId.getText());
vo.setName(textFieldName.getText());
vo.setPassword(textFieldPassword.getText());
vo.setRemark(textFieldRemark.getText());
try {
boolean insertOk = dao.insert(vo);
if (insertOk) {
JOptionPane.showMessageDialog(MyGUIMain.this,
"잘입력했습니다.");
MyDaoGuiTools.setTable(table, jtfs,
"select * from mymember");
} else {
JOptionPane.showMessageDialog(MyGUIMain.this,
"입력되지 않았어요");
}
} catch (SQLException e) {
e.printStackTrace();
}
}
});
btnDelete.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String id = textFieldId.getText();
try {
boolean deleteOk = dao.delete(id);
if (deleteOk) {
JOptionPane
.showMessageDialog(MyGUIMain.this, "잘지웠습니다.");
MyDaoGuiTools.setTable(table, jtfs,
"select * from mymember");
} else {
JOptionPane.showMessageDialog(MyGUIMain.this, "못지웠어요");
}
} catch (SQLException e1) {
e1.printStackTrace();
}
}
});
btnUpdate.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
MyMemberVO vo = new MyMemberVO();
vo.setId(textFieldId.getText());
vo.setName(textFieldName.getText());
vo.setPassword(textFieldPassword.getText());
vo.setRemark(textFieldRemark.getText());
try {
boolean updateOk = dao.update(vo);
if (updateOk) {
JOptionPane.showMessageDialog(MyGUIMain.this,
"잘수정했습니다.");
MyDaoGuiTools.setTable(table, jtfs,
"select * from mymember");
} else {
JOptionPane.showMessageDialog(MyGUIMain.this,
"수정못했습니다.");
}
} catch (SQLException e) {
e.printStackTrace();
}
}
});
btnFind.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String id = textFieldId.getText();
if (id == null || id.equals("")) {
MyDaoGuiTools.setTable(table, jtfs,
"select * from mymember");
clear();
} else {
List<MyMemberVO> list = null;
try {
list = dao.select(id);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
MyMemberVO vo = null;
try {
vo = list.get(0);
} catch (Exception e1) {
JOptionPane.showMessageDialog(null, "자료를 못찾겠습니다.");
return;
}
textFieldName.setText(vo.getName());
textFieldPassword.setText(vo.getPassword());
textFieldRemark.setText(vo.getRemark());
MyDaoGuiTools.setTable(table, jtfs,
"select * from mymember where id='" + id + "'");
}
}
});
btnClear.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
clear();
}
});
}
private void clear() {
for (int i = 0; i < jtfs.length; i++) {
jtfs[i].setText(null);
}
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MyGUIMain frame = new MyGUIMain();
// MyDaoGuiTools.toMcUI(frame);
MyDaoGuiTools.toMcUI(frame);
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
select 부분과 find 부분만 주석이 좀 필요합니다
사용할려고보니 이해가 잘 안되서요...
죄송스럽지만 최대한 자세하게 주석 달아주세요 부탁드립니다