ĐẠI HỌC DUY TÂN
TRƯỜNG KHOA HỌC MÁY TÍNH
KHOA KỸ THUẬT MẠNG MÁY TÍNH & TRUYỀN THÔNG
ĐỒ ÁN CÁ NHÂN
MÔN HỌC
LẬP TRÌNH HƯỚNG ĐỐI TƯỢNG
GIẢNG VIÊN HƯỚNG DẪN
NGUYỄN MINH NHẬT
SINH VIÊN THỰC HIỆN
LÊ CẢNH HÙNG
MSSV
: 28211151710
LỚP MÔN HỌC
CS 311 C
LỚP SINH HOẠT
K28TPM
1
ĐIỂM SỐ
ĐIỂM CHỮ
GIÁM KHẢO
MỤC LỤC
 
 





 



2.2.3. Thit k lp



 

 



 




 
CHƯƠNG 1. GIỚI THIỆU BI TOÁN
1.1. Gii thiêu bi to













1.2. Yêu cu







1.2.1. Input



1.2.2. Output
Xây dựng các lớp:














CHƯƠNG 2. PHÂN TÍCH THIT K
2.1. Phân tch
2.1.1. Ngôn ng lâp trn




2.2. Thit k
2.2.1. Thit k cơ s d liê


2.2.2. Thit k giao diê
2.2.2.1. Giao diên Command Lin










2.2.2.2. Giao diên đ ha (GUI)
Hình 1. Giao diện chinh dạng đồ hoạ
2.2.3. Thit k lp
2.2.3.1. Đi vi Command Line A. Lớp Nguoi: + Tên lớp:+ Thuộc tính:



+ Phương thức:


























































B. Lớp HoGiaDinh quản lý nhng người cùng số nhà: + Tên lớp: 
Thuộc tính:

Phương thức:




































