Create a database to hold address records with the following fields: Name Street
ID: 3770515 • Letter: C
Question
Create a database to hold address records with the following fields:
Name
Street
City
State
Zipcode
Load several records into the database.
Create a JavaFX program to provide a form to display a single address record from the database. Initially, display the first record. Provide the following buttons to display other records in the database, one at a time:
First
Previous
Next
Last
Quit
It will be helpful to include a text field with the following message:
Displaying record m of n
where n is the total number of records in the database and m is the record currently being displayed.
******************************************************************************************************************
I did this program. i am try to connect with sql database.
Explanation / Answer
public class Address {
ArrayList<Customer> mycustomer;
final ArrayList<Employee> myemployee = new ArrayList<Employee>();
private JFrame frame;
private JTextField tfgiven;
private JTextField tflast;
private JTextField tfpersonID;
private JTextField tfphone;
private JTextField tfaddress;
private JTextField tfcity;
private JTextField tfstate;
private JTextField tfzip;
private JTextField tfzip4;
private JButton btnAddCustomer;
private JButton btnAddEmployee;
private JButton btnDisplayAll;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Address window = new Address();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public Address() {
initialize();
}
private void initialize() {
btnAddCustomer.addActionListener(new CustomerListener());
btnAddEmployee.addActionListener(new EmployeeListener());
btnDisplayAll.addActionListener(new DisplayAllListener());
tfgiven.addActionListener(null);
tflast.addActionListener(null);
tfpersonID.addActionListener(null);
tfaddress.addActionListener(null);
tfcity.addActionListener(null);
tfstate.addActionListener(null);
tfzip.addActionListener(null);
tfzip4.addActionListener(null);
}
private class CustomerListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
if(e.getSource() == btnAddCustomer) {
String givenName = tfgiven.getText();
tfgiven.setText("");
String surname = tflast.getText();
tflast.setText("");
String customerID = tfpersonID.getText();
tfpersonID.setText("");
if(customerID.trim().equals("")) {
JOptionPane.showMessageDialog(null, "Customer ID required.");
} else {
Integer.parseInt(customerID);
String phoneNumber = tfphone.getText();
tfphone.setText("");
String streetAddress = tfaddress.getText();
tfaddress.setText("");
String city = tfcity.getText();
tfcity.setText("");
String state = tfstate.getText();
tfstate.setText(state);
String zip = tfzip.getText();
tfzip.setText("");
if(zip.trim().equals("")) {
return;
} else {
Integer.parseInt(zip);
}
String zipPlus4 = tfzip4.getText();
tfzip4.setText("");
if(zipPlus4.trim().equals("")) {
return;
} else {
Integer.parseInt(zipPlus4);
}
}
return;
}
}
}
private class EmployeeListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
if(e.getSource() == btnAddEmployee) {
String givenName = tfgiven.getText();
String surname = tflast.getText();
String employeeID = tfpersonID.getText();
if(employeeID.trim().equals("")) {
JOptionPane.showMessageDialog(null, "Employee ID required.");
} else {
Integer.parseInt(employeeID);
String phoneNumber = tfphone.getText();
String streetAddress = tfaddress.getText();
String city = tfcity.getText();
String state = tfstate.getText();
String zip = tfzip.getText();
if(zip.trim().equals("")) {
} else {
Integer.parseInt(zip);
}
String zipPlus4 = tfzip4.getText();
if(zipPlus4.trim().equals("")) {
} else {
Integer.parseInt(zipPlus4);
}
Employee employees = new Employee(null, null, false, 0);
myemployee.add(employees);
}
}
}
}
private class DisplayAllListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
if(e.getSource() == btnDisplayAll) {
for(int i = 0; i < mycustomer.size(); i++) {
mycustomer.get(i).getGivenName();
mycustomer.get(i).getsurname();
mycustomer.get(i).getCustomerID();
mycustomer.get(i).getPhoneNumber();
mycustomer.get(i).getStreetAddress();
mycustomer.get(i).getState();
mycustomer.get(i).getZip();
mycustomer.get(i).getZipPlus4();
}
ArrayList<ArrayList<Customer>> mycustomer = new ArrayList<ArrayList<Customer>>();
mycustomer.add(new ArrayList<Customer>());
mycustomer.get(0).add(null);
for(int j = 0; j < myemployee.size(); j++) {
myemployee.get(j).getGivenName();
myemployee.get(j).getsurname();
myemployee.get(j).getEmployeeID();
myemployee.get(j).getPhoneNumber();
myemployee.get(j).getStreetAddress();
myemployee.get(j).getCity();
myemployee.get(j).getState();
myemployee.get(j).getZip();
myemployee.get(j).getZipPlus4();
}
myemployee.toArray();
}
System.out.println("Customers: " + " " +
mycustomer + " Employees: " +
" " + myemployee);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.