// A small project type program of phonebook system using LinkList as storage in which a user can add, update, delete and search records. Here, the records are not stored permanently. You will have to add new records afresh each time you run the program.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import javax.swing.table.*;
class Details{
private String contact_no , name;
private String email_address, address;
public Details(){}
public Details(String name,String contact,String email,String address){
putName(name);
putContact(contact);
putEmail(email);
putAddress(address);
}
public void putName(String name){
this.name = name;
}
public String getName(){
return name;
}
public void putContact(String contact){
contact_no = contact;
}
public String getContact(){
return contact_no;
}
public void putEmail(String email){
email_address = email;
}
public String getEmail(){
return email_address;
}
public void putAddress(String address){
this.address = address;
}
public String getAddress(){
return address;
}
}
class Table{
class MyModel extends DefaultTableModel{
public MyModel(Object[] columnNames , int rowcount){
super(columnNames,rowcount);
}
public boolean isCellEditable(int row , int column){
if(column == 1)
return false;
else return true;
}
public void setValueAt(Object aValue,int row, int column){
int temp = 0;
if(column == 2){
for(int i = 0 ; i < aValue.toString().length() ; i++){
char c = aValue.toString().charAt(i);
if(i == 0){
if( !Character.isDigit(c) && ! (c == '+')){
temp++;
}
}
else{
if(!(Character.isDigit(c)) && !(c == ',') && !(c == '+')){
temp++;
}
}
}
if(temp == 0){
super.setValueAt(aValue,row,column);
}
}
else if(column == 3){
int atpos = aValue.toString().indexOf("@");
int dotpos = aValue.toString().indexOf(".");
boolean at = !(atpos > 0);
boolean dot = !(dotpos > (atpos+1));
boolean check = (dotpos == (aValue.toString().length()-1));
if( aValue.toString().trim().equals("") || at || dot || check){
temp++;
}
if(temp == 0){
super.setValueAt(aValue,row,column);
}
}
else{
super.setValueAt(aValue,row,column);
}
}
}
JTable table;
MyModel dm;
String[] column_names = {"S.No.","Name","Contact No","Email Address","Address"};
public Table(){
dm = new MyModel(column_names,0);
table = new JTable(dm);
table.setAutoCreateRowSorter(true);
}
public JTable getTable(){
return table;
}
public DefaultTableModel getDm(){
return dm;
}
public void tableData(JPanel pnl){
JScrollPane scroll = new JScrollPane(table);
pnl.add(scroll,BorderLayout.CENTER);
}
public void addRecordToTable(Details temp){
int row = dm.getRowCount();
String[] rowdata = {""+ (row+1) , temp.getName() , temp.getContact() , temp.getEmail() , temp.getAddress() };
dm.insertRow(row, rowdata);
}
}
class Phonebook extends JFrame implements ActionListener{
private JTabbedPane tabbedpane;
private JPanel pnladdrecord,pnlsearch;
private JLabel lblname,lblcontact,lblemail,lbladdress,lblverification,lblstatus;
private JTextField txtname,txtcontact,txtemail,txtaddress,txtnamesearch;
private JButton btnadd,btnsearch,btndelete,btnSave;
private LinkedList<Details> detail = new LinkedList<>();
private Table tblrecord,tblsearchrecord;
public Phonebook(String title){
super(title);
setLayout(new GridLayout(1,1));
setBounds(300,200,700,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
initialize();
// pack();
}
public void initialize(){
tabbedpane = new JTabbedPane();
pnladdrecord = new JPanel();
AddPanel();
tabbedpane.addTab("Add Record",pnladdrecord);
pnlsearch = new JPanel();
searchPanel();
tabbedpane.addTab("Search Record",pnlsearch);
add(tabbedpane);
}
public void AddPanel(){
pnladdrecord.setLayout(new BorderLayout());
JPanel pnladd = new JPanel();
pnladd.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
//First row
c.gridy = 0;
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.PAGE_START;
c.gridx = 0;
lblname = new JLabel("Name :");
pnladd.add(lblname,c);
c.gridx++;
txtname = new JTextField("",10);
txtname.addKeyListener(new KeyAdapter(){
public void keyTyped(KeyEvent ke){
char c = ke.getKeyChar();
if(!(c >= 'a' && c <= 'z') && !(c >= 'A' && c <= 'Z') && !(c == ' '))
ke.consume();
}
});
pnladd.add(txtname,c);
//Second row
c.gridy++;
c.gridx = 0;
lblcontact = new JLabel("Contact No:");
pnladd.add(lblcontact ,c);
c.gridx++;
c.gridwidth = 2;
txtcontact = new JTextField("",10);
txtcontact.addKeyListener(new KeyAdapter(){
public void keyTyped(KeyEvent ke){
char c = ke.getKeyChar();
if(txtcontact.getCaretPosition() == 0){
if((txtcontact.getText().indexOf('+') == -1)){
if(!(Character.isDigit(c)) && !(c == ',') && !(c == '+') )
ke.consume();
}
else{
ke.consume();
}
}
else{
int comma = txtcontact.getText().indexOf(',');
if((txtcontact.getCaretPosition() == (comma+1))){
if(!(Character.isDigit(c)) && !(c == ',') && !(c == '+') )
ke.consume();
}
else{
if(!(Character.isDigit(c)) && !(c == ','))
ke.consume();
}
}
}
});
pnladd.add(txtcontact,c);
//Third row
c.gridy++;
c.gridwidth = 1;
c.gridx = 0;
lblemail = new JLabel("Email Address :");
pnladd.add(lblemail ,c);
c.gridx++;
c.gridwidth = 2;
txtemail = new JTextField("",10);
txtemail.addKeyListener(new KeyAdapter(){
public void keyTyped(KeyEvent ke){
char c = ke.getKeyChar();
int at = txtemail.getText().indexOf('@');
int dot = txtemail.getText().indexOf('.');
if(txtemail.getCaretPosition() == 0){
if((c == '@') || (c == '.'))
ke.consume();
}
else{
if(at == -1){
if((c == '.'))
ke.consume();
}
else if(at != -1 && dot == -1 && txtemail.getCaretPosition() > (at+1)){
if((c == '@'))
ke.consume();
}
else if(at != -1 && dot == -1 && txtemail.getCaretPosition() == (at+1)){
if((c == '@')|| (c == '.'))
ke.consume();
}
else if(at != -1 && dot != -1){
if((c == '@') || (c == '.'))
ke.consume();
}
}
}
});
pnladd.add(txtemail,c);
//Fourth row
c.gridy++;
c.gridwidth = 1;
c.gridx = 0;
lbladdress = new JLabel("Address :");
pnladd.add(lbladdress ,c);
c.gridx++;
c.gridwidth = 2;
txtaddress = new JTextField("",10);
pnladd.add(txtaddress,c);
//Fifth row
c.gridy++;
c.gridwidth = 3;
c.gridx = 0;
lblstatus = new JLabel(" ");
lblstatus.setForeground(Color.RED);
pnladd.add(lblstatus ,c);
//Last row
c.gridy++;
btnadd = new JButton("Add record");
btnadd.addActionListener(this);
pnladd.add(btnadd , c);
pnladdrecord.add(pnladd,BorderLayout.WEST);
tblrecord = new Table();
tblrecord.tableData(pnladdrecord);
}
public void searchPanel(){
pnlsearch.setLayout(new BorderLayout());
JPanel pnl = new JPanel();
pnl.setLayout(new GridLayout(1,3));
lblname = new JLabel("Name :");
pnl.add(lblname);
txtnamesearch = new JTextField("",10);
pnl.add(txtnamesearch);
btnsearch = new JButton("Search");
btnsearch.addActionListener(this);
pnl.add(btnsearch);
pnlsearch.add(pnl,BorderLayout.NORTH);
tblsearchrecord = new Table();
tblsearchrecord.tableData(pnlsearch);
JPanel pnlDelete = new JPanel();
pnlDelete.setLayout(new BorderLayout());
btndelete = new JButton("Delete");
btndelete.addActionListener(this);
btnSave = new JButton("Save");
btnSave.addActionListener(this);
pnlDelete.add(btnSave,BorderLayout.WEST);
pnlDelete.add(btndelete,BorderLayout.EAST);
pnlsearch.add(pnlDelete,BorderLayout.SOUTH);
}
public void actionPerformed(ActionEvent a){
String command = a.getActionCommand();
switch(command){
case "Add record":
Details temp = new Details();
boolean nameverify = true;
for(int i = 0; i< detail.size() ; i++){
temp = detail.get(i);
if((temp.getName().equalsIgnoreCase(txtname.getText().trim()))){
nameverify = false;
}
}
boolean namecheck = !(txtname.getText().trim().equals("")) && nameverify ;
boolean emailcheck = (!(txtemail.getText().indexOf('@') == -1) && !(txtemail.getText().indexOf('.') == -1)) || (txtemail.getText().equals(""));
boolean contactcheck = !(txtcontact.getText().trim().equals(""));
boolean addresscheck = !(txtaddress.getText().trim().equals(""));
if( namecheck && contactcheck && emailcheck && addresscheck ){
//Adding Details
String tempName = txtname.getText().trim();
String tempContact = txtcontact.getText().trim();
String tempEmail = txtemail.getText().trim();
String tempAddress = txtaddress.getText().trim();
temp = new Details(tempName, tempContact , tempEmail , tempAddress);
detail.add(new Details(tempName, tempContact , tempEmail , tempAddress));
//Adding the record to the table
tblrecord.addRecordToTable(temp);
lblstatus.setText(" Successful");
}
else{
// lblverification.setText(" Invalid Name");
String error;
error = "Unsuccessful!! ";
lblstatus.setText(error);
if(!namecheck){
if(!nameverify)
lblstatus.setText(error + "Name Already Exists");
else
lblstatus.setText(error + " Invalid Name");
}
else if(!contactcheck)
lblstatus.setText(error + " Enter Contact ");
else if(!addresscheck)
lblstatus.setText(error + " Enter Address ");
else if(!emailcheck)
lblstatus.setText(error + " Invalid email ");
}
break;
case "Search":
search();
break;
case "Delete":
int confirm = JOptionPane.showConfirmDialog(new JFrame(),"Are you sure you want to delete these records?",
"Confim Message",JOptionPane.YES_NO_OPTION);
if (confirm == JOptionPane.YES_OPTION) {
int[] row = tblsearchrecord.getTable().getSelectedRows();
Object[] name = new String[row.length];
for(int i = 0 ; i < row.length ; i++){
int index = row[i];
name[i] = tblsearchrecord.getDm().getValueAt(index,1);
}
for(int i = 0 ; i < name.length ; i++){
Details temp1;
Object name1 = name[i];
for(int j = 0; j< detail.size() ; j++){
temp1 = detail.get(j);
if((temp1.getName().equals(name1))){
detail.remove(temp1);
tblrecord.getDm().removeRow(j);
search();
}
}
System.out.println ("Details" + detail);
}
tblrecord.getDm().setRowCount(0);
for(int j = 0; j< detail.size() ; j++){
Details temp1 = detail.get(j);
tblrecord.addRecordToTable(temp1);
}
}
break;
case "Save":
Details temp1;
for(int i = 0 ; i < tblsearchrecord.getDm().getRowCount(); i++){
for(int j = 0; j< detail.size() ; j++){
temp1 = detail.get(j);
if((temp1.getName().equals(tblsearchrecord.getDm().getValueAt(i,1)))){
detail.remove(j);
temp1.putContact(tblsearchrecord.getDm().getValueAt(i,2).toString());
temp1.putEmail(tblsearchrecord.getDm().getValueAt(i,3).toString());
temp1.putAddress(tblsearchrecord.getDm().getValueAt(i,4).toString());
detail.add(j,temp1);
}
}
}
tblrecord.getDm().setRowCount(0);
for(int j = 0; j< detail.size() ; j++){
temp1 = detail.get(j);
tblrecord.addRecordToTable(temp1);
}
search();
break;
}
}
public void search(){
tblsearchrecord.getDm().setRowCount(0);
String namesearch = txtnamesearch.getText();
Details temp;
for( int i = 0; i < detail.size() ; i++){
temp = detail.get(i);
if(temp.getName().toLowerCase().contains(namesearch.toLowerCase())){
int row = tblsearchrecord.getDm().getRowCount();
String[] rowdata = {""+ (row+1) , temp.getName() , temp.getContact() , temp.getEmail() , temp.getAddress() };
tblsearchrecord.getDm().addRow(rowdata);
}
}
}
public static void main (String[] args) {
new Phonebook("Phonebook");
}
}
The default tab of the program
Adding Records in PhoneBook
Searching and Editing the existing record
Need to click on SAVE to save the updated record
Deleting some record from the PhoneBook
Validation applied in different Textfields(as shown for Email)
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import javax.swing.table.*;
class Details{
private String contact_no , name;
private String email_address, address;
public Details(){}
public Details(String name,String contact,String email,String address){
putName(name);
putContact(contact);
putEmail(email);
putAddress(address);
}
public void putName(String name){
this.name = name;
}
public String getName(){
return name;
}
public void putContact(String contact){
contact_no = contact;
}
public String getContact(){
return contact_no;
}
public void putEmail(String email){
email_address = email;
}
public String getEmail(){
return email_address;
}
public void putAddress(String address){
this.address = address;
}
public String getAddress(){
return address;
}
}
class Table{
class MyModel extends DefaultTableModel{
public MyModel(Object[] columnNames , int rowcount){
super(columnNames,rowcount);
}
public boolean isCellEditable(int row , int column){
if(column == 1)
return false;
else return true;
}
public void setValueAt(Object aValue,int row, int column){
int temp = 0;
if(column == 2){
for(int i = 0 ; i < aValue.toString().length() ; i++){
char c = aValue.toString().charAt(i);
if(i == 0){
if( !Character.isDigit(c) && ! (c == '+')){
temp++;
}
}
else{
if(!(Character.isDigit(c)) && !(c == ',') && !(c == '+')){
temp++;
}
}
}
if(temp == 0){
super.setValueAt(aValue,row,column);
}
}
else if(column == 3){
int atpos = aValue.toString().indexOf("@");
int dotpos = aValue.toString().indexOf(".");
boolean at = !(atpos > 0);
boolean dot = !(dotpos > (atpos+1));
boolean check = (dotpos == (aValue.toString().length()-1));
if( aValue.toString().trim().equals("") || at || dot || check){
temp++;
}
if(temp == 0){
super.setValueAt(aValue,row,column);
}
}
else{
super.setValueAt(aValue,row,column);
}
}
}
JTable table;
MyModel dm;
String[] column_names = {"S.No.","Name","Contact No","Email Address","Address"};
public Table(){
dm = new MyModel(column_names,0);
table = new JTable(dm);
table.setAutoCreateRowSorter(true);
}
public JTable getTable(){
return table;
}
public DefaultTableModel getDm(){
return dm;
}
public void tableData(JPanel pnl){
JScrollPane scroll = new JScrollPane(table);
pnl.add(scroll,BorderLayout.CENTER);
}
public void addRecordToTable(Details temp){
int row = dm.getRowCount();
String[] rowdata = {""+ (row+1) , temp.getName() , temp.getContact() , temp.getEmail() , temp.getAddress() };
dm.insertRow(row, rowdata);
}
}
class Phonebook extends JFrame implements ActionListener{
private JTabbedPane tabbedpane;
private JPanel pnladdrecord,pnlsearch;
private JLabel lblname,lblcontact,lblemail,lbladdress,lblverification,lblstatus;
private JTextField txtname,txtcontact,txtemail,txtaddress,txtnamesearch;
private JButton btnadd,btnsearch,btndelete,btnSave;
private LinkedList<Details> detail = new LinkedList<>();
private Table tblrecord,tblsearchrecord;
public Phonebook(String title){
super(title);
setLayout(new GridLayout(1,1));
setBounds(300,200,700,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
initialize();
// pack();
}
public void initialize(){
tabbedpane = new JTabbedPane();
pnladdrecord = new JPanel();
AddPanel();
tabbedpane.addTab("Add Record",pnladdrecord);
pnlsearch = new JPanel();
searchPanel();
tabbedpane.addTab("Search Record",pnlsearch);
add(tabbedpane);
}
public void AddPanel(){
pnladdrecord.setLayout(new BorderLayout());
JPanel pnladd = new JPanel();
pnladd.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
//First row
c.gridy = 0;
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.PAGE_START;
c.gridx = 0;
lblname = new JLabel("Name :");
pnladd.add(lblname,c);
c.gridx++;
txtname = new JTextField("",10);
txtname.addKeyListener(new KeyAdapter(){
public void keyTyped(KeyEvent ke){
char c = ke.getKeyChar();
if(!(c >= 'a' && c <= 'z') && !(c >= 'A' && c <= 'Z') && !(c == ' '))
ke.consume();
}
});
pnladd.add(txtname,c);
//Second row
c.gridy++;
c.gridx = 0;
lblcontact = new JLabel("Contact No:");
pnladd.add(lblcontact ,c);
c.gridx++;
c.gridwidth = 2;
txtcontact = new JTextField("",10);
txtcontact.addKeyListener(new KeyAdapter(){
public void keyTyped(KeyEvent ke){
char c = ke.getKeyChar();
if(txtcontact.getCaretPosition() == 0){
if((txtcontact.getText().indexOf('+') == -1)){
if(!(Character.isDigit(c)) && !(c == ',') && !(c == '+') )
ke.consume();
}
else{
ke.consume();
}
}
else{
int comma = txtcontact.getText().indexOf(',');
if((txtcontact.getCaretPosition() == (comma+1))){
if(!(Character.isDigit(c)) && !(c == ',') && !(c == '+') )
ke.consume();
}
else{
if(!(Character.isDigit(c)) && !(c == ','))
ke.consume();
}
}
}
});
pnladd.add(txtcontact,c);
//Third row
c.gridy++;
c.gridwidth = 1;
c.gridx = 0;
lblemail = new JLabel("Email Address :");
pnladd.add(lblemail ,c);
c.gridx++;
c.gridwidth = 2;
txtemail = new JTextField("",10);
txtemail.addKeyListener(new KeyAdapter(){
public void keyTyped(KeyEvent ke){
char c = ke.getKeyChar();
int at = txtemail.getText().indexOf('@');
int dot = txtemail.getText().indexOf('.');
if(txtemail.getCaretPosition() == 0){
if((c == '@') || (c == '.'))
ke.consume();
}
else{
if(at == -1){
if((c == '.'))
ke.consume();
}
else if(at != -1 && dot == -1 && txtemail.getCaretPosition() > (at+1)){
if((c == '@'))
ke.consume();
}
else if(at != -1 && dot == -1 && txtemail.getCaretPosition() == (at+1)){
if((c == '@')|| (c == '.'))
ke.consume();
}
else if(at != -1 && dot != -1){
if((c == '@') || (c == '.'))
ke.consume();
}
}
}
});
pnladd.add(txtemail,c);
//Fourth row
c.gridy++;
c.gridwidth = 1;
c.gridx = 0;
lbladdress = new JLabel("Address :");
pnladd.add(lbladdress ,c);
c.gridx++;
c.gridwidth = 2;
txtaddress = new JTextField("",10);
pnladd.add(txtaddress,c);
//Fifth row
c.gridy++;
c.gridwidth = 3;
c.gridx = 0;
lblstatus = new JLabel(" ");
lblstatus.setForeground(Color.RED);
pnladd.add(lblstatus ,c);
//Last row
c.gridy++;
btnadd = new JButton("Add record");
btnadd.addActionListener(this);
pnladd.add(btnadd , c);
pnladdrecord.add(pnladd,BorderLayout.WEST);
tblrecord = new Table();
tblrecord.tableData(pnladdrecord);
}
public void searchPanel(){
pnlsearch.setLayout(new BorderLayout());
JPanel pnl = new JPanel();
pnl.setLayout(new GridLayout(1,3));
lblname = new JLabel("Name :");
pnl.add(lblname);
txtnamesearch = new JTextField("",10);
pnl.add(txtnamesearch);
btnsearch = new JButton("Search");
btnsearch.addActionListener(this);
pnl.add(btnsearch);
pnlsearch.add(pnl,BorderLayout.NORTH);
tblsearchrecord = new Table();
tblsearchrecord.tableData(pnlsearch);
JPanel pnlDelete = new JPanel();
pnlDelete.setLayout(new BorderLayout());
btndelete = new JButton("Delete");
btndelete.addActionListener(this);
btnSave = new JButton("Save");
btnSave.addActionListener(this);
pnlDelete.add(btnSave,BorderLayout.WEST);
pnlDelete.add(btndelete,BorderLayout.EAST);
pnlsearch.add(pnlDelete,BorderLayout.SOUTH);
}
public void actionPerformed(ActionEvent a){
String command = a.getActionCommand();
switch(command){
case "Add record":
Details temp = new Details();
boolean nameverify = true;
for(int i = 0; i< detail.size() ; i++){
temp = detail.get(i);
if((temp.getName().equalsIgnoreCase(txtname.getText().trim()))){
nameverify = false;
}
}
boolean namecheck = !(txtname.getText().trim().equals("")) && nameverify ;
boolean emailcheck = (!(txtemail.getText().indexOf('@') == -1) && !(txtemail.getText().indexOf('.') == -1)) || (txtemail.getText().equals(""));
boolean contactcheck = !(txtcontact.getText().trim().equals(""));
boolean addresscheck = !(txtaddress.getText().trim().equals(""));
if( namecheck && contactcheck && emailcheck && addresscheck ){
//Adding Details
String tempName = txtname.getText().trim();
String tempContact = txtcontact.getText().trim();
String tempEmail = txtemail.getText().trim();
String tempAddress = txtaddress.getText().trim();
temp = new Details(tempName, tempContact , tempEmail , tempAddress);
detail.add(new Details(tempName, tempContact , tempEmail , tempAddress));
//Adding the record to the table
tblrecord.addRecordToTable(temp);
lblstatus.setText(" Successful");
}
else{
// lblverification.setText(" Invalid Name");
String error;
error = "Unsuccessful!! ";
lblstatus.setText(error);
if(!namecheck){
if(!nameverify)
lblstatus.setText(error + "Name Already Exists");
else
lblstatus.setText(error + " Invalid Name");
}
else if(!contactcheck)
lblstatus.setText(error + " Enter Contact ");
else if(!addresscheck)
lblstatus.setText(error + " Enter Address ");
else if(!emailcheck)
lblstatus.setText(error + " Invalid email ");
}
break;
case "Search":
search();
break;
case "Delete":
int confirm = JOptionPane.showConfirmDialog(new JFrame(),"Are you sure you want to delete these records?",
"Confim Message",JOptionPane.YES_NO_OPTION);
if (confirm == JOptionPane.YES_OPTION) {
int[] row = tblsearchrecord.getTable().getSelectedRows();
Object[] name = new String[row.length];
for(int i = 0 ; i < row.length ; i++){
int index = row[i];
name[i] = tblsearchrecord.getDm().getValueAt(index,1);
}
for(int i = 0 ; i < name.length ; i++){
Details temp1;
Object name1 = name[i];
for(int j = 0; j< detail.size() ; j++){
temp1 = detail.get(j);
if((temp1.getName().equals(name1))){
detail.remove(temp1);
tblrecord.getDm().removeRow(j);
search();
}
}
System.out.println ("Details" + detail);
}
tblrecord.getDm().setRowCount(0);
for(int j = 0; j< detail.size() ; j++){
Details temp1 = detail.get(j);
tblrecord.addRecordToTable(temp1);
}
}
break;
case "Save":
Details temp1;
for(int i = 0 ; i < tblsearchrecord.getDm().getRowCount(); i++){
for(int j = 0; j< detail.size() ; j++){
temp1 = detail.get(j);
if((temp1.getName().equals(tblsearchrecord.getDm().getValueAt(i,1)))){
detail.remove(j);
temp1.putContact(tblsearchrecord.getDm().getValueAt(i,2).toString());
temp1.putEmail(tblsearchrecord.getDm().getValueAt(i,3).toString());
temp1.putAddress(tblsearchrecord.getDm().getValueAt(i,4).toString());
detail.add(j,temp1);
}
}
}
tblrecord.getDm().setRowCount(0);
for(int j = 0; j< detail.size() ; j++){
temp1 = detail.get(j);
tblrecord.addRecordToTable(temp1);
}
search();
break;
}
}
public void search(){
tblsearchrecord.getDm().setRowCount(0);
String namesearch = txtnamesearch.getText();
Details temp;
for( int i = 0; i < detail.size() ; i++){
temp = detail.get(i);
if(temp.getName().toLowerCase().contains(namesearch.toLowerCase())){
int row = tblsearchrecord.getDm().getRowCount();
String[] rowdata = {""+ (row+1) , temp.getName() , temp.getContact() , temp.getEmail() , temp.getAddress() };
tblsearchrecord.getDm().addRow(rowdata);
}
}
}
public static void main (String[] args) {
new Phonebook("Phonebook");
}
}