Class: CIS355A Week 6 – Practice Programming
— For The Software: Netbeans// Java If you could walk through the process of where to paste the code. Like exp: under the package that would be helpful.
Question: Make an address book application that stores your contacts in a database. First, set up a database with at least one table for the contacts. The fields should include the contact’s name, phone number, and email address. Then create a JTabbedPane GUI with two tabs: an Add tab that lets the user enter the information for a contact and add it to the database, and a Display tab that shows all of the contacts in the database.
Expert Answer
Address.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package addressbook;
/**
*
* @author Akshay Bisht
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class Address extends JFrame
implements ActionListener
{
public static final int WDT = 400;
public static final int HT = 250;
private JTextField ntf, atf, ctf,
stf, ztf, ptf, etf;
public Address()
{
setSize(WDT,HT);
setTitle(“Address Book”);
Container contentPane = getContentPane();
contentPane.setBackground(Color.YELLOW);
contentPane.setLayout(new GridLayout(8,2));
JLabel nl = new JLabel(“Name: “);
contentPane.add(nl);
ntf = new JTextField(25);
contentPane.add(ntf);
JLabel al = new JLabel(“Address: “);
contentPane.add(al);
atf = new JTextField(25);
contentPane.add(atf);
JLabel cl = new JLabel(“City: “);
contentPane.add(cl);
ctf = new JTextField(25);
contentPane.add(ctf);
JLabel sl = new JLabel(“State: “);
contentPane.add(sl);
stf = new JTextField(25);
contentPane.add(stf);
JLabel zl = new JLabel(“Zip code: “);
contentPane.add(zl);
ztf = new JTextField(25);
contentPane.add(ztf);
JLabel pl = new JLabel(“Phone number: “);
contentPane.add(pl);
ptf = new JTextField(25);
contentPane.add(ptf);
JLabel el = new JLabel(“Email: “);
contentPane.add(el);
etf = new JTextField(25);
contentPane.add(etf);
JButton entBtn = new JButton(“Enter Record”);
entBtn.addActionListener(this);
contentPane.add(entBtn);
JButton exit = new JButton(“Exit”);
exit.addActionListener(this);
contentPane.add(exit);
}
public void actionPerformed(ActionEvent e)
{
String actionCmd = e.getActionCommand();
if(actionCmd.equals(“Enter Record”))
{
String disp = ntf.getText() + “n”;
disp += atf.getText() + “n”;
disp += ctf.getText() + “n”;
disp += stf.getText() + “n”;
disp += ztf.getText() + “n”;
disp += ptf.getText() + “n”;
disp += etf.getText();
ntf.setText(“”);
atf.setText(“”);
ctf.setText(“”);
stf.setText(“”);
ztf.setText(“”);
ptf.setText(“”);
etf.setText(“”);
JOptionPane.showMessageDialog(null, disp);
}
else
System.exit(0);
}
public static void main(String[] args)
{
Address add = new Address();
add.setVisible(true);
}
}
Output: