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) {
	
	
}
}

Use an ArrayList rather than an array, and you don't have to worry about all that array manipulation. And as far as "storing" the data, how do you propose to do that with an empty actionPerformed method?

Use an ArrayList rather than an array, and you don't have to worry about all that array manipulation. And as far as "storing" the data, how do you propose to do that with an empty actionPerformed method?

Well as I stated the MainForm was a class given to me to start with so I'm not sure what is to go here. I have an actionPerformed method in my GUI class (first snippet) would the save to array method not go in there? Also, what do you mean exactly by not having to worry about all that array manipulation?

Maybe I'll come back to this later. I knew it was going to be this kind of question and I am just not in the mood right now.

Maybe I'll come back to this later. I knew it was going to be this kind of question and I am just not in the mood right now.

I see. I wait in anticipation :)

commented: You should at least make an attempt with the info you have. -2

Any help guys? :S

No good having a forum if there's no one to help is there? :|

It's because you posted a ton of code and it doesn't look like you tried very hard at solving this yourself, so none of us really care enough to help you. Read about ArrayList on google and you'll see what Masijade means. Read about ActionListener and you'll figure out how to implement it.

It's because you posted a ton of code and it doesn't look like you tried very hard at solving this yourself, so none of us really care enough to help you. Read about ArrayList on google and you'll see what Masijade means. Read about ActionListener and you'll figure out how to implement it.

For your information I have tried. This forum was my last resort after many weeks of stress! This forum has too many so called "experts" who are on their high horses and like to ignore or dismiss those who want help which begs the question why should this forum exist if it doesn't provide the service a forum is meant to provide?

no point in having knowledge if you do not wish to share it.

Honestly posts like the one above just make you look stupid. I have almost 2000 posts in this forum, almost all of them trying to help people. You have 18 posts, probably all of them asking for help. There's nothing wrong with asking for help, but you are not entitled to receive it. The main reason I even posted in this thread was because your attitude indicated that you thought you were entitled, ("no good having a forum if there's no one to help.."). The people who help here are volunteers. Obviously your posts didn't provide enough info to warrant us going out of our way to help you like I pointed out before.

Most of your 2000 posts do not help with programming, they are mainly giving a link to the API, discussing TV or making criticisms. Makes one wonder do you actually know much about programming or are you just one of those people who thinks forum post counts are very important to them as you seem to "mock" my 18 posts.

Most of your 2000 posts do not help with programming, they are mainly giving a link to the API, discussing TV or making criticisms. Makes one wonder do you actually know much about programming or are you just one of those people who thinks forum post counts are very important to them as you seem to "mock" my 18 posts.

This isn't about my level of programming skill or yours. The important thing is learning how to ask questions well and showing effort, not expecting people to do your work for you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.