Hi,
I'm creating a Java Swing application that lets the user enter the usual details one would expect in an address book then click the save button. The current JPanel will then be hidden while another JPanel is shown. This second panel is used for viewing all the contacts added to the address book so will have buttons to flick forward and backward through the book. I have the GUI part done for the new contact JPanel but I'm struggling in getting what is entered, stored into an array for use later when viewing the contacts. I have numerous classes but the ones I think are needed for help with the array is my GUI class and contacts class files so I will include some code snippets for visual aid as a means to point me in the right direction. I thank you in advance for any help provided :-).
GUI Class -
public void actionPerformed(ActionEvent e) { if (e.getSource() == saveButton){ addContactPanel.setVisible(false); viewAllPanel.setVisible(true); } if (e.getSource() == quitButton){ System.exit(0); } } public static void main(String[] args) { GUIClass form = new GUIClass(); form.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); form.setVisible(true); } }
Contacts class -
import java.io.*; public class contacts implements Serializable { private contacts list[]; private int current = 0; private int count; private int maxSize; private contacts outputFile; public contacts(int max) { list = new contacts[max]; maxSize = max; count = 0; } public void add (contacts c) { if (!isFull() && !isIn(p)) { list[count] =p; count++; } else { System.out.println("Contact list is full!."); System.out.println(""); } } public boolean isFull() { return count == maxSize; } public boolean isEmpty() { return count==0; } public boolean isIn(contacts c) { for (int index = 0; index < count; index++) { if(list[index].equals(p)) { return true; } } return false; } public int getCount() { return count; } public contacts currentRecord() { return list[current]; } public void incrementCurrentPointer() { this.current++; if (current>=count) { current=0; } } public void decrementCurrentPointer() { this.current--; if(current<0) { current=count-1; } } public void displayAll() { for (int index=0; index < count; index++) System.out.println(list[index]); } }
I also have a class with the following code in which was provided for me but I am not entirely sure of its purpose. If anyone could also explain this to me I would be forever grateful.
import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.io.Serializable; public class MainForm extends JFrame implements ActionListener, Serializable { contacts book = new contacts(50); public MainForm() { super("Address Book"); contact contact1= new Person ("Ryan", 'M', new Date (2 ,05, 58)); contact contact2= new Person ("David", 'M', new Date (17 ,09, 71)); book.add(contact1); book.add(contact2); } public void actionPerformed(ActionEvent e) { } }