I had posted earlier requesting help with my code, but I quickly cleared up my issues. I am almost complete with my work, but I was just wondering if I could get some help on fixing some code which may cause my program to crash or not function properly.

public class Database {
 
 Game[] Chars;
   int i;
   String	CharInfo ;
   
	public Database() 
	    {
			Chars = new Game[5];
			i = 0;
	    }
	    
	public void add(String nm, String rc,String typ,String jc, String wep )
	{
		if (i>4)
		{
			JOptionPane.showMessageDialog ( null, "You are exceeding the set amount of characters, you will now start over.", "Error - Character limit exceeded", JOptionPane.ERROR_MESSAGE);
			i = 0;
		}	
		if (i <= 4)
		{
			Chars[i] = new Game(nm, rc,typ, jc,wep);
    		i++;
		}
	}

[B]	public void remove(int index)
		{
			Chars[index-1]= null;
		}[/B]


	public String toString()
		{
	 	String Temp;
		for (int x = 0;x <=  4; x++ )
			{
	  	
		Temp =  "Character name:" + Chars[x].getName()+
				"\nRace: "+Chars[x].r.getRace()+
	    		"\nSkin Color: " + Chars[x].r.getColor(); 
	    CharInfo = CharInfo + Temp;
	
			}
		return CharInfo;
		}
}

I was wondering how to make a check where my "remove" method gets checked later on when one of my button's is clicked.

if(e.getSource()==show)
	   {
	    if(db.Chars[i]==null)
	{
JOptionPane.showMessageDialog ( null, "There is no character in this slot!", "Chars info", JOptionPane.ERROR_MESSAGE);
	}

That is basically my code for the button, but I would like it to also "reset" the array slot which was set to null, that way I can still make a dialog box show up displaying other info while the array slot which is nulled does not display anything. I also tried doing

Chars[index-1]= "";

so that the specific slot is set to blank, but I recieve incompatible types.

Also I would like to request some assistance on a Sort() method which will be created in my database class, which can sort through the array slots according to "name, race, weapon, job" etc.


Once again, thanks for the assistance in advance.

Of course you get an error, since the Chars is an array of Game objects and you are trying to pass a String: "".
In the method you are doing:
Chars = new Game(nm, rc,typ, jc,wep)

Do the same, only this time pass empty Strings.

Also it is better to use the Vector class instead of an array. Just remember to override the equals method in the Game class

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.