你好,各位大神,我卡关了,当我删除所选列时,并按下删除按钮,Jtable确实是把该列删了,但当我再次开启时,其删除列并没有删除,我想原因是其变动并没有储存进数据库,请问各位大神具体实作方式要怎麽做?
我是用MVC去实作的,数据库使用Sqlite,另外想请问各位大神当我要做修改的动作时,按下修改钮时,Jtable可以进行修改,且储存进资料库,想请问各位大神具体实作方式是怎麽实现?
//以下为Model
package model;
import java.sql.*;
import entities.*;
import java.util.*;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
public class ClientModel extends AbstractTableModel {
private List<Client> listClient = new ArrayList<Client>();
//Search all data
public List<Client> findAll() {
List<Client> listClient = new ArrayList<>();
try {
PreparedStatement ps = ConnectDB.getConn().prepareStatement("select * from client");
ResultSet rs = ps.executeQuery();
while (rs.next()) {
Client c = new Client();
c.setCategory(rs.getString("category"));
c.setOrganization(rs.getString("organization"));
c.setName(rs.getString("name"));
c.setNo(rs.getInt("no"));
c.setZip(rs.getString("zip"));
c.setAddress(rs.getString("address"));
c.setCellnumber(rs.getString("cellnumber"));
c.setFax(rs.getString("fax"));
c.setEmail(rs.getString("email"));
c.setBirthday(rs.getDate("birthday"));
listClient.add(c);
}
return listClient;
} catch (Exception e) {
e.printStackTrace();
System.out.println(e);
return null;
}
}
//Search data
public Client find(int no) {
Client c = null;
try {
PreparedStatement ps = ConnectDB.getConn().prepareStatement("select * from client" + "where category = ?, where organization = ?"
+ "where name = ?, where no = ?, where zip = ?, where address = ?, where landline = ?, where cellnumber = ?, where fax = ?, where email = ?, where birthday = ?");
ResultSet rs = ps.executeQuery();
while (rs.next()) {
c = new Client();
c.setCategory(rs.getString("category"));
c.setOrganization(rs.getString("organization"));
c.setName(rs.getString("name"));
c.setNo(rs.getInt("no"));
c.setZip(rs.getString("zip"));
c.setAddress(rs.getString("address"));
c.setCellnumber(rs.getString("cellnumber"));
c.setFax(rs.getString("fax"));
c.setEmail(rs.getString("email"));
c.setBirthday(rs.getDate("birthday"));
}
} catch (Exception e) {
c = null;
}
return c;
}
//add data
public boolean create(Client client) {
boolean result = true;
try {
PreparedStatement ps = ConnectDB.getConn().prepareStatement(
"insert into client(category, organization, name, no, zip, address, cellnumber, fax, email, birthday) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
ps.setString(1, client.getCategory());
ps.setString(2, client.getOrganization());
ps.setString(3, client.getName());
ps.setInt(4, client.getNo());
ps.setString(5, client.getZip());
ps.setString(6, client.getAddress());
ps.setString(7, client.getCellnumber());
ps.setString(8, client.getFax());
ps.setString(9, client.getEmail());
ps.setDate(10, new java.sql.Date(client.getBirthday().getTime()));
result = ps.executeUpdate() > 0;
} catch (Exception e) {
result = false;
}
return result;
}
// delete data
public void removeSelectedFromTable(JTable clientTable) {
int[] rows = clientTable.getSelectedRows();
TableModel tm = (DefaultTableModel) clientTable.getModel();
for (int row : rows) {
((DefaultTableModel) tm).removeRow(clientTable.convertRowIndexToModel(row));
}
clientTable.setModel(tm);
}
package model;
import java.sql.*;
public class ConnectDB {
private static Connection connection = null;
public static Connection getConn() {
try {
Class.forName("org.sqlite.JDBC");
System.out.println("驅動載入成功");
connection = DriverManager.getConnection("jdbc:sqlite:D:\\work\\sileai2\\sileai_db\\sileai.db");
System.out.println("連接到資料庫");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return connection;
}
public static void closeConn() {
try {
if (connection != null) {
connection.close();
}
connection = null;
} catch (Exception e) {
e.printStackTrace();
}
}
}
//以下为Entities
package entities;
import java.text.SimpleDateFormat;
import java.util.*;
public class Client {
private String category;
private String organization;
private String name;
private int no;
private String zip;
private String address;
private String cellnumber;
private String fax;
private String email;
private Date birthday;
public Client(String category, String organization, String name, int no, String zip, String address,
String landline, String cellnumber, String fax, String email, Date birthday) {
super();
this.category = category;
this.organization = organization;
this.name = name;
this.no = no;
this.zip = zip;
this.address = address;
this.cellnumber = cellnumber;
this.fax = fax;
this.email = email;
this.birthday = birthday;
}
public Client() {
super();
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getOrganization() {
return organization;
}
public void setOrganization(String organization) {
this.organization = organization;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getNo() {
return no;
}
public void setNo(int no) {
this.no = no;
}
public String getZip() {
return zip;
}
public void setZip(String zip) {
this.zip = zip;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getLandline() {
return landline;
}
public void setLandline(String landline) {
this.landline = landline;
}
public String getCellnumber() {
return cellnumber;
}
public void setCellnumber(String cellnumber) {
this.cellnumber = cellnumber;
}
public String getFax() {
return fax;
}
public void setFax(String fax) {
this.fax = fax;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
}
//以下为demo
package demo;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import java.util.*;
import java.text.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.border.LineBorder;
import com.toedter.calendar.JCalendar;
import com.toedter.calendar.JDayChooser;
import com.toedter.components.JSpinField;
import model.*;
import entities.*;
import com.toedter.components.JLocaleChooser;
import com.toedter.calendar.JDateChooser;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.beans.*;
@SuppressWarnings("serial")
public class SileaiFrame extends JFrame {
// 宣告
private ClientModel cm = new ClientModel();
private JPanel contentPane;
private JTable jfta_ResultTable;
private JTabbedPane jftp_0;
private JLayeredPane clientLayeredPane;
private JTextField organizationTextField;
private JTextField addressTextField;
private JTextField nameTextField;
private JLabel organizationLabel;
private JLabel nameLabel;
private JLabel addressLabel;
private JScrollPane clientScrollPane;
private JLabel categoryLabel;
private JLayeredPane jflp_1;
private JTabbedPane jftp_10;
private JLayeredPane jflp_10;
private JLayeredPane jflp_11;
private JLayeredPane jflp_3;
private JComboBox DeliveryComboBox;
private JLayeredPane activityLayeredPane;
private JLabel ActivityDatelabel;
private JLabel label_1;
private JComboBox comboBox_3;
private JLabel label_2;
private JComboBox comboBox_4;
private JLabel label_3;
private JTextField textField;
private JLabel label_4;
private JTextArea textArea;
private JLabel label_5;
private JTextField textField_1;
private JLabel label_6;
private JTextArea textArea_1;
private JButton button;
private JButton button_1;
private JLabel label_7;
private JTextField textField_2;
private JButton btnNewButton;
private JButton btnNewButton_1;
private JLabel label_13;
private JLabel noLabel;
private JTextField noTextField;
private JLabel landlineLabel;
private JTextField landlineTextField;
private JLabel cellnumberLabel;
private JLabel faxLabel;
private JTextField cellnumberTextField;
private JLabel emailLabel;
private JLabel zipLabel;
private JTextField zipTextField;
private JTextField emailTextField;
private JLabel Label;
private JComboBox categoryComboBox;
private JMenuBar exportMenuBar;
private JMenu exportMenu;
private JMenuItem pdfMenuItem;
private JMenuItem csvMenuItem;
private JTextField faxTextField;
private JCalendar calendar;
private JDateChooser search1DateChooser;
private JLabel label;
private JDateChooser dateChooser_3;
private JDateChooser dateChooser_4;
private JTable clientTable;
private JLayeredPane searchLayeredPane;
private JButton readButton;
private JButton deleteButton;
private JButton updateButton;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
SileaiFrame Jframe = new SileaiFrame();
Jframe.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
System.out.print(e);
}
}
});
}
/**
* Create the frame.
*
* @throws ParseException
*/
@SuppressWarnings("rawtypes")
// Swing主體
public SileaiFrame() throws ParseException {
setTitle("資料管理系統");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 793, 477);
exportMenuBar = new JMenuBar();
setJMenuBar(exportMenuBar);
exportMenu = new JMenu("匯出");
exportMenuBar.add(exportMenu);
pdfMenuItem = new JMenuItem("PDF");
exportMenu.add(pdfMenuItem);
csvMenuItem = new JMenuItem("CSV");
exportMenu.add(csvMenuItem);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
jftp_0 = new JTabbedPane(JTabbedPane.TOP);
contentPane.add(jftp_0, BorderLayout.CENTER);
jfta_ResultTable = new JTable();
clientLayeredPane = new JLayeredPane();
jftp_0.addTab("基本資料", null, clientLayeredPane, null);
GridBagLayout gbl_clientLayeredPane = new GridBagLayout();
gbl_clientLayeredPane.columnWidths = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
gbl_clientLayeredPane.rowHeights = new int[] { 0, 0, 0, 0, 0, 0, 0 };
gbl_clientLayeredPane.columnWeights = new double[] { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0,
Double.MIN_VALUE };
gbl_clientLayeredPane.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE };
clientLayeredPane.setLayout(gbl_clientLayeredPane);
categoryLabel = new JLabel("類別");
GridBagConstraints gbc_categoryLabel = new GridBagConstraints();
gbc_categoryLabel.insets = new Insets(0, 0, 5, 5);
gbc_categoryLabel.gridx = 0;
gbc_categoryLabel.gridy = 0;
clientLayeredPane.add(categoryLabel, gbc_categoryLabel);
categoryComboBox = new JComboBox();
categoryComboBox.setEditable(true);
categoryComboBox.setModel(new DefaultComboBoxModel(new String[] { "活動", "捐物", "捐款", "會員", "客戶", "廠商", "政商" }));
GridBagConstraints gbc_categoryComboBox = new GridBagConstraints();
gbc_categoryComboBox.fill = GridBagConstraints.HORIZONTAL;
gbc_categoryComboBox.insets = new Insets(0, 0, 5, 5);
gbc_categoryComboBox.gridx = 1;
gbc_categoryComboBox.gridy = 0;
clientLayeredPane.add(categoryComboBox, gbc_categoryComboBox);
organizationLabel = new JLabel("單位");
GridBagConstraints gbc_organizationLabel = new GridBagConstraints();
gbc_organizationLabel.insets = new Insets(0, 0, 5, 5);
gbc_organizationLabel.gridx = 2;
gbc_organizationLabel.gridy = 0;
clientLayeredPane.add(organizationLabel, gbc_organizationLabel);
organizationTextField = new JTextField();
GridBagConstraints gbc_organizationTextField = new GridBagConstraints();
gbc_organizationTextField.fill = GridBagConstraints.HORIZONTAL;
gbc_organizationTextField.insets = new Insets(0, 0, 5, 5);
gbc_organizationTextField.gridx = 3;
gbc_organizationTextField.gridy = 0;
clientLayeredPane.add(organizationTextField, gbc_organizationTextField);
organizationTextField.setColumns(10);
nameLabel = new JLabel("客戶姓名");
GridBagConstraints gbc_nameLabel = new GridBagConstraints();
gbc_nameLabel.insets = new Insets(0, 0, 5, 5);
gbc_nameLabel.gridx = 4;
gbc_nameLabel.gridy = 0;
clientLayeredPane.add(nameLabel, gbc_nameLabel);
nameTextField = new JTextField();
GridBagConstraints gbc_nameTextField = new GridBagConstraints();
gbc_nameTextField.fill = GridBagConstraints.HORIZONTAL;
gbc_nameTextField.insets = new Insets(0, 0, 5, 5);
gbc_nameTextField.gridx = 5;
gbc_nameTextField.gridy = 0;
clientLayeredPane.add(nameTextField, gbc_nameTextField);
nameTextField.setColumns(10);
noLabel = new JLabel("客戶代號");
GridBagConstraints gbc_noLabel = new GridBagConstraints();
gbc_noLabel.insets = new Insets(0, 0, 5, 5);
gbc_noLabel.gridx = 6;
gbc_noLabel.gridy = 0;
clientLayeredPane.add(noLabel, gbc_noLabel);
noTextField = new JTextField();
GridBagConstraints gbc_noTextField = new GridBagConstraints();
gbc_noTextField.insets = new Insets(0, 0, 5, 5);
gbc_noTextField.fill = GridBagConstraints.HORIZONTAL;
gbc_noTextField.gridx = 7;
gbc_noTextField.gridy = 0;
clientLayeredPane.add(noTextField, gbc_noTextField);
noTextField.setColumns(10);
zipLabel = new JLabel("郵區");
GridBagConstraints gbc_zipLabel = new GridBagConstraints();
gbc_zipLabel.insets = new Insets(0, 0, 5, 5);
gbc_zipLabel.gridx = 0;
gbc_zipLabel.gridy = 1;
clientLayeredPane.add(zipLabel, gbc_zipLabel);
zipTextField = new JTextField();
GridBagConstraints gbc_zipTextField = new GridBagConstraints();
gbc_zipTextField.insets = new Insets(0, 0, 5, 5);
gbc_zipTextField.fill = GridBagConstraints.HORIZONTAL;
gbc_zipTextField.gridx = 1;
gbc_zipTextField.gridy = 1;
clientLayeredPane.add(zipTextField, gbc_zipTextField);
zipTextField.setColumns(10);
addressLabel = new JLabel("地址");
GridBagConstraints gbc_addressLabel = new GridBagConstraints();
gbc_addressLabel.insets = new Insets(0, 0, 5, 5);
gbc_addressLabel.gridx = 2;
gbc_addressLabel.gridy = 1;
clientLayeredPane.add(addressLabel, gbc_addressLabel);
addressTextField = new JTextField();
GridBagConstraints gbc_addressTextField = new GridBagConstraints();
gbc_addressTextField.fill = GridBagConstraints.HORIZONTAL;
gbc_addressTextField.gridwidth = 2;
gbc_addressTextField.insets = new Insets(0, 0, 5, 5);
gbc_addressTextField.gridx = 3;
gbc_addressTextField.gridy = 1;
clientLayeredPane.add(addressTextField, gbc_addressTextField);
addressTextField.setColumns(10);
landlineLabel = new JLabel("市話");
GridBagConstraints gbc_landlineLabel = new GridBagConstraints();
gbc_landlineLabel.insets = new Insets(0, 0, 5, 5);
gbc_landlineLabel.gridx = 5;
gbc_landlineLabel.gridy = 1;
clientLayeredPane.add(landlineLabel, gbc_landlineLabel);
landlineTextField = new JTextField();
GridBagConstraints gbc_landlineTextField = new GridBagConstraints();
gbc_landlineTextField.gridwidth = 2;
gbc_landlineTextField.insets = new Insets(0, 0, 5, 5);
gbc_landlineTextField.fill = GridBagConstraints.HORIZONTAL;
gbc_landlineTextField.gridx = 6;
gbc_landlineTextField.gridy = 1;
clientLayeredPane.add(landlineTextField, gbc_landlineTextField);
landlineTextField.setColumns(10);
cellnumberLabel = new JLabel("手機");
GridBagConstraints gbc_cellnumberLabel = new GridBagConstraints();
gbc_cellnumberLabel.insets = new Insets(0, 0, 5, 5);
gbc_cellnumberLabel.gridx = 0;
gbc_cellnumberLabel.gridy = 2;
clientLayeredPane.add(cellnumberLabel, gbc_cellnumberLabel);
cellnumberTextField = new JTextField();
cellnumberTextField.setColumns(10);
GridBagConstraints gbc_cellnumberTextField = new GridBagConstraints();
gbc_cellnumberTextField.fill = GridBagConstraints.HORIZONTAL;
gbc_cellnumberTextField.anchor = GridBagConstraints.WEST;
gbc_cellnumberTextField.insets = new Insets(0, 0, 5, 5);
gbc_cellnumberTextField.gridx = 1;
gbc_cellnumberTextField.gridy = 2;
clientLayeredPane.add(cellnumberTextField, gbc_cellnumberTextField);
faxLabel = new JLabel("傳真");
GridBagConstraints gbc_faxLabel = new GridBagConstraints();
gbc_faxLabel.insets = new Insets(0, 0, 5, 5);
gbc_faxLabel.gridx = 2;
gbc_faxLabel.gridy = 2;
clientLayeredPane.add(faxLabel, gbc_faxLabel);
faxTextField = new JTextField();
GridBagConstraints gbc_faxTextField = new GridBagConstraints();
gbc_faxTextField.insets = new Insets(0, 0, 5, 5);
gbc_faxTextField.fill = GridBagConstraints.HORIZONTAL;
gbc_faxTextField.gridx = 3;
gbc_faxTextField.gridy = 2;
clientLayeredPane.add(faxTextField, gbc_faxTextField);
faxTextField.setColumns(10);
emailLabel = new JLabel("信箱");
GridBagConstraints gbc_emailLabel = new GridBagConstraints();
gbc_emailLabel.insets = new Insets(0, 0, 5, 5);
gbc_emailLabel.gridx = 4;
gbc_emailLabel.gridy = 2;
clientLayeredPane.add(emailLabel, gbc_emailLabel);
emailTextField = new JTextField();
GridBagConstraints gbc_emailTextField = new GridBagConstraints();
gbc_emailTextField.insets = new Insets(0, 0, 5, 5);
gbc_emailTextField.fill = GridBagConstraints.HORIZONTAL;
gbc_emailTextField.gridx = 5;
gbc_emailTextField.gridy = 2;
clientLayeredPane.add(emailTextField, gbc_emailTextField);
emailTextField.setColumns(10);
Label = new JLabel("生日");
GridBagConstraints gbc_Label = new GridBagConstraints();
gbc_Label.insets = new Insets(0, 0, 5, 5);
gbc_Label.gridx = 0;
gbc_Label.gridy = 3;
clientLayeredPane.add(Label, gbc_Label);
JDateChooser birthdayDateChooser = new JDateChooser();
birthdayDateChooser.setDateFormatString("yyyy-MM-dd");
GridBagConstraints gbc_birthdayDateChooser = new GridBagConstraints();
gbc_birthdayDateChooser.fill = GridBagConstraints.HORIZONTAL;
birthdayDateChooser.setBounds(20, 20, 200, 20);
gbc_birthdayDateChooser.insets = new Insets(0, 0, 5, 5);
gbc_birthdayDateChooser.gridx = 1;
gbc_birthdayDateChooser.gridy = 3;
clientLayeredPane.add(birthdayDateChooser, gbc_birthdayDateChooser);
label = new JLabel("~");
GridBagConstraints gbc_label = new GridBagConstraints();
gbc_label.insets = new Insets(0, 0, 5, 5);
gbc_label.gridx = 2;
gbc_label.gridy = 3;
clientLayeredPane.add(label, gbc_label);
search1DateChooser = new JDateChooser();
GridBagConstraints gbc_search1DateChooser = new GridBagConstraints();
gbc_search1DateChooser.fill = GridBagConstraints.HORIZONTAL;
gbc_search1DateChooser.insets = new Insets(0, 0, 5, 5);
gbc_search1DateChooser.gridx = 3;
gbc_search1DateChooser.gridy = 3;
clientLayeredPane.add(search1DateChooser, gbc_search1DateChooser);
JButton createButton = new JButton("新增");
createButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Client c = new Client();
if (!noTextField.getText().trim().equals("")) {
c.setCategory(categoryComboBox.getSelectedItem().toString());
c.setOrganization(organizationTextField.getText());
c.setName(nameTextField.getText());
c.setNo(Integer.parseInt(noTextField.getText()));
c.setZip(zipTextField.getText());
c.setAddress(addressTextField.getText());
c.setCellnumber(cellnumberTextField.getText());
c.setEmail(emailTextField.getText());
c.setFax(faxTextField.getText());
c.setBirthday(birthdayDateChooser.getDate());
if (cm.create(c)) {
JOptionPane.showMessageDialog(null, "新增客戶資料成功");
LoadData();
} else
JOptionPane.showMessageDialog(null, "新增客戶資料失敗");
} else {
JOptionPane.showMessageDialog(null, "客戶編號不得為空");
}
}
});
GridBagConstraints gbc_createButton = new GridBagConstraints();
gbc_createButton.insets = new Insets(0, 0, 5, 5);
gbc_createButton.gridx = 4;
gbc_createButton.gridy = 4;
clientLayeredPane.add(createButton, gbc_createButton);
readButton = new JButton("查詢");
readButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
}
});
GridBagConstraints gbc_readButton = new GridBagConstraints();
gbc_readButton.insets = new Insets(0, 0, 5, 5);
gbc_readButton.gridx = 5;
gbc_readButton.gridy = 4;
clientLayeredPane.add(readButton, gbc_readButton);
deleteButton = new JButton("刪除");
deleteButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
cm.removeSelectedFromTable(clientTable);
categoryComboBox.setSelectedItem("");
organizationTextField.setText("");
nameTextField.setText("");
noTextField.setText("");
zipTextField.setText("");
addressTextField.setText("");
cellnumberTextField.setText("");
faxTextField.setText("");
emailTextField.setText("");
birthdayDateChooser.setDate(null);
}
});
GridBagConstraints gbc_deleteButton = new GridBagConstraints();
gbc_deleteButton.insets = new Insets(0, 0, 5, 5);
gbc_deleteButton.gridx = 6;
gbc_deleteButton.gridy = 4;
clientLayeredPane.add(deleteButton, gbc_deleteButton);
updateButton = new JButton("修改");
updateButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
DefaultTableModel dtm = (DefaultTableModel) clientTable.getModel();
//Client c = new Client();
//if (cm.edit(c)) {
cm.editSelectedFromTable(clientTable);
categoryComboBox.getSelectedItem().toString();
organizationTextField.getText();
nameTextField.getText();
Integer.parseInt(noTextField.getText());
zipTextField.getText();
addressTextField.getText();
cellnumberTextField.getText();
emailTextField.getText();
faxTextField.getText();
birthdayDateChooser.getDate();
}
});
GridBagConstraints gbc_updateButton = new GridBagConstraints();
gbc_updateButton.insets = new Insets(0, 0, 5, 5);
gbc_updateButton.gridx = 7;
gbc_updateButton.gridy = 4;
clientLayeredPane.add(updateButton, gbc_updateButton);
clientScrollPane = new JScrollPane();
GridBagConstraints gbc_clientScrollPane = new GridBagConstraints();
gbc_clientScrollPane.gridwidth = 9;
gbc_clientScrollPane.fill = GridBagConstraints.BOTH;
gbc_clientScrollPane.gridx = 0;
gbc_clientScrollPane.gridy = 5;
clientLayeredPane.add(clientScrollPane, gbc_clientScrollPane);
clientTable = new JTable();
clientTable.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
categoryComboBox.setSelectedItem(clientTable.getValueAt(clientTable.getSelectedRow(), 0).toString());
organizationTextField.setText(clientTable.getValueAt(clientTable.getSelectedRow(), 1).toString());
nameTextField.setText(clientTable.getValueAt(clientTable.getSelectedRow(), 2).toString());
noTextField.setText(clientTable.getValueAt(clientTable.getSelectedRow(), 3).toString());
zipTextField.setText(clientTable.getValueAt(clientTable.getSelectedRow(), 4).toString());
addressTextField.setText(clientTable.getValueAt(clientTable.getSelectedRow(), 5).toString());
landlineTextField.setText(clientTable.getValueAt(clientTable.getSelectedRow(), 6).toString());
cellnumberTextField.setText(clientTable.getValueAt(clientTable.getSelectedRow(), 7).toString());
faxTextField.setText(clientTable.getValueAt(clientTable.getSelectedRow(), 8).toString());
emailTextField.setText(clientTable.getValueAt(clientTable.getSelectedRow(), 9).toString());
birthdayDateChooser.setDate((java.util.Date) clientTable.getValueAt(clientTable.getSelectedRow(), 10));
}
});
clientScrollPane.setViewportView(clientTable);
LoadData();
activityLayeredPane = new JLayeredPane();
jftp_0.addTab("活動紀錄", null, activityLayeredPane, null);
activityLayeredPane.setForeground(Color.GRAY);
activityLayeredPane.setBackground(SystemColor.menu);
GridBagLayout gbl_activityLayeredPane = new GridBagLayout();
gbl_activityLayeredPane.columnWidths = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
gbl_activityLayeredPane.rowHeights = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
gbl_activityLayeredPane.columnWeights = new double[] { 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0 };
gbl_activityLayeredPane.rowWeights = new double[] { 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0,
Double.MIN_VALUE };
activityLayeredPane.setLayout(gbl_activityLayeredPane);
activityLayeredPane.setOpaque(true);
ActivityDatelabel = new JLabel("日期");
GridBagConstraints gbc_ActivityDatelabel = new GridBagConstraints();
gbc_ActivityDatelabel.insets = new Insets(0, 0, 5, 5);
gbc_ActivityDatelabel.gridx = 1;
gbc_ActivityDatelabel.gridy = 0;
activityLayeredPane.add(ActivityDatelabel, gbc_ActivityDatelabel);
dateChooser_3 = new JDateChooser();
GridBagConstraints gbc_dateChooser_3 = new GridBagConstraints();
gbc_dateChooser_3.insets = new Insets(0, 0, 5, 5);
gbc_dateChooser_3.fill = GridBagConstraints.HORIZONTAL;
gbc_dateChooser_3.gridx = 2;
gbc_dateChooser_3.gridy = 0;
activityLayeredPane.add(dateChooser_3, gbc_dateChooser_3);
label_5 = new JLabel("負責人員");
GridBagConstraints gbc_label_5 = new GridBagConstraints();
gbc_label_5.insets = new Insets(0, 0, 5, 5);
gbc_label_5.gridx = 3;
gbc_label_5.gridy = 0;
activityLayeredPane.add(label_5, gbc_label_5);
textField_1 = new JTextField();
GridBagConstraints gbc_textField_1 = new GridBagConstraints();
gbc_textField_1.fill = GridBagConstraints.HORIZONTAL;
gbc_textField_1.gridwidth = 2;
gbc_textField_1.insets = new Insets(0, 0, 5, 5);
gbc_textField_1.gridx = 4;
gbc_textField_1.gridy = 0;
activityLayeredPane.add(textField_1, gbc_textField_1);
textField_1.setColumns(10);
label_2 = new JLabel("參與方式");
GridBagConstraints gbc_label_2 = new GridBagConstraints();
gbc_label_2.insets = new Insets(0, 0, 5, 5);
gbc_label_2.gridx = 6;
gbc_label_2.gridy = 0;
activityLayeredPane.add(label_2, gbc_label_2);
comboBox_4 = new JComboBox();
GridBagConstraints gbc_comboBox_4 = new GridBagConstraints();
gbc_comboBox_4.fill = GridBagConstraints.HORIZONTAL;
gbc_comboBox_4.insets = new Insets(0, 0, 5, 5);
gbc_comboBox_4.gridx = 7;
gbc_comboBox_4.gridy = 0;
activityLayeredPane.add(comboBox_4, gbc_comboBox_4);
label_1 = new JLabel("活動類型");
GridBagConstraints gbc_label_1 = new GridBagConstraints();
gbc_label_1.insets = new Insets(0, 0, 5, 5);
gbc_label_1.gridx = 1;
gbc_label_1.gridy = 1;
activityLayeredPane.add(label_1, gbc_label_1);
comboBox_3 = new JComboBox();
GridBagConstraints gbc_comboBox_3 = new GridBagConstraints();
gbc_comboBox_3.fill = GridBagConstraints.HORIZONTAL;
gbc_comboBox_3.insets = new Insets(0, 0, 5, 5);
gbc_comboBox_3.gridx = 2;
gbc_comboBox_3.gridy = 1;
activityLayeredPane.add(comboBox_3, gbc_comboBox_3);
label_3 = new JLabel("活動名稱");
GridBagConstraints gbc_label_3 = new GridBagConstraints();
gbc_label_3.fill = GridBagConstraints.VERTICAL;
gbc_label_3.insets = new Insets(0, 0, 5, 5);
gbc_label_3.gridx = 1;
gbc_label_3.gridy = 2;
activityLayeredPane.add(label_3, gbc_label_3);
textField = new JTextField();
GridBagConstraints gbc_textField = new GridBagConstraints();
gbc_textField.insets = new Insets(0, 0, 5, 5);
gbc_textField.fill = GridBagConstraints.HORIZONTAL;
gbc_textField.gridx = 2;
gbc_textField.gridy = 2;
activityLayeredPane.add(textField, gbc_textField);
textField.setColumns(10);
textArea = new JTextArea();
GridBagConstraints gbc_textArea = new GridBagConstraints();
gbc_textArea.gridwidth = 4;
gbc_textArea.gridheight = 3;
gbc_textArea.insets = new Insets(0, 0, 5, 5);
gbc_textArea.fill = GridBagConstraints.BOTH;
gbc_textArea.gridx = 6;
gbc_textArea.gridy = 1;
activityLayeredPane.add(textArea, gbc_textArea);
label_4 = new JLabel("說明");
GridBagConstraints gbc_label_4 = new GridBagConstraints();
gbc_label_4.insets = new Insets(0, 0, 5, 5);
gbc_label_4.gridx = 5;
gbc_label_4.gridy = 2;
activityLayeredPane.add(label_4, gbc_label_4);
textArea_1 = new JTextArea();
GridBagConstraints gbc_textArea_1 = new GridBagConstraints();
gbc_textArea_1.gridheight = 3;
gbc_textArea_1.gridwidth = 3;
gbc_textArea_1.insets = new Insets(0, 0, 5, 5);
gbc_textArea_1.fill = GridBagConstraints.BOTH;
gbc_textArea_1.gridx = 2;
gbc_textArea_1.gridy = 3;
activityLayeredPane.add(textArea_1, gbc_textArea_1);
label_6 = new JLabel("備註");
GridBagConstraints gbc_label_6 = new GridBagConstraints();
gbc_label_6.insets = new Insets(0, 0, 5, 5);
gbc_label_6.gridx = 1;
gbc_label_6.gridy = 4;
activityLayeredPane.add(label_6, gbc_label_6);
button = new JButton("搜尋");
GridBagConstraints gbc_button = new GridBagConstraints();
gbc_button.insets = new Insets(0, 0, 5, 5);
gbc_button.gridx = 7;
gbc_button.gridy = 5;
activityLayeredPane.add(button, gbc_button);
button_1 = new JButton("新增");
GridBagConstraints gbc_button_1 = new GridBagConstraints();
gbc_button_1.insets = new Insets(0, 0, 5, 5);
gbc_button_1.gridx = 8;
gbc_button_1.gridy = 5;
activityLayeredPane.add(button_1, gbc_button_1);
JScrollPane scrollPane_1 = new JScrollPane();
GridBagConstraints gbc_scrollPane_1 = new GridBagConstraints();
gbc_scrollPane_1.gridheight = 4;
gbc_scrollPane_1.gridwidth = 8;
gbc_scrollPane_1.insets = new Insets(0, 0, 0, 5);
gbc_scrollPane_1.fill = GridBagConstraints.BOTH;
gbc_scrollPane_1.gridx = 2;
gbc_scrollPane_1.gridy = 6;
activityLayeredPane.add(scrollPane_1, gbc_scrollPane_1);
JTabbedPane tabbedPane_2 = new JTabbedPane(JTabbedPane.TOP);
scrollPane_1.setColumnHeaderView(tabbedPane_2);
label_7 = new JLabel("搜尋結果");
GridBagConstraints gbc_label_7 = new GridBagConstraints();
gbc_label_7.insets = new Insets(0, 0, 5, 5);
gbc_label_7.gridx = 1;
gbc_label_7.gridy = 7;
activityLayeredPane.add(label_7, gbc_label_7);
jflp_1 = new JLayeredPane();
jftp_0.addTab("交易資料", null, jflp_1, null);
jflp_1.setLayout(new BorderLayout(0, 0));
jftp_10 = new JTabbedPane(JTabbedPane.TOP);
jflp_1.add(jftp_10, BorderLayout.CENTER);
jflp_10 = new JLayeredPane();
jftp_10.addTab("查詢", null, jflp_10, null);
GridBagLayout gbl_jflp_10 = new GridBagLayout();
gbl_jflp_10.columnWidths = new int[] { 0, 0, 0, 0, 0 };
gbl_jflp_10.rowHeights = new int[] { 0, 0, 0, 0, 0 };
gbl_jflp_10.columnWeights = new double[] { 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE };
gbl_jflp_10.rowWeights = new double[] { 0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE };
jflp_10.setLayout(gbl_jflp_10);
jflp_11 = new JLayeredPane();
jftp_10.addTab("資料", null, jflp_11, null);
jflp_3 = new JLayeredPane();
jftp_0.addTab("捐款紀錄", null, jflp_3, null);
JPanel ContactPanel = new JPanel();
jftp_0.addTab("聯絡紀錄", null, ContactPanel, null);
GridBagLayout gbl_ContactPanel = new GridBagLayout();
gbl_ContactPanel.columnWidths = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
gbl_ContactPanel.rowHeights = new int[] { 0, 0, 0, 0, 0, 0, 0 };
gbl_ContactPanel.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
Double.MIN_VALUE };
gbl_ContactPanel.rowWeights = new double[] { 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, Double.MIN_VALUE };
ContactPanel.setLayout(gbl_ContactPanel);
JLabel label_8 = new JLabel("日期");
GridBagConstraints gbc_label_8 = new GridBagConstraints();
gbc_label_8.insets = new Insets(0, 0, 5, 5);
gbc_label_8.gridx = 0;
gbc_label_8.gridy = 0;
ContactPanel.add(label_8, gbc_label_8);
dateChooser_4 = new JDateChooser();
GridBagConstraints gbc_dateChooser_4 = new GridBagConstraints();
gbc_dateChooser_4.gridwidth = 2;
gbc_dateChooser_4.insets = new Insets(0, 0, 5, 5);
gbc_dateChooser_4.fill = GridBagConstraints.BOTH;
gbc_dateChooser_4.gridx = 1;
gbc_dateChooser_4.gridy = 0;
ContactPanel.add(dateChooser_4, gbc_dateChooser_4);
JLabel label_9 = new JLabel("聯繫方式");
GridBagConstraints gbc_label_9 = new GridBagConstraints();
gbc_label_9.insets = new Insets(0, 0, 5, 5);
gbc_label_9.gridx = 6;
gbc_label_9.gridy = 0;
ContactPanel.add(label_9, gbc_label_9);
JComboBox comboBox_9 = new JComboBox();
GridBagConstraints gbc_comboBox_9 = new GridBagConstraints();
gbc_comboBox_9.fill = GridBagConstraints.HORIZONTAL;
gbc_comboBox_9.gridwidth = 3;
gbc_comboBox_9.insets = new Insets(0, 0, 5, 5);
gbc_comboBox_9.gridx = 8;
gbc_comboBox_9.gridy = 0;
ContactPanel.add(comboBox_9, gbc_comboBox_9);
JLabel label_10 = new JLabel("負責人");
GridBagConstraints gbc_label_10 = new GridBagConstraints();
gbc_label_10.insets = new Insets(0, 0, 5, 5);
gbc_label_10.gridx = 11;
gbc_label_10.gridy = 0;
ContactPanel.add(label_10, gbc_label_10);
textField_2 = new JTextField();
GridBagConstraints gbc_textField_2 = new GridBagConstraints();
gbc_textField_2.insets = new Insets(0, 0, 5, 0);
gbc_textField_2.fill = GridBagConstraints.HORIZONTAL;
gbc_textField_2.gridx = 12;
gbc_textField_2.gridy = 0;
ContactPanel.add(textField_2, gbc_textField_2);
textField_2.setColumns(10);
JLabel label_11 = new JLabel("實體寄送物");
GridBagConstraints gbc_label_11 = new GridBagConstraints();
gbc_label_11.insets = new Insets(0, 0, 5, 5);
gbc_label_11.gridx = 0;
gbc_label_11.gridy = 1;
ContactPanel.add(label_11, gbc_label_11);
JRadioButton radioButton = new JRadioButton("有");
GridBagConstraints gbc_radioButton = new GridBagConstraints();
gbc_radioButton.insets = new Insets(0, 0, 5, 5);
gbc_radioButton.gridx = 1;
gbc_radioButton.gridy = 1;
ContactPanel.add(radioButton, gbc_radioButton);
JRadioButton radioButton_1 = new JRadioButton("無");
GridBagConstraints gbc_radioButton_1 = new GridBagConstraints();
gbc_radioButton_1.insets = new Insets(0, 0, 5, 5);
gbc_radioButton_1.gridx = 2;
gbc_radioButton_1.gridy = 1;
ContactPanel.add(radioButton_1, gbc_radioButton_1);
JLabel lblNewLabel = new JLabel("聯絡狀態");
GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5);
gbc_lblNewLabel.gridx = 6;
gbc_lblNewLabel.gridy = 1;
ContactPanel.add(lblNewLabel, gbc_lblNewLabel);
JComboBox comboBox_8 = new JComboBox();
comboBox_8.setModel(new DefaultComboBoxModel(new String[] { "正常", "暫停通信", "失聯" }));
GridBagConstraints gbc_comboBox_8 = new GridBagConstraints();
gbc_comboBox_8.gridwidth = 2;
gbc_comboBox_8.insets = new Insets(0, 0, 5, 5);
gbc_comboBox_8.fill = GridBagConstraints.HORIZONTAL;
gbc_comboBox_8.gridx = 8;
gbc_comboBox_8.gridy = 1;
ContactPanel.add(comboBox_8, gbc_comboBox_8);
JLabel label_12 = new JLabel("通聯狀況說明");
GridBagConstraints gbc_label_12 = new GridBagConstraints();
gbc_label_12.insets = new Insets(0, 0, 5, 5);
gbc_label_12.gridx = 0;
gbc_label_12.gridy = 2;
ContactPanel.add(label_12, gbc_label_12);
JTextArea textArea_2 = new JTextArea();
GridBagConstraints gbc_textArea_2 = new GridBagConstraints();
gbc_textArea_2.gridwidth = 8;
gbc_textArea_2.insets = new Insets(0, 0, 5, 5);
gbc_textArea_2.fill = GridBagConstraints.BOTH;
gbc_textArea_2.gridx = 1;
gbc_textArea_2.gridy = 2;
ContactPanel.add(textArea_2, gbc_textArea_2);
btnNewButton = new JButton("新增");
GridBagConstraints gbc_btnNewButton = new GridBagConstraints();
gbc_btnNewButton.anchor = GridBagConstraints.SOUTH;
gbc_btnNewButton.insets = new Insets(0, 0, 5, 5);
gbc_btnNewButton.gridx = 10;
gbc_btnNewButton.gridy = 2;
ContactPanel.add(btnNewButton, gbc_btnNewButton);
btnNewButton_1 = new JButton("查詢");
GridBagConstraints gbc_btnNewButton_1 = new GridBagConstraints();
gbc_btnNewButton_1.anchor = GridBagConstraints.SOUTH;
gbc_btnNewButton_1.insets = new Insets(0, 0, 5, 5);
gbc_btnNewButton_1.gridx = 11;
gbc_btnNewButton_1.gridy = 2;
ContactPanel.add(btnNewButton_1, gbc_btnNewButton_1);
label_13 = new JLabel("搜尋結果");
GridBagConstraints gbc_label_13 = new GridBagConstraints();
gbc_label_13.insets = new Insets(0, 0, 5, 5);
gbc_label_13.gridx = 0;
gbc_label_13.gridy = 3;
ContactPanel.add(label_13, gbc_label_13);
JScrollPane scrollPane = new JScrollPane();
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
gbc_scrollPane.gridheight = 3;
gbc_scrollPane.gridwidth = 12;
gbc_scrollPane.fill = GridBagConstraints.BOTH;
gbc_scrollPane.gridx = 1;
gbc_scrollPane.gridy = 3;
ContactPanel.add(scrollPane, gbc_scrollPane);
JTabbedPane tabbedPane_1 = new JTabbedPane(JTabbedPane.TOP);
scrollPane.setColumnHeaderView(tabbedPane_1);
searchLayeredPane = new JLayeredPane();
jftp_0.addTab("查詢頁面", null, searchLayeredPane, null);
}
private void LoadData() {
DefaultTableModel dtm = new DefaultTableModel();
dtm.addColumn("分類");
dtm.addColumn("單位");
dtm.addColumn("姓名");
dtm.addColumn("客戶編號");
dtm.addColumn("郵區");
dtm.addColumn("地址");
dtm.addColumn("手機");
dtm.addColumn("傳真");
dtm.addColumn("信箱");
dtm.addColumn("生日");
for (Client client : cm.findAll()) {
dtm.addRow(new Object[] { client.getCategory(), client.getOrganization(), client.getName(), client.getNo(),
client.getZip(), client.getAddress(), client.getCellnumber(), client.getFax(),
client.getEmail(), client.getBirthday() });
}
this.clientTable.setModel(dtm);
}
}