Create a JAVA application to create and maintain a contact list. The contact lis
ID: 3550509 • Letter: C
Question
Create a JAVA application to create and maintain a contact list. The contact list should include the contact name, address, city, state, zip and phone number. In addition, the contact list application must have the ability to Add, Delete, Update and Find contacts as needed. Create a database to store the contact information.
The contact list application will display appropriate messages when a user successfully adds, updates or deletes a contact and will also display any error messages when a given user action fails.
Explanation / Answer
Here is your Complete Program. I have put lot off efforts for your Problem. just put your connection
String and Run it. I have used JDBC with MYSQL database.
import java.awt.event.*;
import java.sql.*;
import java.io.*;
public class Contact extends Frame
{
Connection con;
Textfield name,city,state,zipcode,phoneno;
TextArea address,t1,t2;
Label l1,l2,l3,l4,l5,l6;
Panel p1,p2,p3,p4;
Button b1,b2,b3,b4,b5,b6,b7,b8;
public Contact()
{
setLayout(new FlowLayout());
p1=new Panel();
p2=new Panel();
p3=new Panel();
p4=new Panel();
p1.setLayout(new GridLayout(3,3,20,20));
p2.setLayout(new BorderLayout());
p3.setLayout(new GridLayout(2,3,15,15));
name=new TextField("',20);
city=new TextField("',20);
state=new TextField("',20);
zipcode=new TextField("',20);
phoneno=new TextField("',20);
address =new TextArea(",5,60);
t1=new TextArea("Enter query",5,60);
t2=new TextArea("Result",5,60);
l1=new Label("Name");
l2=new Label("City");
l3=new Label("State");
l4=new Label("zipcode");
l5=new Label("PhoneNo");
l6=new Label("Address");
b1=new Button("connect");
b2=new Button("disconnect");
b3=new Button("select");
b4=new Buton("update");
b5=new Button("Insert");
b6=new Button("Delete");
p1.add(l1);
p1.add(name);
p1.add(l2);
p1.add(city);
p1.add(l3);
p1.add(state);
p1.add(l4);
p1.add(zipcode);
p1.add(l5);
p1.add(phoneno);
p1.add(l6);
p1.add(address);
p2.add("center",t1);
p1.add(b1);
p1.add(b2);
p3.add(b3);
p3.add(b4);
p3.add(b5);
p3.add(b6);
p2.add("South",p3);
add(p1);
add(p2);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
b1.addActionListener(new ConnectDB());
b2.addActionListener(new DisconnectDB());
b3.addActionListener(new Select());
b4.addActionListener(new Insert());
b5.addActionListener(new Update());
b6.addActionListener(new Delete());
}
class ConnectDB implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
try{
ClassforName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("here whould be your connection string");
}
catch(Exception e2)
{ }
}
}
class DB implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
try{
con.commit();
con.close();
}
catch(Exception e)
{ }
}
}
class Select implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
try{
Statement stmt;
ResultSet rs;
String query;
boolean more;
stmt=con.createStatement();
int count=0;
query=t1.getText();
rs=stmt.executeQuery(query);
more=rs.next();
if(!more)
{
t2.append("NO resutls");
return;
}
t2.append("No results");
return;
while(more)
{
t2.append(" "+rs.getString(1)+" "+rs.getString(2)
+" "+rs.getString(3)+" "+rs.getString(4)+" "+rs.getString(5)+" "+rs.getString(6));
count++;
more=rs.newxt();
}
t2.append(" "+count+"row selected");
rs.close();
stmt.close();
}
catch(Exception e1)
{
t2.setText("error in selection");
}
}
}