In: Computer Science
ou will create a GUI data entry program to be used to enter Customer Information. This program should be based on the requirements and design you created in previous modules.
It will be a GUI, based either on the Java Swing classes or JavaFX. The program will allow for entry of all fields described in your requirements and include appropriate validations for each field. It will be left to you to decide if the validations methods should be part of the entry program or a separate validation class. You should use exception objects to reject invalid data, inform users and allow the program to fail securely. When a complete, correct Customer record has been completed, the user must be able to write the data to an encrypted file.
The requirements:
fields for first and last name, address, date, product, phone, secondary phone, email, complaints, employee name, employee id.
Build this as a project for your application and compress and submit the entire project file. See the Course Documents, Submitting Your Programs for more detail.
package com.company;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Main {
public static void main(String[] args) {
JFrame f=new JFrame("GUI Example");
JLabel jl = new JLabel("First Name");
jl.setBounds(10, 10, 100, 20);
JTextField tf=new JTextField();
tf.setBounds(100,10, 150,20);
JLabel jl1 = new JLabel("Last Name");
jl1.setBounds(300, 10, 150, 20);
JTextField tf1 = new JTextField();
tf1.setBounds(500, 10, 150, 20);
JLabel jl2 = new JLabel("Address:");
jl2.setBounds(10, 50, 100, 20);
JTextField tf22 = new JTextField();
tf22.setBounds(100,50,150,20);
JTextField tf2 = new JTextField();
tf2.setBounds(100, 100, 150, 20);
JLabel jl3 = new JLabel("Date");
jl3.setBounds(300, 50, 150, 20);
JTextField tf3 = new JTextField();
tf3.setBounds(500, 50, 150, 20);
JLabel jl4 = new JLabel("Product");
JLabel jl5 = new JLabel("Phone");
JLabel jl6 = new JLabel("Secondary Phone");
JLabel jl7 = new JLabel("Email");
JLabel jl8 = new JLabel("Complaint");
JLabel jl9 = new JLabel("Employee Name");
JLabel jl10 = new JLabel("Employee ID");
jl4.setBounds(50,200, 150,20);
jl6.setBounds(50,300, 150,20);
jl8.setBounds(50,400, 150,20);
jl10.setBounds(50,500, 150,20);
jl5.setBounds(400, 200, 150, 20);
jl7.setBounds(400, 300, 150, 20);
jl9.setBounds(400, 400, 150, 20);
JTextField tf4 = new JTextField();
JTextField tf5 = new JTextField();
JTextField tf6 = new JTextField();
JTextField tf7 = new JTextField();
JTextField tf8 = new JTextField();
JTextField tf9 = new JTextField();
JTextField tf10 = new JTextField();
tf4.setBounds(200,200, 150,20);
tf5.setBounds(550, 200, 150, 20);
tf6.setBounds(200,300, 150,20);
tf7.setBounds(550, 300, 150, 20);
tf8.setBounds(200,400, 150,20);
tf9.setBounds(550, 400, 150, 20);
tf10.setBounds(200,500, 150,20);
JButton b=new JButton("Ok");
b.setBounds(350,700,95,30);
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
int counter = 0;
String phone = tf5.getText();
if (phone.length() == 10){
try{
Double d= Double.parseDouble(phone);
}catch (NumberFormatException nfe){
System.out.println("Enter correct number !");
counter ++;
}
}
else
System.out.println("Enter correct number OFf!");
counter++;
if (counter == 0)
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
});
f.add(b);f.add(tf);f.add(jl);f.add(jl1);f.add(tf1);f.add(jl2);f.add(tf2);f.add(tf22);
f.add(jl3);f.add(tf3);f.add(jl4);f.add(jl6);f.add(jl8);f.add(jl10);f.add(jl5);f.add(jl7);f.add(jl9);
f.add(tf4);
f.add(tf5);
f.add(tf6);
f.add(tf7);
f.add(tf8);
f.add(tf9);
f.add(tf10);
f.setSize(800,800);
f.setLayout(null);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}