C. Lớp KhuPho quản lý nhiều hộ gia đnh và người dân: Tên lớp: KhuPho.java
+ Thuộc tính:
` Phương thức: 



























































































































































2.2.3.2. Đi vi giao diên GU
+ Tên class: Mã nguồn:
























































































































































































































































 





































































 




 







































































Preview text:

ĐẠI HỌC DUY TÂN
TRƯỜNG KHOA HỌC MÁY TÍNH
KHOA KỸ THUẬT MẠNG MÁY TÍNH & TRUYỀN THÔNG ĐỒ ÁN CÁ NHÂN MÔN HỌC :
LẬP TRÌNH HƯỚNG ĐỐI TƯỢNG
GIẢNG VIÊN HƯỚNG DẪN : NGUYỄN MINH NHẬT
SINH VIÊN THỰC HIỆN
: LÊ CẢNH HÙNG MSSV : 28211151710 LỚP MÔN HỌC : CS 311 C LỚP SINH HOẠT
: K28TPM 1 ĐIỂM SỐ ĐIỂM CHỮ GIÁM KHẢO MỤC LỤC
CHƯƠNG 1. GIỚI THIÊU BÀI TOÁṆ ...........................................................3
1.1. Giới thiêu bài toáṇ ...................................................................................3
1.2. Yêu cầu....................................................................................................3
1.2.1. Input...................................................................................................3
1.2.2. Output................................................................................................3
CHƯƠNG 2. PHÂN TÍCH THIẾT KẾ............................................................4
2.1. Phân tích..................................................................................................4
2.1.1. Ngôn ngữ lâp trìnḥ ............................................................................4
2.2. Thiết kế....................................................................................................4
2.2.1. Thiết kế cơ sở dữ liêụ ........................................................................4
2.2.2. Thiết kế giao diêṇ ..............................................................................4
2.2.3. Thiết kế lớp........................................................................................5
2.2.4. Sơ đồ lớp..........................................................................................30
CHƯƠNG 3. CÀI ĐĂT VÀ KIỂM THƯ ̣̉ .......................................................30
3.1. Giao diên chínḥ .....................................................................................30
3.1.1. Giao diên Command Linẹ................................................................30
3.1.2. Giao diên GUỊ .................................................................................31
3.2. Môt số kết qua ̣̉ .......................................................................................31
3.2.1. Giao diên Command Linẹ...............................................................31
3.2.2. Giao diên đồ họạ ..............................................................................33
CHƯƠNG 4. KẾT LUÂṆ ...............................................................................38
4.1. Các vấn đề đạt được..............................................................................38
4.2. Các vấn đề chưa đạt được......................................................................38
4.3. Hướng phát triển....................................................................................38
TÀI LIÊU THAM KHẢỌ ...............................................................................39
CHƯƠNG 1. GIỚI THIỆU BÀI TOÁN
1.1. Giới thiêu bài toáṇ
Để quản lý các hộ dân cư trong một khu phố, người ta cần các thông tin sau: Số thành viên trong gia
đình, Số nhà, thông tin mỗi cá nhân trong gia đình. Với mỗi cá nhân, người ta quản lý các thông tin
sau: Họ tên, Tuổi, Nghề nghiệp, số chứng minh nhân dân (duy nhất cho mỗi người).
Yêu cầu 1: Hãy xây dựng lớp Nguoi để quản lý thông tin của mỗi cá nhân.
Yêu cầu 2: Xây dựng lớp HoGiaDinh để quản lý thông tin của từng hộ gia đình.
Yêu cầu 2: Xây dựng lớp KhuPho để quản lý các thông tin của từng hộ gia đình.
Yêu cầu 3: Nhập n hộ dân. (n nhập từ bàn phím), hiển thị thông tin của các hộ trong khu phố.
Yêu cầu 4: Thêm hộ gia đình, thêm thông tin thành viên trong hộ gia đình.
Yêu cầu 5: Tìm cá nhân theo số CMND.
Yêu cầu 6: Thoát chương trình. Hãy thực hiện:
Thiết kế giao diện GUI để thực hiện được tất cả các chức năng nêu trên.
Thiết kế cơ sở dữ liệu phù hợp cho project. Dữ liệu đọc và lưu từ file hoặc từ Hệ
Quản Trị CSDL như: MS. Access, SQL Server, MySQL v.v…
1.2. Yêu cầu
Yêu cầu 1: Hãy xây dựng lớp Nguoi để quản lý thông tin của mỗi cá nhân.
Yêu cầu 2: Xây dựng lớp HoGiaDinh để quản lý thông tin của từng hộ gia đình.
Yêu cầu 2: Xây dựng lớp KhuPho để quản lý các thông tin của từng hộ gia đình.
Yêu cầu 3: Nhập n hộ dân. (n nhập từ bàn phím), hiển thị thông tin của các hộ trong khu phố.
Yêu cầu 4: Thêm hộ gia đình, thêm thông tin thành viên trong hộ gia đình.
Yêu cầu 5: Tìm cá nhân theo số CMND.
Yêu cầu 6: Thoát chương trình. 1.2.1. Input + Cơ sở dữ liệu:
Lựa chọn Hệ thống file văn bản, gồm các file: dulieu.txt: 1.2.2. Output
Xây dựng các lớp:
Xây dựng class Nguoi bao gồm các thuộc tính( họ và tên, số CMND, tuổi, nghề nghiệp, số nhà)
Xây dựng class HoGiaDinh để quản lý những Nguoi có cùng số nhà và có thuộc tính(số nhà)
Xây dựng class KhuPho để quản lý những HoGiaDinh khác nhau với các phương thức:
+ Thêm mới hộ gia đình
+ Hiện thông tin hộ gia đình
+ Hiện thông tin toàn bộ người dân + Kiểm tra tồn tại
+ Xóa thông tin người dân
+ Tìm kiếm thông tin người dân theo số CMND
+ Lưu dữ liệu xuống file
+ Lấy dữ liệu từ file + Thoát chương trình
CHƯƠNG 2. PHÂN TÍCH THIẾT KẾ
2.1. Phân tích
2.1.1. Ngôn ngữ lâp trìnḥ
Ngôn ngữ lập trình: Java Framework: JavaSwing
Công cụ phát triển: Apache NetBeans 12
Môi trường vận hành: Thực hiện PC, Desktop với hệ điều hành Window 7.
2.2. Thiết kế
2.2.1. Thiết kế cơ sở dữ liêụ
Hệ thống lưu trữ: Hệ thống File văn bản (dạng *.txt) Gồm các file có cấu trúc như sau:
+ Dulieu.txt: Lưu trữ các thông tin của người dân và các hộ gia đình
2.2.2. Thiết kế giao diêṇ
2.2.2.1. Giao diên Command Linẹ
---QUẢN LÝ HỘ DÂN CƯ---
OPTION 1: Thêm hộ gia đình
OPTION 2: Tìm theo số CMND
OPTION 3: Hiện toàn bộ thông tin khu phố
OPTION 4: Hiện thông tin theo số nhà
OPTION 5: Xoá thông tin người theo số CMND OPTION 6: Lưu file
OPTION 7: Lấy dữ liệu từ file OPTION 0: THOÁT Mời bạn chọn option.
2.2.2.2. Giao diên đồ họa (GUI)̣
Hình 1. Giao diện chinh dạng đồ hoạ
2.2.3. Thiết kế lớp
2.2.3.1. Đối với Command Line A. Lớp Nguoi: + Tên lớp: Nguoi,java + Thuộc tính: private String hoTen;
private int tuoi; private String ngheNghiep; private int soCMND; private String soNha; + Phương thức: public Nguoi() { }
public Nguoi(String hoTen, int tuoi, String ngheNghiep, int soCMND,String soNha) {
this.hoTen = suaTen(hoTen); this.tuoi = tuoi;
this.ngheNghiep = ngheNghiep; this.soCMND = soCMND; this.soNha = soNha; }
public String suaTen(String input) { if (input == null || input.isEmpty()) { return input; }
String[] words = input.split("\\s"); StringBuilder result = new StringBuilder();
for (String word : words) { if (!word.isEmpty()) {
result.append(Character.toUpperCase(word.charAt(0)))
.append(word.substring(1).toLowerCase()) .append(" "); } }
return result.toString().trim(); } public String getSoNha() { return soNha; }
public void setSoNha(String soNha) { this.soNha = soNha; }
public String getHoTen() { return hoTen; }
public void setHoTen(String hoTen) { this.hoTen = hoTen; }
public int getTuoi() { return tuoi; }
public void setTuoi(int tuoi) { this.tuoi = tuoi; }
public String getNgheNghiep() { return ngheNghiep; }
public void setNgheNghiep(String ngheNghiep) { this.ngheNghiep = ngheNghiep; }
public int getSoCMND() { return soCMND;
public void setSoCMND(int soCMND) { this.soCMND = soCMND; } public void xuatThongTin(){
System.out.println("Họ và tên : " + getHoTen());
System.out.println("Số CMND : " + getSoCMND());
System.out.println("Nghề nghiệp : " + getNgheNghiep());
System.out.println("Tuổi : " + getTuoi());
System.out.println("Số nhà : " + getSoNha()); } @Override public String toString() {
return "Nguoi{" + "hoTen=" + hoTen + ", tuoi=" + tuoi + ", ngheNghiep=" + ngheNghiep + ", soCMND=" + soCMND + '}'; }
B. Lớp HoGiaDinh quản lý những người cùng số nhà: + Tên lớp: HoGiaDinh.java + Thuộc tính:
private ArrayList list; private String soNha; private int soThanhVien; + Phương thức: public ArrayList getList() { return list; }
public void setSoThanhVien(int soThanhVien) { this.soThanhVien = soThanhVien; }
public boolean checkCMND(int cmnd){
if(this.list == null){ return false; }
for(Nguoi n : list){ if(n.getSoCMND() == cmnd){ return true; } } return false; }
public HoGiaDinh() { list = new ArrayList(); public HoGiaDinh(String soNha) { this.soNha = soNha; this.list = new ArrayList(); }
public String getSoNha() { return soNha; } public void xuatThongTin(){
System.out.println("Số nhà: " + getSoNha()); System.out.println("Số thành viên: " +
this.list.size()); int i = 0; for(Nguoi n : list){ i+=1;
System.out.println("Thông tin thành viên thứ "+i+": "); n.xuatThongTin(); } }
public void themThanhVien(Nguoi nguoi){ this.list.add(nguoi); }
public void xoaThanhVien(Nguoi nguoi){ this.list.remove(nguoi); }
C. Lớp KhuPho quản lý nhiều hộ gia đình và người dân: + Tên lớp: KhuPho.java + Thuộc tính: `
private ArrayList list; + Phương thức: Scanner sc = new Scanner(System.in); public KhuPho() { list = new ArrayList(); }
public void show(){ if(this.list == null){
System.out.println("Danh sách rỗng");
}else{ for(HoGiaDinh hgd : list){ for(Nguoi nguoi : hgd.getList()){ nguoi.xuatThongTin();
System.out.println("--------------------------"); } } }
public void setList(ArrayList list) { this.list = list; }
public void timTheoCMND(int cmnd){ for(HoGiaDinh hgd : list){ for(Nguoi
nguoi : hgd.getList()){ if(nguoi.getSoCMND() == cmnd){ nguoi.xuatThongTin(); break; } } } } public ArrayList getList() { return list; }
public boolean checkCMND(int cmnd){
if(this.list == null){ return false; }
for(HoGiaDinh hgd : list){ for(Nguoi nguoi : hgd.getList()){
if(nguoi.getSoCMND() == cmnd){ return true; } } }return false; }
public boolean checkSoNha(String soNha){ for(HoGiaDinh hgd : list){
if(hgd.getSoNha().equals(soNha)){ return true; } } return false; }
public int checkFolmat(){ int temp = 0; try {
temp = Integer.parseInt(sc.nextLine()); return temp; } catch (Exception e) {
System.out.println("BẠN ĐÃ NHẬP SAI CÚ PHÁP"); return checkFolmat(); } }
public void xuatThongTin(String soNha){ if(this.list == null){
System.out.println("Danh sách rỗng"); }else{
for(HoGiaDinh hgd : list){ if(hgd.getSoNha().equals(soNha)){ hgd.xuatThongTin(); } } } } public void write(){ try {
FileOutputStream fos = new FileOutputStream("dulieu.txt");
ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(list);
System.out.println("GHI THÀNH CÔNG"); oos.close(); fos.close(); } catch (IOException e) {
System.out.println("LỖI GHI FILE"); } } public void read(){ try {
FileInputStream fis = new FileInputStream("dulieu.txt"); ObjectInputStream
ois = new ObjectInputStream(fis);
this.list = (ArrayList)ois.readObject();
System.out.println("ĐỌC VÀ LẤY DỮ LIỆU FILE THÀNH CÔNG"); fis.close(); ois.close();
} catch (IOException | ClassNotFoundException e) {
System.out.println("LỖI ĐỌC FILE"); } }
public void themHoGiaDinh(HoGiaDinh hgd){ this.list.add(hgd); }
public void xoaNguoi(int cmnd){ if(this.checkCMND(cmnd)==false){
System.out.println("Số CMND này chưa có trong danh sách"); }else{
for(HoGiaDinh hgd : list){ for(Nguoi nguoi : hgd.getList()){
if(nguoi.getSoCMND() == cmnd){ hgd.xoaThanhVien(nguoi); if(hgd.getList()==null){ this.list.remove(hgd); }
System.out.println("ĐÃ XÓA THÔNG TIN NGƯỜI DÂN SỐ CMND " + cmnd); break; } } } } }
public void themThongTinHoGiaDinh(String soNha){
HoGiaDinh hgd = new HoGiaDinh(soNha);
System.out.println("Nhập số thành viên trong hộ gia đình:"); int i = checkFolmat();
hgd.setSoThanhVien(i); for (int j = 0; j < i; j++) {
System.out.println("Nhập thông tin thành viên thứ " + (j+1)); int ok = 1; int soCMND; do{ ok = 1;
System.out.println("Nhập số CMND: "); soCMND = checkFolmat();
if(checkCMND(soCMND) || hgd.checkCMND(soCMND)){
System.out.println("Số CMND không hợp lệ, vui lòng nhập lại"); ok = 0; } }while(ok == 0);
System.out.println("Nhập họ và tên: ");
String hoTen = chuanHoaTen(); System.out.println("Nhập tuổi: "); int tuoi = checkFolmat();
System.out.println("Nhập nghề nghiệp: ");
String ngheNghiep = chuanHoaTen();
Nguoi nguoi = new Nguoi(hoTen,tuoi,ngheNghiep,soCMND,soNha); hgd.themThanhVien(nguoi); } this.list.add(hgd); }
public String chuanHoaTen() { String ten = sc.nextLine(); if (!isValidName(ten)) {
System.out.println("CHUỖI BỊ LỖI, VUI LÒNG NHẬP LẠI"); return
chuanHoaTen();} String[] arr = ten.split("\\s+");
StringBuilder sb = new StringBuilder(); for (String s : arr) { if (s.length() > 0) {
sb.append(Character.toUpperCase(s.charAt(0)));
sb.append(s.substring(1).toLowerCase()); sb.append(" "); } } return sb.toString().trim(); }
public boolean isValidName(String name) { for (int i = 0; i < name.length(); i++) {
char c = name.charAt(i); if (isSpecialCharacter(c)) { return false; } } return true; }
public boolean isSpecialCharacter(char c) {
return !(Character.isLetter(c) || Character.isWhitespace(c)); }
2.2.3.2. Đối với giao diên GUỊ
+ Tên class: QuanLyHoDanCu_GUI.java + Mã nguồn:
public class QuanLyHoDanCu_GUI extends javax.swing.JFrame { KhuPho khuPho = new KhuPho(); /**
* Creates new form QuanLyHoDanCu_GUI */
public QuanLyHoDanCu_GUI() { initComponents();
this.setLocationRelativeTo(null); this.setResizable(false);
tableInfo.getTableHeader().setReorderingAllowed(false);
jMenuItem_Save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK));
jMenuItem_Open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,
InputEvent.CTRL_DOWN_MASK)); } /**
* This method is called from within the constructor to initialize the form. * WARNING:
Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */
@SuppressWarnings("unchecked") // private void initComponents() {
jLabel1 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane();
tableInfo = new javax.swing.JTable(); btnThem = new javax.swing.JButton();
btnTimKiem = new javax.swing.JButton(); jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jLabel5 =
new javax.swing.JLabel(); jLabel6 = new javax.swing.JLabel(); soCMNDTextField
= new javax.swing.JTextField(); hoVaTenTextField = new javax.swing.JTextField();
tuoiTextField = new javax.swing.JTextField(); ngheNghiepTextField = new
javax.swing.JTextField(); soNhaTextField = new javax.swing.JTextField(); btnClear
= new javax.swing.JButton(); timKiemTextField = new javax.swing.JTextField();
jLayeredPane2 = new javax.swing.JLayeredPane(); btnXoa = new javax.swing.JButton();
btnShowALL = new javax.swing.JButton(); btnUpdate = new javax.swing.JButton();
btnSave = new javax.swing.JButton(); btnOpen = new javax.swing.JButton();
jLabel7 = new javax.swing.JLabel(); jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu(); jMenuItem_Open = new javax.swing.JMenuItem();
jMenuItem_Save = new javax.swing.JMenuItem(); jMenu2 = new javax.swing.JMenu();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Quản Lý Hộ Dân Cư"); setBackground(new java.awt.Color(255, 0, 0));
jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
jLabel1.setForeground(new java.awt.Color(255, 0, 0));
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setText("QUẢN LÝ HỘ DÂN CƯ");
tableInfo.setBorder(javax.swing.BorderFactory.createEtchedBorder());
tableInfo.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { }, new String [] {
"CMND", "Họ và tên", "Tuổi", "Nghề nghiệp", "Số nhà" } ) {
Class[] types = new Class [] {
java.lang.Integer.class, java.lang.String.class, java.lang.Integer.class,
java.lang.String.class, java.lang.Integer.class };
boolean[] canEdit = new boolean [] { false, false, false, false, false };
public Class getColumnClass(int columnIndex) { return types [columnIndex]; }
public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit [columnIndex]; } });
jScrollPane1.setViewportView(tableInfo);
btnThem.setText("THÊM"); btnThem.addActionListener(new
java.awt.event.ActionListener() { public void
actionPerformed(java.awt.event.ActionEvent evt) { btnThemActionPerformed(evt); } });
btnTimKiem.setText("Tìm kiếm"); btnTimKiem.addActionListener(new
java.awt.event.ActionListener() { public void
actionPerformed(java.awt.event.ActionEvent evt) {
btnTimKiemActionPerformed(evt); } });
jLabel2.setText("Số CMND:"); jLabel3.setText("Họ và tên:");
jLabel4.setText("Tuổi:"); jLabel5.setText("Nghề nghiệp:"); jLabel6.setText("Số nhà:");
soCMNDTextField.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
soCMNDTextFieldActionPerformed(evt); } });
tuoiTextField.addActionListener(new java.awt.event.ActionListener() { public
void actionPerformed(java.awt.event.ActionEvent evt) {
tuoiTextFieldActionPerformed(evt); } });
btnClear.setText("Clear"); btnClear.addActionListener(new
java.awt.event.ActionListener() { public void
actionPerformed(java.awt.event.ActionEvent evt) { btnClearActionPerformed(evt); } });
timKiemTextField.setForeground(new java.awt.Color(153, 153, 153));
timKiemTextField.setText("Nhập vào số CMND cần tìm");
timKiemTextField.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
timKiemTextFieldMouseClicked(evt); } });
timKiemTextField.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
timKiemTextFieldActionPerformed(evt); } });
jLayeredPane2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing. border.BevelBorder.RAISED));
btnXoa.setText("Xóa thông tin người dùng"); btnXoa.addActionListener(new
java.awt.event.ActionListener() { public void
actionPerformed(java.awt.event.ActionEvent evt) { btnXoaActionPerformed(evt); } });
btnShowALL.setText("Hiên toàn bộ thông tin khu phố");
btnShowALL.addActionListener(new java.awt.event.ActionListener() { public void
actionPerformed(java.awt.event.ActionEvent evt) {
btnShowALLActionPerformed(evt); } });
btnUpdate.setText("Sửa thông tin người dùng"); btnUpdate.addActionListener(new
java.awt.event.ActionListener() { public void
actionPerformed(java.awt.event.ActionEvent evt) {
btnUpdateActionPerformed(evt); } });
btnSave.setText("SAVE"); btnSave.addActionListener(new
java.awt.event.ActionListener() { public void
actionPerformed(java.awt.event.ActionEvent evt) { btnSaveActionPerformed(evt); } }); btnOpen.setText("OPEN");
btnOpen.addActionListener(new java.awt.event.ActionListener() { public void
actionPerformed(java.awt.event.ActionEvent evt) { btnOpenActionPerformed(evt); } });
jLabel7.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
jLabel7.setText("CHỨC NĂNG");
jLayeredPane2.setLayer(btnXoa, javax.swing.JLayeredPane.DEFAULT_LAYER);
jLayeredPane2.setLayer(btnShowALL,
javax.swing.JLayeredPane.DEFAULT_LAYER); jLayeredPane2.setLayer(btnUpdate,
javax.swing.JLayeredPane.DEFAULT_LAYER); jLayeredPane2.setLayer(btnSave,
javax.swing.JLayeredPane.DEFAULT_LAYER); jLayeredPane2.setLayer(btnOpen,
javax.swing.JLayeredPane.DEFAULT_LAYER); jLayeredPane2.setLayer(jLabel7,
javax.swing.JLayeredPane.DEFAULT_LAYER); javax.swing.GroupLayout
jLayeredPane2Layout = new javax.swing.GroupLayout(jLayeredPane2);
jLayeredPane2.setLayout(jLayeredPane2Layout);
jLayeredPane2Layout.setHorizontalGroup(
jLayeredPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.L EADING)
.addGroup(jLayeredPane2Layout.createSequentialGroup() .addContainerGap()
.addGroup(jLayeredPane2Layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addComponent(btnXoa, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnShowALL,
javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE)
.addComponent(btnUpdate, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnSave, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnOpen, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap())
.addGroup(jLayeredPane2Layout.createSequentialGroup() .addGap(52, 52, 52) .addComponent(jLabel7)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) );
jLayeredPane2Layout.setVerticalGroup(
jLayeredPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.L EADING)
.addGroup(jLayeredPane2Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 21,
javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(btnXoa) .addGap(18, 18, 18) .addComponent(btnUpdate) .addGap(18, 18, 18) .addComponent(btnSave) .addGap(18, 18, 18) .addComponent(btnOpen) .addGap(18, 18, 18) .addComponent(btnShowALL) .addContainerGap()) ); jMenu1.setText("File");
jMenuItem_Open.setText("Open");
jMenuItem_Open.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem_OpenActionPerformed(evt); } }); jMenu1.add(jMenuItem_Open);
jMenuItem_Save.setText("Save");
jMenuItem_Save.addActionListener(new java.awt.event.ActionListener() { public
void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem_SaveActionPerformed(evt); } });
jMenu1.add(jMenuItem_Save); jMenuBar1.add(jMenu1);
jMenu2.setText("Edit"); jMenuBar1.add(jMenu2); setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout); layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup() .addGap(63, 63, 63)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 332,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE ADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignmen t.LEADING)
.addGroup(layout.createSequentialGroup() .addGap(33, 33, 33)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alig nment.LEADING) .addComponent(jLabel2) .addComponent(jLabel6) .addComponent(jLabel5) .addComponent(jLabel4) .addComponent(jLabel3)) .addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alig nment.LEADING, false)
.addComponent(hoVaTenTextField) .addComponent(tuoiTextField)
.addComponent(ngheNghiepTextField)
.addComponent(soNhaTextField)
.addComponent(soCMNDTextField,
javax.swing.GroupLayout.DEFAULT_SIZE, 246, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup() .addComponent(btnThem)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement
.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnClear))))
.addGroup(layout.createSequentialGroup() .addGap(24, 24, 24)
.addComponent(timKiemTextField,
javax.swing.GroupLayout.PREFERRED_SIZE, 246,
javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(btnTimKiem)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATE D)
.addComponent(jLayeredPane2))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup() .addContainerGap()
.addComponent(jScrollPane1))) .addContainerGap()) );
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[]
{hoVaTenTextField, ngheNghiepTextField, soCMNDTextField, soNhaTextField, tuoiTextField}); layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup() .addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 36,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE ADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignmen t.BASELINE) .addComponent(jLabel2)
.addComponent(soCMNDTextField,
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignmen t.BASELINE) .addComponent(jLabel3)
.addComponent(hoVaTenTextField,
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignmen t.BASELINE) .addComponent(jLabel4) .addComponent(tuoiTextField,
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignmen t.BASELINE) .addComponent(jLabel5)
.addComponent(ngheNghiepTextField,
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignmen t.BASELINE) .addComponent(jLabel6)
.addComponent(soNhaTextField,
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATE D)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignmen t.BASELINE) .addComponent(btnClear) .addComponent(btnThem))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATE D,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignmen t.BASELINE)
.addComponent(timKiemTextField,
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnTimKiem)))
.addGroup(layout.createSequentialGroup() .addComponent(jLayeredPane2,
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE)))
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE,
174, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(4, 4, 4)) ); pack(); }//
private void soCMNDTextFieldActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here: }
private void tuoiTextFieldActionPerformed(java.awt.event.ActionEvent evt) { //
TODO add your handling code here: }
private void btnThemActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here:
if(btnThem.getText().equals("UPDATE")){ if(!checkfill()){
JOptionPane.showMessageDialog(rootPane, "Bạn chưa điền đầy đủ thông tin");
}else if(!checkFolmatTuoi(soCMNDTextField.getText())){
JOptionPane.showMessageDialog(rootPane, "Định dạng sô CMND không hợp lệ"); soCMNDTextField.setText("");
}else if(!checkFolmatTuoi(tuoiTextField.getText())){
JOptionPane.showMessageDialog(rootPane, "Định dạng tuổi không hợp lệ"); tuoiTextField.setText("");
}else if(Integer.parseInt(tuoiTextField.getText())<0){
JOptionPane.showMessageDialog(rootPane, "Tuổi phải lớn hơn 0"); tuoiTextField.setText("");
}else if(!checkFolmatHoVaTen(hoVaTenTextField.getText())){
JOptionPane.showMessageDialog(rootPane, "Bạn đã nhập sai định dạng họ và tên");
hoVaTenTextField.setText("");
}else if(!checkFolmatHoVaTen(ngheNghiepTextField.getText())){
JOptionPane.showMessageDialog(rootPane, "Bạn đã nhập sai định dạng nghề nghiệp");
ngheNghiepTextField.setText(""); }else{ Nguoi nguoi = new
Nguoi(hoVaTenTextField.getText(),Integer.parseInt(tuoiTextField.getText()),ngheNghiep
TextField.getText(),Integer.parseInt(soCMNDTextField.getText()),soNhaTextField.getTex t());
HoGiaDinh hgd = new HoGiaDinh(soNhaTextField.getText());
if(khuPho.checkSoNha(hgd.getSoNha())){ for(HoGiaDinh h : khuPho.getList()){
if(h.getSoNha().equals(soNhaTextField.getText())){ h.themThanhVien(nguoi);
JOptionPane.showMessageDialog(rootPane, "Đã sửa thông tin người dân mã
số " + soCMNDTextField.getText()); btnThem.setText("Thêm"); in(); } } }else{
hgd.themThanhVien(nguoi); khuPho.themHoGiaDinh(hgd);
JOptionPane.showMessageDialog(rootPane, "Đã sửa thông tin người dân mã số " + soCMNDTextField.getText()); btnThem.setText("Thêm"); in(); } } }else{ if(!checkfill()){
JOptionPane.showMessageDialog(rootPane, "Bạn chưa điền đầy đủ thông tin");
}else if(!checkFolmatTuoi(soCMNDTextField.getText())){
JOptionPane.showMessageDialog(rootPane, "Định dạng sô CMND không hợp lệ"); soCMNDTextField.setText("");
}else if(!checkFolmatTuoi(tuoiTextField.getText())){
JOptionPane.showMessageDialog(rootPane, "Định dạng tuổi không hợp lệ"); tuoiTextField.setText("");
}else if(Integer.parseInt(tuoiTextField.getText())<0){
JOptionPane.showMessageDialog(rootPane, "Tuổi phải lớn hơn 0"); tuoiTextField.setText("");