I am having trouble getting the code to work. it needs to create an address book and creates a file from the inputted data. Please advice how to fix the code I have.
import java.awt.*; import javax.swing.*; import java.awt.event.*; public class AddressBook extends JFrame implements ActionListener { FlowLayout leftLayout; JFrame winNew; private static JPanel pTitle; private static JPanel pName; private static JPanel pAddress; private static JPanel pPhoneNumber; private static JPanel pEmail; private static JPanel pButtons; private static JLabel lblTitle; private static JLabel lblName; private static JLabel lblAddress; private static JLabel lblPhoneNumber; private static JLabel lblEmail; private static JTextField txtName; private static JTextField txtAddress; private static JTextField txtPhoneNumber; private static JTextField txtEmail; private static JButton btnImport; private static JButton btnAdd; private static JButton btnPrevious; private static JButton btnNext; private static JButton btnSave; public static void main(String[] args) { AddressBook project = new AddressBook(); } public AddressBook() { final int WIDTH = 450; final int HEIGHT = 400; JFrame win = new JFrame("Address Book"); win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); leftLayout = new FlowLayout(FlowLayout.LEFT); pTitle = new JPanel(); pTitle.setLayout(new FlowLayout(FlowLayout.CENTER)); lblTitle = new JLabel("Address Book"); pTitle.add(lblTitle); win.add(pTitle); win.setLayout(new GridLayout(6,1)); win.setSize(WIDTH, HEIGHT); win.setBackground(Color.BLUE); win.setResizable(false); win.setLocationRelativeTo(null); pName = new JPanel(); pName.setLayout(leftLayout); lblName = new JLabel("Name: "); txtName = new JTextField(20); win.add(pName); pName.add(lblName); pName.add(txtName); pAddress = new JPanel(); pAddress.setLayout(leftLayout); lblAddress = new JLabel("Address: "); txtAddress = new JTextField(30); win.add(pAddress); pAddress.add(lblAddress); pAddress.add(txtAddress); pPhoneNumber = new JPanel(); pPhoneNumber.setLayout(leftLayout); lblPhoneNumber = new JLabel("Phone Number: "); txtPhoneNumber = new JTextField(12); win.add(pPhoneNumber); pPhoneNumber.add(lblPhoneNumber); pPhoneNumber.add(txtPhoneNumber); pEmail = new JPanel(); pEmail.setLayout(leftLayout); lblEmail = new JLabel("Email: "); txtEmail = new JTextField(30); win.add(pEmail); pEmail.add(lblEmail); pEmail.add(txtEmail); pButtons = new JPanel(); btnImport = new JButton("Import"); pButtons.add(btnImport); btnImport.addActionListener(this); btnAdd = new JButton("Add"); pButtons.add(btnAdd); btnAdd.addActionListener(this); btnPrevious = new JButton("Previous"); pButtons.add(btnPrevious); //btnPrevious.addActionListener(this); btnNext = new JButton("Next"); pButtons.add(btnNext); //btnNext.addActionListener(this); win.add(pButtons); win.setVisible(true); } JFileChooser chooser = new JFileChooser(); public void actionPerformed(ActionEvent e) { if(e.getSource() == btnAdd) AddContact(); else if(e.getSource() == Import) int returnVal = fc.showOpenDialog (AddressBook.this); } public void AddContact() { newContactFrame(); } public void newContactFrame() { final int WIDTH = 375; final int HEIGHT = 325; winNew = new JFrame("Add New Contact"); leftLayout = new FlowLayout(FlowLayout.LEFT); pTitle = new JPanel(); pTitle.setLayout(new FlowLayout(FlowLayout.CENTER)); lblTitle = new JLabel("New Contact"); pTitle.add(lblTitle); winNew.add(pTitle); winNew.setLayout(new GridLayout(6,1)); winNew.setSize(WIDTH, HEIGHT); winNew.setBackground(Color.BLUE); pName = new JPanel(); pName.setLayout(leftLayout); lblName = new JLabel("Name: "); txtName = new JTextField(20); winNew.add(pName); pName.add(lblName); pName.add(txtName); pAddress = new JPanel(); pAddress.setLayout(leftLayout); lblAddress = new JLabel("Address: "); txtAddress = new JTextField(30); winNew.add(pAddress); pAddress.add(lblAddress); pAddress.add(txtAddress); pPhoneNumber = new JPanel(); pPhoneNumber.setLayout(leftLayout); lblPhoneNumber = new JLabel("Phone Number: "); txtPhoneNumber = new JTextField(12); winNew.add(pPhoneNumber); pPhoneNumber.add(lblPhoneNumber); pPhoneNumber.add(txtPhoneNumber); pEmail = new JPanel(); pEmail.setLayout(leftLayout); lblEmail = new JLabel("Email: "); txtEmail = new JTextField(30); winNew.add(pEmail); pEmail.add(lblEmail); pEmail.add(txtEmail); pButtons = new JPanel(); btnSave = new JButton("Save"); pButtons.add(btnSave); btnSave.addActionListener(this); winNew.add(pButtons); winNew.setVisible(true); } }