├── LICENSE
├── README.md
├── ScriptSQL
└── script.sql
├── images
├── 1.png
├── 2.png
├── 3.png
├── 4.png
├── 5.png
└── 6.png
└── project
├── dao
└── ClientsDAO.java
├── jdbc
├── ConnectionFactory.java
├── TestConnection.java
└── mysql-connector-java-5.1.47.jar
├── model
├── Clients.java
└── Utilities.java
└── view
├── FrmClients.form
└── FrmClients.java
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 Vinicius Almeida
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
Java CRUD with MySQL Connection
2 |
3 | This repository contains a Java project with basic CRUD (Create, Read, Update, and Delete) operations using a connection to the MySQL database.
4 |
5 | Technologies used in this project:
6 |
7 | * Java
8 | * MySQL
9 | * JDBC (Java Database Connectivity)
10 | * Swing (Java graphical library)
11 | * Git (version control)
12 |
13 | Requirements:
14 |
15 | * JDK 8 or higher
16 | * MySQL Server 5.7 or higher
17 | * MySQL connection library (mysql-connector-java-8.0.23.jar)
18 |
19 | To use the project, follow these steps:
20 |
21 | 1. Download the repository in ZIP format or clone the project using the following SSH code:
22 |
23 | ~~~bash
24 | git clone git@github.com:viniciusvk1/Java-CRUD-with-MySQL-Connection.git
25 | ~~~
26 |
27 | 2. Open the project in your preferred IDE.
28 |
29 | 3. Import the MySQL connection library (mysql-connector-java-8.0.23.jar) into your project.
30 |
31 | 4. Create a MySQL database named "db_sales" and execute the following SQL script to create the "clients" table:
32 |
33 | ~~~sql
34 | CREATE TABLE clients (
35 | id INT NOT NULL AUTO_INCREMENT,
36 | name VARCHAR(255) NOT NULL,
37 | rg VARCHAR(15) NOT NULL,
38 | cpf VARCHAR(15) NOT NULL,
39 | email VARCHAR(100) NOT NULL,
40 | phone VARCHAR(15) NOT NULL,
41 | mobile VARCHAR(15) NOT NULL,
42 | zip_code VARCHAR(10) NOT NULL,
43 | address VARCHAR(255) NOT NULL,
44 | number INT NOT NULL,
45 | complement VARCHAR(255) NULL,
46 | neighborhood VARCHAR(100) NOT NULL,
47 | city VARCHAR(100) NOT NULL,
48 | state VARCHAR(2) NOT NULL,
49 | PRIMARY KEY (id)
50 | );
51 | ~~~
52 |
53 | 5. Change the database access credentials in the ConnectionFactory.java file to the credentials of your MySQL environment:
54 |
55 | ~~~java
56 | return DriverManager.getConnection("jdbc:mysql:///", "", "");
57 | ~~~
58 |
59 | 6. Run the project and test the CRUD operations using the graphical interface.
60 |
61 |
62 | Images of the program running
63 |
64 | 1. Screenshot of the 'Personal Data' tab without modifications:
65 |
66 | 
67 |
68 | 2. Screenshot of the 'Customer Search' tab without modifications:
69 |
70 | 
71 |
72 | 3. Inputting data for a new customer
73 |
74 | 
75 |
76 | 4. Displaying the newly registered 'customer' in the Customer Search tab
77 |
78 | 
79 |
80 | 5. Using the 'Edit' button to edit the data already included in the registration
81 |
82 | 
83 |
84 | 6. Using the 'Delete' button to remove a customer inserted in the database
85 |
86 | 
87 |
88 |
89 | Open Source
90 |
91 | This project is open source software under the MIT license. This means that anyone can use it, modify it, and contribute to the project. We are happy to receive contributions from the community and thank everyone who helps improve our project in advance!
92 |
93 | * MIT License
94 |
95 |
96 | Copyright (c) 2023, Vinicius Almeida
97 |
98 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
99 |
100 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
101 |
102 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
103 |
104 |
--------------------------------------------------------------------------------
/ScriptSQL/script.sql:
--------------------------------------------------------------------------------
1 | CREATE DATABASE db_sales;
2 |
3 |
4 | CREATE USER 'test'@'%' IDENTIFIED BY '123';
5 |
6 | GRANT ALL ON *.* TO 'test'@'%' WITH GRANT OPTION;
7 |
8 | FLUSH PRIVILEGES;
9 |
10 | USE db_sales;
11 |
12 | CREATE TABLE tb_clients (
13 | id INT AUTO_INCREMENT PRIMARY KEY,
14 | name VARCHAR(100),
15 | rg VARCHAR(100),
16 | -- RG stands for "Registro Geral" in Portuguese and it is a personal identification document in Brazil. It contains the individual's full name, photograph, signature, date of birth, place of birth, and registration number.
17 | cpf VARCHAR(20),
18 | -- CPF (Cadastro de Pessoas Físicas) is a unique identification number given to Brazilian citizens and resident aliens for tax and social security purposes.
19 | email VARCHAR(200),
20 | phone VARCHAR(30),
21 | mobile VARCHAR(30),
22 | zip_code VARCHAR(100),
23 | address VARCHAR(255),
24 | number INT,
25 | complement VARCHAR(200),
26 | neighborhood VARCHAR(100),
27 | city VARCHAR(100),
28 | state VARCHAR(2)
29 | );
30 |
31 |
--------------------------------------------------------------------------------
/images/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/viniciusvk1/Java-CRUD-with-MySQL-Connection/01ffb05bc5736638911981e79fae928d4c87d24c/images/1.png
--------------------------------------------------------------------------------
/images/2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/viniciusvk1/Java-CRUD-with-MySQL-Connection/01ffb05bc5736638911981e79fae928d4c87d24c/images/2.png
--------------------------------------------------------------------------------
/images/3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/viniciusvk1/Java-CRUD-with-MySQL-Connection/01ffb05bc5736638911981e79fae928d4c87d24c/images/3.png
--------------------------------------------------------------------------------
/images/4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/viniciusvk1/Java-CRUD-with-MySQL-Connection/01ffb05bc5736638911981e79fae928d4c87d24c/images/4.png
--------------------------------------------------------------------------------
/images/5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/viniciusvk1/Java-CRUD-with-MySQL-Connection/01ffb05bc5736638911981e79fae928d4c87d24c/images/5.png
--------------------------------------------------------------------------------
/images/6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/viniciusvk1/Java-CRUD-with-MySQL-Connection/01ffb05bc5736638911981e79fae928d4c87d24c/images/6.png
--------------------------------------------------------------------------------
/project/dao/ClientsDAO.java:
--------------------------------------------------------------------------------
1 | package br.com.project.dao;
2 |
3 | import br.com.project.jdbc.ConnectionFactory;
4 | import br.com.project.model.Clients;
5 | import java.sql.PreparedStatement;
6 | import java.sql.Connection;
7 | import java.sql.SQLException;
8 | import java.util.ArrayList;
9 | import java.util.List;
10 | import javax.swing.JOptionPane;
11 | import java.sql.ResultSet;
12 |
13 | public class ClientsDAO {
14 |
15 | private Connection con;
16 | private Object txtaddress;
17 |
18 | public ClientsDAO() {
19 | this.con = new ConnectionFactory().getConnection();
20 | }
21 |
22 | public void registerCustomer(Clients obj) {
23 |
24 | try {
25 |
26 | String sql = "INSERT INTO tb_clients (name, rg, cpf, email, phone, mobile, zip_code, address, number, complement, neighborhood, city, state)"
27 | + " VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)";
28 |
29 | PreparedStatement stmt = con.prepareStatement(sql);
30 | stmt.setString(1, obj.getName());
31 | stmt.setString(2, obj.getRg());
32 | stmt.setString(3, obj.getCpf());
33 | stmt.setString(4, obj.getEmail());
34 | stmt.setString(5, obj.getPhone());
35 | stmt.setString(6, obj.getMobile());
36 | stmt.setString(7, obj.getZip_code());
37 | stmt.setString(8, obj.getAddress());
38 | stmt.setInt(9, obj.getNumber());
39 | stmt.setString(10, obj.getComplement());
40 | stmt.setString(11, obj.getNeighborhood());
41 | stmt.setString(12, obj.getCity());
42 | stmt.setString(13, obj.getState());
43 |
44 | stmt.execute();
45 | stmt.close();
46 |
47 | JOptionPane.showMessageDialog(null, "Registered successfully!");
48 |
49 | } catch (SQLException error) {
50 |
51 | JOptionPane.showMessageDialog(null, "Error:!" + error);
52 |
53 | }
54 |
55 | }
56 |
57 | public void modifyCustomer(Clients obj) {
58 | try {
59 |
60 | String sql = "UPDATE tb_clients SET name=?, rg=?, cpf=?, email=?, phone=?, mobile=?, zip_code=?,"
61 | + "address=?, number=?, complement=?, neighborhood=?, city=?, state=? WHERE id =?";
62 |
63 | PreparedStatement stmt = con.prepareStatement(sql);
64 | stmt.setString(1, obj.getName());
65 | stmt.setString(2, obj.getRg());
66 | stmt.setString(3, obj.getCpf());
67 | stmt.setString(4, obj.getEmail());
68 | stmt.setString(5, obj.getPhone());
69 | stmt.setString(6, obj.getMobile());
70 | stmt.setString(7, obj.getZip_code());
71 | stmt.setString(8, obj.getAddress());
72 | stmt.setInt(9, obj.getNumber());
73 | stmt.setString(10, obj.getComplement());
74 | stmt.setString(11, obj.getNeighborhood());
75 | stmt.setString(12, obj.getCity());
76 | stmt.setString(13, obj.getState());
77 | stmt.setInt(14, obj.getId());
78 |
79 | stmt.execute();
80 | stmt.close();
81 |
82 | JOptionPane.showMessageDialog(null, "Successfully changed!");
83 |
84 | } catch (SQLException error) {
85 |
86 | JOptionPane.showMessageDialog(null, "Error:!" + error);
87 |
88 | }
89 | }
90 |
91 | public void deleteCustomer(Clients obj) {
92 | try {
93 |
94 | String sql = "DELETE FROM tb_clients where id = ?";
95 |
96 | PreparedStatement stmt = con.prepareStatement(sql);
97 | stmt.setInt(1, obj.getId());
98 |
99 | stmt.execute();
100 | stmt.close();
101 |
102 | JOptionPane.showMessageDialog(null, "Successfully excluded!");
103 |
104 | } catch (SQLException error) {
105 |
106 | JOptionPane.showMessageDialog(null, "Error:!" + error);
107 |
108 | }
109 | }
110 |
111 | public List listClients() {
112 | try {
113 |
114 | List list = new ArrayList<>();
115 |
116 | String sql = "SELECT * FROM tb_clients";
117 |
118 | PreparedStatement stmt = con.prepareStatement(sql);
119 | ResultSet rs = stmt.executeQuery();
120 |
121 | while (rs.next()) {
122 | Clients obj = new Clients();
123 |
124 | obj.setId(rs.getInt("id"));
125 | obj.setName(rs.getString("name"));
126 | obj.setRg(rs.getString("rg"));
127 | obj.setCpf(rs.getString("cpf"));
128 | obj.setEmail(rs.getString("email"));
129 | obj.setPhone(rs.getString("phone"));
130 | obj.setMobile(rs.getString("mobile"));
131 | obj.setZip_code(rs.getString("zip_code"));
132 | obj.setAddress(rs.getString("address"));
133 | obj.setNumber(rs.getInt("number"));
134 | obj.setComplement(rs.getString("complement"));
135 | obj.setNeighborhood(rs.getString("neighborhood"));
136 | obj.setCity(rs.getString("city"));
137 | obj.setState(rs.getString("state"));
138 |
139 | list.add(obj);
140 |
141 | }
142 |
143 | return list;
144 |
145 | } catch (SQLException error) {
146 | JOptionPane.showMessageDialog(null, "Error" + error);
147 | return null;
148 | }
149 | }
150 |
151 | public Clients searchByName(String name) {
152 | try {
153 |
154 | String sql = "SELECT * FROM tb_clients WHERE name = ?";
155 |
156 | PreparedStatement stmt = con.prepareStatement(sql);
157 | stmt.setString(1, name);
158 | ResultSet rs = stmt.executeQuery();
159 |
160 | Clients obj = new Clients();
161 |
162 | if (rs.next()) {
163 |
164 | obj.setId(rs.getInt("id"));
165 | obj.setName(rs.getString("name"));
166 | obj.setRg(rs.getString("rg"));
167 | obj.setCpf(rs.getString("cpf"));
168 | obj.setEmail(rs.getString("email"));
169 | obj.setPhone(rs.getString("phone"));
170 | obj.setMobile(rs.getString("mobile"));
171 | obj.setZip_code(rs.getString("zip_code"));
172 | obj.setAddress(rs.getString("address"));
173 | obj.setNumber(rs.getInt("number"));
174 | obj.setComplement(rs.getString("complement"));
175 | obj.setNeighborhood(rs.getString("neighborhood"));
176 | obj.setCity(rs.getString("city"));
177 | obj.setState(rs.getString("state"));
178 | }
179 | return obj;
180 |
181 | } catch (SQLException e) {
182 | JOptionPane.showMessageDialog(null, "Customer not found");
183 | return null;
184 | }
185 | }
186 |
187 | public List searchClients(String name) {
188 | try {
189 |
190 | List list = new ArrayList<>();
191 |
192 | String sql = "SELECT * FROM tb_clients WHERE name LIKE ?";
193 |
194 | PreparedStatement stmt = con.prepareStatement(sql);
195 | stmt.setString(1, name);
196 | ResultSet rs = stmt.executeQuery();
197 |
198 | while (rs.next()) {
199 | Clients obj = new Clients();
200 |
201 | obj.setId(rs.getInt("id"));
202 | obj.setName(rs.getString("name"));
203 | obj.setRg(rs.getString("rg"));
204 | obj.setCpf(rs.getString("cpf"));
205 | obj.setEmail(rs.getString("email"));
206 | obj.setPhone(rs.getString("phone"));
207 | obj.setMobile(rs.getString("mobile"));
208 | obj.setZip_code(rs.getString("zip_code"));
209 | obj.setAddress(rs.getString("address"));
210 | obj.setNumber(rs.getInt("number"));
211 | obj.setComplement(rs.getString("complement"));
212 | obj.setNeighborhood(rs.getString("neighborhood"));
213 | obj.setCity(rs.getString("city"));
214 | obj.setState(rs.getString("state"));
215 |
216 | list.add(obj);
217 |
218 | }
219 |
220 | return list;
221 |
222 | } catch (SQLException error) {
223 | JOptionPane.showMessageDialog(null, "Error" + error);
224 | return null;
225 | }
226 | }
227 |
228 | }
229 |
230 |
--------------------------------------------------------------------------------
/project/jdbc/ConnectionFactory.java:
--------------------------------------------------------------------------------
1 | package br.com.project.jdbc;
2 |
3 | import java.sql.Connection;
4 | import java.sql.DriverManager;
5 | import java.sql.SQLException;
6 |
7 | public class ConnectionFactory {
8 |
9 | public Connection getConnection(){
10 |
11 | try {
12 |
13 | return DriverManager.getConnection("jdbc:mysql://127.0.0.1/db_sales","test","123");
14 |
15 | } catch (SQLException erro) {
16 |
17 | throw new RuntimeException(erro);
18 |
19 | }
20 |
21 |
22 | }
23 |
24 |
25 | }
--------------------------------------------------------------------------------
/project/jdbc/TestConnection.java:
--------------------------------------------------------------------------------
1 | package br.com.project.jdbc;
2 |
3 | import javax.swing.JOptionPane;
4 |
5 | public class TestConnection {
6 |
7 | public static void main(String[] args) {
8 |
9 | try {
10 | new ConnectionFactory().getConnection();
11 | JOptionPane.showMessageDialog(null,"Successfully connected!");
12 | } catch (Exception error) {
13 | JOptionPane.showMessageDialog(null,"An error has occurred\"!" + error);
14 | }
15 |
16 | }
17 |
18 | }
--------------------------------------------------------------------------------
/project/jdbc/mysql-connector-java-5.1.47.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/viniciusvk1/Java-CRUD-with-MySQL-Connection/01ffb05bc5736638911981e79fae928d4c87d24c/project/jdbc/mysql-connector-java-5.1.47.jar
--------------------------------------------------------------------------------
/project/model/Clients.java:
--------------------------------------------------------------------------------
1 | package br.com.project.model;
2 |
3 | public class Clients {
4 |
5 | private int id;
6 | private String name;
7 | private String rg;
8 | private String cpf;
9 | private String email;
10 | private String phone;
11 | private String mobile;
12 | private String zip_code;
13 | private String address;
14 | private int number;
15 | private String complement;
16 | private String neighborhood;
17 | private String city;
18 | private String state;
19 |
20 | public int getId() {
21 | return id;
22 | }
23 |
24 | public void setId(int id) {
25 | this.id = id;
26 | }
27 |
28 | public String getName() {
29 | return name;
30 | }
31 |
32 | public void setName(String name) {
33 | this.name = name;
34 | }
35 |
36 | public String getRg() {
37 | return rg;
38 | }
39 |
40 | public void setRg(String rg) {
41 | this.rg = rg;
42 | }
43 |
44 | public String getCpf() {
45 | return cpf;
46 | }
47 |
48 | public void setCpf(String cpf) {
49 | this.cpf = cpf;
50 | }
51 |
52 | public String getEmail() {
53 | return email;
54 | }
55 |
56 | public void setEmail(String email) {
57 | this.email = email;
58 | }
59 |
60 | public String getPhone() {
61 | return phone;
62 | }
63 |
64 | public void setPhone(String phone) {
65 | this.phone = phone;
66 | }
67 |
68 | public String getMobile() {
69 | return mobile;
70 | }
71 |
72 | public void setMobile(String mobile) {
73 | this.mobile = mobile;
74 | }
75 |
76 | public String getZip_code() {
77 | return zip_code;
78 | }
79 |
80 | public void setZip_code(String zip_code) {
81 | this.zip_code = zip_code;
82 | }
83 |
84 | public String getAddress() {
85 | return address;
86 | }
87 |
88 | public void setAddress(String address) {
89 | this.address = address;
90 | }
91 |
92 | public int getNumber() {
93 | return number;
94 | }
95 |
96 | public void setNumber(int number) {
97 | this.number = number;
98 | }
99 |
100 | public String getComplement() {
101 | return complement;
102 | }
103 |
104 | public void setComplement(String complement) {
105 | this.complement = complement;
106 | }
107 |
108 | public String getNeighborhood() {
109 | return neighborhood;
110 | }
111 |
112 | public void setNeighborhood(String neighborhood) {
113 | this.neighborhood = neighborhood;
114 | }
115 |
116 | public String getCity() {
117 | return city;
118 | }
119 |
120 | public void setCity(String city) {
121 | this.city = city;
122 | }
123 |
124 | public String getState() {
125 | return state;
126 | }
127 |
128 | public void setState(String state) {
129 | this.state = state;
130 | }
131 |
132 |
133 | }
--------------------------------------------------------------------------------
/project/model/Utilities.java:
--------------------------------------------------------------------------------
1 | package br.com.project.model;
2 |
3 | import java.awt.Component;
4 | import javax.swing.JPanel;
5 | import javax.swing.JTextField;
6 |
7 | public class Utilities {
8 |
9 | public void clearScreen(JPanel container){
10 | Component components[] = container.getComponents();
11 | for (Component component : components){
12 | if (component instanceof JTextField){
13 | ((JTextField) component).setText(null);
14 | }
15 | }
16 | }
17 |
18 | }
--------------------------------------------------------------------------------
/project/view/FrmClients.form:
--------------------------------------------------------------------------------
1 |
2 |
3 |
782 |
--------------------------------------------------------------------------------
/project/view/FrmClients.java:
--------------------------------------------------------------------------------
1 | package br.com.project.view;
2 |
3 | import br.com.project.dao.ClientsDAO;
4 | import br.com.project.model.Clients;
5 | import br.com.project.model.Utilities;
6 | import java.util.List;
7 | import javax.swing.JOptionPane;
8 | import javax.swing.table.DefaultTableModel;
9 |
10 | public class FrmClients extends javax.swing.JFrame {
11 |
12 | public void LoadDatatable() {
13 |
14 | ClientsDAO dao = new ClientsDAO();
15 | List list = dao.listClients();
16 |
17 | DefaultTableModel data = (DefaultTableModel) tabelClients.getModel();
18 | data.setNumRows(0);
19 |
20 | for (Clients c : list) {
21 | data.addRow(new Object[]{
22 | c.getId(),
23 | c.getName(),
24 | c.getRg(),
25 | c.getCpf(),
26 | c.getEmail(),
27 | c.getPhone(),
28 | c.getMobile(),
29 | c.getZip_code(),
30 | c.getAddress(),
31 | c.getNumber(),
32 | c.getComplement(),
33 | c.getNeighborhood(),
34 | c.getCity(),
35 | c.getState()
36 | });
37 |
38 | }
39 |
40 | }
41 |
42 |
43 | public FrmClients() {
44 | initComponents();
45 | }
46 |
47 | @SuppressWarnings("unchecked")
48 | // //GEN-BEGIN:initComponents
49 | private void initComponents() {
50 |
51 | jPanel1 = new javax.swing.JPanel();
52 | jLabel1 = new javax.swing.JLabel();
53 | jTabbedPane1 = new javax.swing.JTabbedPane();
54 | paneldata = new javax.swing.JPanel();
55 | jLabel2 = new javax.swing.JLabel();
56 | txtid = new javax.swing.JTextField();
57 | txtname = new javax.swing.JTextField();
58 | jLabel3 = new javax.swing.JLabel();
59 | jLabel4 = new javax.swing.JLabel();
60 | txtemail = new javax.swing.JTextField();
61 | jLabel5 = new javax.swing.JLabel();
62 | txtmobile = new javax.swing.JFormattedTextField();
63 | jLabel6 = new javax.swing.JLabel();
64 | txtphone = new javax.swing.JFormattedTextField();
65 | jLabel7 = new javax.swing.JLabel();
66 | txtzip_code = new javax.swing.JFormattedTextField();
67 | jLabel8 = new javax.swing.JLabel();
68 | txtaddress = new javax.swing.JTextField();
69 | jLabel9 = new javax.swing.JLabel();
70 | txtnumber = new javax.swing.JTextField();
71 | jLabel10 = new javax.swing.JLabel();
72 | txtneighborhood = new javax.swing.JTextField();
73 | txtcity = new javax.swing.JTextField();
74 | jLabel11 = new javax.swing.JLabel();
75 | txtcomplement = new javax.swing.JTextField();
76 | jLabel12 = new javax.swing.JLabel();
77 | jLabel13 = new javax.swing.JLabel();
78 | cbuf = new javax.swing.JComboBox<>();
79 | jLabel14 = new javax.swing.JLabel();
80 | jLabel15 = new javax.swing.JLabel();
81 | txtrg = new javax.swing.JFormattedTextField();
82 | txtcpf = new javax.swing.JFormattedTextField();
83 | jPanel3 = new javax.swing.JPanel();
84 | jLabel44 = new javax.swing.JLabel();
85 | txtsearch = new javax.swing.JTextField();
86 | btnsearch = new javax.swing.JButton();
87 | jScrollPane1 = new javax.swing.JScrollPane();
88 | tabelClients = new javax.swing.JTable();
89 | jButton6 = new javax.swing.JButton();
90 | btnSave = new javax.swing.JButton();
91 | jButton8 = new javax.swing.JButton();
92 | jButton9 = new javax.swing.JButton();
93 |
94 | setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
95 | addWindowListener(new java.awt.event.WindowAdapter() {
96 | public void windowActivated(java.awt.event.WindowEvent evt) {
97 | formWindowActivated(evt);
98 | }
99 | });
100 |
101 | jPanel1.setBackground(new java.awt.Color(0, 102, 204));
102 |
103 | jLabel1.setFont(new java.awt.Font("Segoe UI", 0, 24)); // NOI18N
104 | jLabel1.setForeground(new java.awt.Color(255, 255, 255));
105 | jLabel1.setText("Customer Registration");
106 |
107 | javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
108 | jPanel1.setLayout(jPanel1Layout);
109 | jPanel1Layout.setHorizontalGroup(
110 | jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
111 | .addGroup(jPanel1Layout.createSequentialGroup()
112 | .addContainerGap()
113 | .addComponent(jLabel1)
114 | .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
115 | );
116 | jPanel1Layout.setVerticalGroup(
117 | jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
118 | .addGroup(jPanel1Layout.createSequentialGroup()
119 | .addGap(37, 37, 37)
120 | .addComponent(jLabel1)
121 | .addContainerGap(47, Short.MAX_VALUE))
122 | );
123 |
124 | jTabbedPane1.setBackground(new java.awt.Color(255, 255, 255));
125 |
126 | paneldata.setBackground(new java.awt.Color(204, 204, 204));
127 |
128 | jLabel2.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
129 | jLabel2.setText("ID:");
130 |
131 | txtid.setEditable(false);
132 | txtid.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
133 | txtid.addActionListener(new java.awt.event.ActionListener() {
134 | public void actionPerformed(java.awt.event.ActionEvent evt) {
135 | txtidActionPerformed(evt);
136 | }
137 | });
138 |
139 | txtname.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
140 | txtname.addActionListener(new java.awt.event.ActionListener() {
141 | public void actionPerformed(java.awt.event.ActionEvent evt) {
142 | txtnameActionPerformed(evt);
143 | }
144 | });
145 |
146 | jLabel3.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
147 | jLabel3.setText("Name: ");
148 |
149 | jLabel4.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
150 | jLabel4.setText("E-mail:");
151 |
152 | txtemail.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
153 | txtemail.addActionListener(new java.awt.event.ActionListener() {
154 | public void actionPerformed(java.awt.event.ActionEvent evt) {
155 | txtemailActionPerformed(evt);
156 | }
157 | });
158 |
159 | jLabel5.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
160 | jLabel5.setText("Mobile Phone Number:");
161 |
162 | try {
163 | txtmobile.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##) # #### - ####")));
164 | } catch (java.text.ParseException ex) {
165 | ex.printStackTrace();
166 | }
167 | txtmobile.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
168 | txtmobile.addActionListener(new java.awt.event.ActionListener() {
169 | public void actionPerformed(java.awt.event.ActionEvent evt) {
170 | txtmobileActionPerformed(evt);
171 | }
172 | });
173 |
174 | jLabel6.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
175 | jLabel6.setText("Phone (include area code):");
176 |
177 | try {
178 | txtphone.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##) # #### - ####")));
179 | } catch (java.text.ParseException ex) {
180 | ex.printStackTrace();
181 | }
182 | txtphone.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
183 | txtphone.addActionListener(new java.awt.event.ActionListener() {
184 | public void actionPerformed(java.awt.event.ActionEvent evt) {
185 | txtphoneActionPerformed(evt);
186 | }
187 | });
188 |
189 | jLabel7.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
190 | jLabel7.setText("Zip Code:");
191 |
192 | try {
193 | txtzip_code.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##### - ###")));
194 | } catch (java.text.ParseException ex) {
195 | ex.printStackTrace();
196 | }
197 | txtzip_code.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
198 | txtzip_code.addActionListener(new java.awt.event.ActionListener() {
199 | public void actionPerformed(java.awt.event.ActionEvent evt) {
200 | txtzip_codeActionPerformed(evt);
201 | }
202 | });
203 | txtzip_code.addKeyListener(new java.awt.event.KeyAdapter() {
204 | public void keyPressed(java.awt.event.KeyEvent evt) {
205 | txtzip_codeKeyPressed(evt);
206 | }
207 | });
208 |
209 | jLabel8.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
210 | jLabel8.setText("Address:");
211 |
212 | txtaddress.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
213 | txtaddress.addActionListener(new java.awt.event.ActionListener() {
214 | public void actionPerformed(java.awt.event.ActionEvent evt) {
215 | txtaddressActionPerformed(evt);
216 | }
217 | });
218 |
219 | jLabel9.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
220 | jLabel9.setText("House/apartment number:");
221 |
222 | txtnumber.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
223 | txtnumber.addActionListener(new java.awt.event.ActionListener() {
224 | public void actionPerformed(java.awt.event.ActionEvent evt) {
225 | txtnumberActionPerformed(evt);
226 | }
227 | });
228 |
229 | jLabel10.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
230 | jLabel10.setText("Neighborhood:");
231 |
232 | txtneighborhood.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
233 | txtneighborhood.addActionListener(new java.awt.event.ActionListener() {
234 | public void actionPerformed(java.awt.event.ActionEvent evt) {
235 | txtneighborhoodActionPerformed(evt);
236 | }
237 | });
238 |
239 | txtcity.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
240 | txtcity.addActionListener(new java.awt.event.ActionListener() {
241 | public void actionPerformed(java.awt.event.ActionEvent evt) {
242 | txtcityActionPerformed(evt);
243 | }
244 | });
245 |
246 | jLabel11.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
247 | jLabel11.setText("City:");
248 |
249 | txtcomplement.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
250 | txtcomplement.addActionListener(new java.awt.event.ActionListener() {
251 | public void actionPerformed(java.awt.event.ActionEvent evt) {
252 | txtcomplementActionPerformed(evt);
253 | }
254 | });
255 |
256 | jLabel12.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
257 | jLabel12.setText("Complement:");
258 |
259 | jLabel13.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
260 | jLabel13.setText("UF:");
261 |
262 | cbuf.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "AC", "AL", "AP", "AM", "BA ", "CE", "DF", "ES", "GO", "MA", "MT", "MS", "MG", "PA", "PB", "PR", "PE", "PI", "RJ", "RN", "RS", "RO", "RR", "SC", "SP", "SE", "TO" }));
263 | cbuf.addActionListener(new java.awt.event.ActionListener() {
264 | public void actionPerformed(java.awt.event.ActionEvent evt) {
265 | cbufActionPerformed(evt);
266 | }
267 | });
268 |
269 | jLabel14.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
270 | jLabel14.setText("RG:");
271 |
272 | jLabel15.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
273 | jLabel15.setText("CPF:");
274 |
275 | try {
276 | txtrg.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##.###.###-##")));
277 | } catch (java.text.ParseException ex) {
278 | ex.printStackTrace();
279 | }
280 | txtrg.addActionListener(new java.awt.event.ActionListener() {
281 | public void actionPerformed(java.awt.event.ActionEvent evt) {
282 | txtrgActionPerformed(evt);
283 | }
284 | });
285 |
286 | try {
287 | txtcpf.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
288 | } catch (java.text.ParseException ex) {
289 | ex.printStackTrace();
290 | }
291 | txtcpf.addActionListener(new java.awt.event.ActionListener() {
292 | public void actionPerformed(java.awt.event.ActionEvent evt) {
293 | txtcpfActionPerformed(evt);
294 | }
295 | });
296 |
297 | javax.swing.GroupLayout paneldataLayout = new javax.swing.GroupLayout(paneldata);
298 | paneldata.setLayout(paneldataLayout);
299 | paneldataLayout.setHorizontalGroup(
300 | paneldataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
301 | .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, paneldataLayout.createSequentialGroup()
302 | .addContainerGap(21, Short.MAX_VALUE)
303 | .addGroup(paneldataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
304 | .addGroup(paneldataLayout.createSequentialGroup()
305 | .addComponent(jLabel7)
306 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
307 | .addComponent(txtzip_code, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
308 | .addGap(18, 18, 18)
309 | .addComponent(jLabel8)
310 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
311 | .addComponent(txtaddress, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE)
312 | .addGap(72, 72, 72)
313 | .addComponent(jLabel9)
314 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
315 | .addComponent(txtnumber, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
316 | .addGroup(paneldataLayout.createSequentialGroup()
317 | .addComponent(jLabel2)
318 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
319 | .addComponent(txtid, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
320 | .addGroup(paneldataLayout.createSequentialGroup()
321 | .addGroup(paneldataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
322 | .addComponent(jLabel4)
323 | .addComponent(jLabel3))
324 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
325 | .addGroup(paneldataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
326 | .addComponent(txtname, javax.swing.GroupLayout.PREFERRED_SIZE, 365, javax.swing.GroupLayout.PREFERRED_SIZE)
327 | .addGroup(paneldataLayout.createSequentialGroup()
328 | .addComponent(txtemail, javax.swing.GroupLayout.PREFERRED_SIZE, 365, javax.swing.GroupLayout.PREFERRED_SIZE)
329 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
330 | .addComponent(jLabel5)
331 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
332 | .addComponent(txtmobile, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
333 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
334 | .addComponent(jLabel6)
335 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
336 | .addComponent(txtphone, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE))))
337 | .addGroup(paneldataLayout.createSequentialGroup()
338 | .addComponent(jLabel10)
339 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
340 | .addComponent(txtneighborhood, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
341 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
342 | .addComponent(jLabel11)
343 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
344 | .addComponent(txtcity, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
345 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
346 | .addComponent(jLabel12)
347 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
348 | .addComponent(txtcomplement, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
349 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
350 | .addComponent(jLabel13)
351 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
352 | .addComponent(cbuf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
353 | .addGroup(paneldataLayout.createSequentialGroup()
354 | .addComponent(jLabel14)
355 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
356 | .addComponent(txtrg, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
357 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
358 | .addComponent(jLabel15)
359 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
360 | .addComponent(txtcpf, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)))
361 | .addGap(18, 18, 18))
362 | );
363 | paneldataLayout.setVerticalGroup(
364 | paneldataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
365 | .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, paneldataLayout.createSequentialGroup()
366 | .addContainerGap(66, Short.MAX_VALUE)
367 | .addGroup(paneldataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
368 | .addComponent(jLabel2)
369 | .addComponent(txtid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
370 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
371 | .addGroup(paneldataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
372 | .addComponent(jLabel3)
373 | .addComponent(txtname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
374 | .addGap(9, 9, 9)
375 | .addGroup(paneldataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
376 | .addComponent(jLabel4)
377 | .addComponent(txtemail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
378 | .addComponent(jLabel5)
379 | .addComponent(txtmobile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
380 | .addComponent(jLabel6)
381 | .addComponent(txtphone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
382 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
383 | .addGroup(paneldataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
384 | .addComponent(jLabel7)
385 | .addComponent(txtzip_code, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
386 | .addComponent(jLabel8)
387 | .addComponent(txtaddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
388 | .addComponent(jLabel9)
389 | .addComponent(txtnumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
390 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
391 | .addGroup(paneldataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
392 | .addComponent(jLabel10)
393 | .addComponent(txtneighborhood, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
394 | .addComponent(jLabel11)
395 | .addComponent(txtcity, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
396 | .addComponent(jLabel12)
397 | .addComponent(txtcomplement, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
398 | .addComponent(jLabel13)
399 | .addComponent(cbuf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
400 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
401 | .addGroup(paneldataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
402 | .addComponent(jLabel14)
403 | .addComponent(jLabel15)
404 | .addComponent(txtrg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
405 | .addComponent(txtcpf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
406 | .addGap(45, 45, 45))
407 | );
408 |
409 | jTabbedPane1.addTab("Personal Data", paneldata);
410 |
411 | jPanel3.setBackground(new java.awt.Color(204, 204, 204));
412 |
413 | jLabel44.setText("Name:");
414 |
415 | txtsearch.addActionListener(new java.awt.event.ActionListener() {
416 | public void actionPerformed(java.awt.event.ActionEvent evt) {
417 | txtsearchActionPerformed(evt);
418 | }
419 | });
420 | txtsearch.addKeyListener(new java.awt.event.KeyAdapter() {
421 | public void keyPressed(java.awt.event.KeyEvent evt) {
422 | txtsearchKeyPressed(evt);
423 | }
424 | });
425 |
426 | btnsearch.setText("Search");
427 | btnsearch.addActionListener(new java.awt.event.ActionListener() {
428 | public void actionPerformed(java.awt.event.ActionEvent evt) {
429 | btnsearchActionPerformed(evt);
430 | }
431 | });
432 |
433 | tabelClients.setModel(new javax.swing.table.DefaultTableModel(
434 | new Object [][] {
435 |
436 | },
437 | new String [] {
438 | "ID", "Name", "RG", "CPF", "E-Mail", "Phone", "Mobile Phone Number", "Zip Code", "Address", "House Number", "Complement", "Neighborhood", "City", "UF"
439 | }
440 | ));
441 | tabelClients.addMouseListener(new java.awt.event.MouseAdapter() {
442 | public void mouseClicked(java.awt.event.MouseEvent evt) {
443 | tabelClientsMouseClicked(evt);
444 | }
445 | });
446 | jScrollPane1.setViewportView(tabelClients);
447 | if (tabelClients.getColumnModel().getColumnCount() > 0) {
448 | tabelClients.getColumnModel().getColumn(4).setResizable(false);
449 | }
450 |
451 | javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
452 | jPanel3.setLayout(jPanel3Layout);
453 | jPanel3Layout.setHorizontalGroup(
454 | jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
455 | .addGroup(jPanel3Layout.createSequentialGroup()
456 | .addContainerGap()
457 | .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
458 | .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1037, Short.MAX_VALUE)
459 | .addGroup(jPanel3Layout.createSequentialGroup()
460 | .addComponent(jLabel44)
461 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
462 | .addComponent(txtsearch, javax.swing.GroupLayout.PREFERRED_SIZE, 330, javax.swing.GroupLayout.PREFERRED_SIZE)
463 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
464 | .addComponent(btnsearch)
465 | .addGap(0, 0, Short.MAX_VALUE)))
466 | .addContainerGap())
467 | );
468 | jPanel3Layout.setVerticalGroup(
469 | jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
470 | .addGroup(jPanel3Layout.createSequentialGroup()
471 | .addGap(21, 21, 21)
472 | .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
473 | .addComponent(jLabel44)
474 | .addComponent(txtsearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
475 | .addComponent(btnsearch))
476 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
477 | .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 256, javax.swing.GroupLayout.PREFERRED_SIZE)
478 | .addGap(36, 36, 36))
479 | );
480 |
481 | jTabbedPane1.addTab("Customer Search", jPanel3);
482 |
483 | jButton6.setText("NEW");
484 | jButton6.addActionListener(new java.awt.event.ActionListener() {
485 | public void actionPerformed(java.awt.event.ActionEvent evt) {
486 | jButton6ActionPerformed(evt);
487 | }
488 | });
489 |
490 | btnSave.setText("SAVE");
491 | btnSave.addActionListener(new java.awt.event.ActionListener() {
492 | public void actionPerformed(java.awt.event.ActionEvent evt) {
493 | btnSaveActionPerformed(evt);
494 | }
495 | });
496 |
497 | jButton8.setText("EDIT");
498 | jButton8.addActionListener(new java.awt.event.ActionListener() {
499 | public void actionPerformed(java.awt.event.ActionEvent evt) {
500 | jButton8ActionPerformed(evt);
501 | }
502 | });
503 |
504 | jButton9.setText("DELETE");
505 | jButton9.addActionListener(new java.awt.event.ActionListener() {
506 | public void actionPerformed(java.awt.event.ActionEvent evt) {
507 | jButton9ActionPerformed(evt);
508 | }
509 | });
510 |
511 | javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
512 | getContentPane().setLayout(layout);
513 | layout.setHorizontalGroup(
514 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
515 | .addGroup(layout.createSequentialGroup()
516 | .addContainerGap()
517 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
518 | .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
519 | .addComponent(jTabbedPane1))
520 | .addContainerGap())
521 | .addGroup(layout.createSequentialGroup()
522 | .addGap(338, 338, 338)
523 | .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
524 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
525 | .addComponent(btnSave)
526 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
527 | .addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
528 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
529 | .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
530 | .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
531 | );
532 |
533 | layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnSave, jButton6, jButton8, jButton9});
534 |
535 | layout.setVerticalGroup(
536 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
537 | .addGroup(layout.createSequentialGroup()
538 | .addContainerGap()
539 | .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
540 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
541 | .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 345, javax.swing.GroupLayout.PREFERRED_SIZE)
542 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
543 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
544 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
545 | .addComponent(jButton6)
546 | .addComponent(btnSave)
547 | .addComponent(jButton8))
548 | .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
549 | .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
550 | );
551 |
552 | layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btnSave, jButton6, jButton8, jButton9});
553 |
554 | pack();
555 | }// //GEN-END:initComponents
556 |
557 | private void txtidActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtidActionPerformed
558 | // TODO add your handling code here:
559 | }//GEN-LAST:event_txtidActionPerformed
560 |
561 | private void txtnameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtnameActionPerformed
562 | // TODO add your handling code here:
563 | }//GEN-LAST:event_txtnameActionPerformed
564 |
565 | private void txtemailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtemailActionPerformed
566 | // TODO add your handling code here:
567 | }//GEN-LAST:event_txtemailActionPerformed
568 |
569 | private void txtmobileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtmobileActionPerformed
570 | // TODO add your handling code here:
571 | }//GEN-LAST:event_txtmobileActionPerformed
572 |
573 | private void txtphoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtphoneActionPerformed
574 | // TODO add your handling code here:
575 | }//GEN-LAST:event_txtphoneActionPerformed
576 |
577 | private void txtzip_codeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtzip_codeActionPerformed
578 |
579 | }//GEN-LAST:event_txtzip_codeActionPerformed
580 |
581 | private void txtaddressActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtaddressActionPerformed
582 | // TODO add your handling code here:
583 | }//GEN-LAST:event_txtaddressActionPerformed
584 |
585 | private void txtnumberActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtnumberActionPerformed
586 | // TODO add your handling code here:
587 | }//GEN-LAST:event_txtnumberActionPerformed
588 |
589 | private void txtneighborhoodActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtneighborhoodActionPerformed
590 | // TODO add your handling code here:
591 | }//GEN-LAST:event_txtneighborhoodActionPerformed
592 |
593 | private void txtcityActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtcityActionPerformed
594 | // TODO add your handling code here:
595 | }//GEN-LAST:event_txtcityActionPerformed
596 |
597 | private void txtcomplementActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtcomplementActionPerformed
598 | // TODO add your handling code here:
599 | }//GEN-LAST:event_txtcomplementActionPerformed
600 |
601 | private void cbufActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbufActionPerformed
602 | // TODO add your handling code here:
603 | }//GEN-LAST:event_cbufActionPerformed
604 |
605 | private void txtrgActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtrgActionPerformed
606 | // TODO add your handling code here:
607 | }//GEN-LAST:event_txtrgActionPerformed
608 |
609 | private void txtcpfActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtcpfActionPerformed
610 | // TODO add your handling code here:
611 | }//GEN-LAST:event_txtcpfActionPerformed
612 |
613 | private void txtsearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtsearchActionPerformed
614 | // TODO add your handling code here:
615 | }//GEN-LAST:event_txtsearchActionPerformed
616 |
617 | private void btnsearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnsearchActionPerformed
618 |
619 | String name = "%" + txtsearch.getText() + "%";
620 |
621 | ClientsDAO dao = new ClientsDAO();
622 | List list = dao.searchClients(name);
623 |
624 | DefaultTableModel data = (DefaultTableModel) tabelClients.getModel();
625 | data.setNumRows(0);
626 |
627 | for (Clients c : list) {
628 | data.addRow(new Object[]{
629 | c.getId(),
630 | c.getName(),
631 | c.getRg(),
632 | c.getCpf(),
633 | c.getEmail(),
634 | c.getPhone(),
635 | c.getMobile(),
636 | c.getZip_code(),
637 | c.getAddress(),
638 | c.getNumber(),
639 | c.getComplement(),
640 | c.getNeighborhood(),
641 | c.getCity(),
642 | c.getState()
643 | });
644 | }//GEN-LAST:event_btnsearchActionPerformed
645 |
646 | }
647 |
648 | private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
649 | new Utilities().clearScreen(paneldata);
650 | }//GEN-LAST:event_jButton6ActionPerformed
651 |
652 | private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
653 |
654 | Clients obj = new Clients();
655 |
656 | obj.setName(txtname.getText());
657 | obj.setRg(txtrg.getText());
658 | obj.setCpf(txtcpf.getText());
659 | obj.setEmail(txtemail.getText());
660 | obj.setPhone(txtphone.getText());
661 | obj.setMobile(txtmobile.getText());
662 | obj.setZip_code(txtzip_code.getText());
663 | obj.setAddress(txtaddress.getText());
664 | obj.setNumber(Integer.parseInt(txtnumber.getText()));
665 | obj.setComplement(txtcomplement.getText());
666 | obj.setNeighborhood(txtneighborhood.getText());
667 | obj.setCity(txtcity.getText());
668 | obj.setState(cbuf.getSelectedItem().toString());
669 |
670 | ClientsDAO dao = new ClientsDAO();
671 |
672 | dao.registerCustomer(obj);
673 |
674 | new Utilities().clearScreen(paneldata);
675 |
676 |
677 | }//GEN-LAST:event_btnSaveActionPerformed
678 |
679 | private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
680 | LoadDatatable();
681 | }//GEN-LAST:event_formWindowActivated
682 |
683 | private void tabelClientsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabelClientsMouseClicked
684 | jTabbedPane1.setSelectedIndex(0);
685 |
686 | txtid.setText(tabelClients.getValueAt(tabelClients.getSelectedRow(), 0).toString());
687 | txtname.setText(tabelClients.getValueAt(tabelClients.getSelectedRow(), 1).toString());
688 | txtrg.setText(tabelClients.getValueAt(tabelClients.getSelectedRow(), 2).toString());
689 | txtcpf.setText(tabelClients.getValueAt(tabelClients.getSelectedRow(), 3).toString());
690 | txtemail.setText(tabelClients.getValueAt(tabelClients.getSelectedRow(), 4).toString());
691 | txtphone.setText(tabelClients.getValueAt(tabelClients.getSelectedRow(), 5).toString());
692 | txtmobile.setText(tabelClients.getValueAt(tabelClients.getSelectedRow(), 6).toString());
693 | txtzip_code.setText(tabelClients.getValueAt(tabelClients.getSelectedRow(), 7).toString());
694 | txtaddress.setText(tabelClients.getValueAt(tabelClients.getSelectedRow(), 8).toString());
695 | txtnumber.setText(tabelClients.getValueAt(tabelClients.getSelectedRow(), 9).toString());
696 | txtcomplement.setText(tabelClients.getValueAt(tabelClients.getSelectedRow(), 10).toString());
697 | txtneighborhood.setText(tabelClients.getValueAt(tabelClients.getSelectedRow(), 11).toString());
698 | txtcity.setText(tabelClients.getValueAt(tabelClients.getSelectedRow(), 12).toString());
699 | cbuf.setSelectedItem(tabelClients.getValueAt(tabelClients.getSelectedRow(), 13).toString());
700 |
701 | }//GEN-LAST:event_tabelClientsMouseClicked
702 |
703 | private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
704 | Clients obj = new Clients();
705 |
706 | obj.setName(txtname.getText());
707 | obj.setRg(txtrg.getText());
708 | obj.setCpf(txtcpf.getText());
709 | obj.setEmail(txtemail.getText());
710 | obj.setPhone(txtphone.getText());
711 | obj.setMobile(txtmobile.getText());
712 | obj.setZip_code(txtzip_code.getText());
713 | obj.setAddress(txtaddress.getText());
714 | obj.setNumber(Integer.parseInt(txtnumber.getText()));
715 | obj.setComplement(txtcomplement.getText());
716 | obj.setNeighborhood(txtneighborhood.getText());
717 | obj.setCity(txtcity.getText());
718 | obj.setState(cbuf.getSelectedItem().toString());
719 |
720 | obj.setId(Integer.parseInt(txtid.getText()));
721 |
722 | ClientsDAO dao = new ClientsDAO();
723 |
724 | dao.modifyCustomer(obj);
725 |
726 | new Utilities().clearScreen(paneldata);
727 |
728 | }//GEN-LAST:event_jButton8ActionPerformed
729 |
730 | private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
731 | Clients obj = new Clients();
732 |
733 | obj.setId(Integer.parseInt(txtid.getText()));
734 |
735 | ClientsDAO dao = new ClientsDAO();
736 |
737 | dao.deleteCustomer(obj);
738 | new Utilities().clearScreen(paneldata);
739 | }//GEN-LAST:event_jButton9ActionPerformed
740 |
741 | private void txtsearchKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtsearchKeyPressed
742 |
743 | String name = "%" + txtsearch.getText() + "%";
744 |
745 | ClientsDAO dao = new ClientsDAO();
746 | List list = dao.searchClients(name);
747 |
748 | DefaultTableModel data = (DefaultTableModel) tabelClients.getModel();
749 | data.setNumRows(0);
750 |
751 | for (Clients c : list) {
752 | data.addRow(new Object[]{
753 | c.getId(),
754 | c.getName(),
755 | c.getRg(),
756 | c.getCpf(),
757 | c.getEmail(),
758 | c.getPhone(),
759 | c.getMobile(),
760 | c.getZip_code(),
761 | c.getAddress(),
762 | c.getNumber(),
763 | c.getComplement(),
764 | c.getNeighborhood(),
765 | c.getCity(),
766 | c.getState()
767 | });
768 | }
769 |
770 | }//GEN-LAST:event_txtsearchKeyPressed
771 |
772 | private void txtzip_codeKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtzip_codeKeyPressed
773 |
774 | }//GEN-LAST:event_txtzip_codeKeyPressed
775 |
776 | /**
777 | * @param args the command line arguments
778 | */
779 | public static void main(String args[]) {
780 | /* Set the Nimbus look and feel */
781 | //
782 | /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
783 | * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
784 | */
785 | try {
786 | for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
787 | if ("Nimbus".equals(info.getName())) {
788 | javax.swing.UIManager.setLookAndFeel(info.getClassName());
789 | break;
790 | }
791 | }
792 | } catch (ClassNotFoundException ex) {
793 | java.util.logging.Logger.getLogger(FrmClients.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
794 | } catch (InstantiationException ex) {
795 | java.util.logging.Logger.getLogger(FrmClients.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
796 | } catch (IllegalAccessException ex) {
797 | java.util.logging.Logger.getLogger(FrmClients.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
798 | } catch (javax.swing.UnsupportedLookAndFeelException ex) {
799 | java.util.logging.Logger.getLogger(FrmClients.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
800 | }
801 | //
802 |
803 | /* Create and display the form */
804 | java.awt.EventQueue.invokeLater(new Runnable() {
805 | public void run() {
806 | new FrmClients().setVisible(true);
807 | }
808 | });
809 |
810 | }
811 |
812 | // Variables declaration - do not modify//GEN-BEGIN:variables
813 | private javax.swing.JButton btnSave;
814 | private javax.swing.JButton btnsearch;
815 | private javax.swing.JComboBox cbuf;
816 | private javax.swing.JButton jButton6;
817 | private javax.swing.JButton jButton8;
818 | private javax.swing.JButton jButton9;
819 | private javax.swing.JLabel jLabel1;
820 | private javax.swing.JLabel jLabel10;
821 | private javax.swing.JLabel jLabel11;
822 | private javax.swing.JLabel jLabel12;
823 | private javax.swing.JLabel jLabel13;
824 | private javax.swing.JLabel jLabel14;
825 | private javax.swing.JLabel jLabel15;
826 | private javax.swing.JLabel jLabel2;
827 | private javax.swing.JLabel jLabel3;
828 | private javax.swing.JLabel jLabel4;
829 | private javax.swing.JLabel jLabel44;
830 | private javax.swing.JLabel jLabel5;
831 | private javax.swing.JLabel jLabel6;
832 | private javax.swing.JLabel jLabel7;
833 | private javax.swing.JLabel jLabel8;
834 | private javax.swing.JLabel jLabel9;
835 | private javax.swing.JPanel jPanel1;
836 | private javax.swing.JPanel jPanel3;
837 | private javax.swing.JScrollPane jScrollPane1;
838 | private javax.swing.JTabbedPane jTabbedPane1;
839 | private javax.swing.JPanel paneldata;
840 | private javax.swing.JTable tabelClients;
841 | private javax.swing.JTextField txtaddress;
842 | private javax.swing.JTextField txtcity;
843 | private javax.swing.JTextField txtcomplement;
844 | private javax.swing.JFormattedTextField txtcpf;
845 | private javax.swing.JTextField txtemail;
846 | private javax.swing.JTextField txtid;
847 | private javax.swing.JFormattedTextField txtmobile;
848 | private javax.swing.JTextField txtname;
849 | private javax.swing.JTextField txtneighborhood;
850 | private javax.swing.JTextField txtnumber;
851 | private javax.swing.JFormattedTextField txtphone;
852 | private javax.swing.JFormattedTextField txtrg;
853 | private javax.swing.JTextField txtsearch;
854 | private javax.swing.JFormattedTextField txtzip_code;
855 | // End of variables declaration//GEN-END:variables
856 | }
857 |
--------------------------------------------------------------------------------