I am having some trouble with the coding for the api. games4j.com has all of the codes and files, but when I insert the api codes into my doe I get an error. Please help me. I am getting the error with these two lines

loggedIn = Highscore.isLoggedIn(applet);

and

Highscore.save(applet, score [,level]);

Thanks for any help.

Did you import Highscore? Where is the Highscore class coming from.

What "api" you are referring to?

I imported this

import com.games4j.webAPI.*;

and this package is coming from games4j.com under the game developers tab under api's (it can be downloaded) It shows what codes to add on the website, but I copy the codes directly from the website to my code and it doesn't work.

Edited 5 Years Ago by sirlink99: n/a

i have the com/games4j/webAPI folder in the same location as my game, but I still get an error with the (applet) parts and the [,level] part. Why is this I can take a screenshot if you wish.

Exactly what are the errors? This line as written is not valid syntax

Highscore.save(applet, score [,level]);

You cannot have brackets around a parameter like that. Perhaps there are two versions of that method, one that includes level and one that does not? If you copied it from documentation, maybe they were indicated an optional parameter?

Post the stack traces of the errors.

I get a problem with the applets after I may have fixed the error. it says that there is "no entity named applet was found in this environment"

Take it out? Use or create the appropriate parameter variable?

I don't know because I have no idea what that code you copied and pasted from somewhere is supposed to do and I have no knowledge of the rest of your program. You need to read the docs more closely and figure out what that 'applet' variable is in their code.

ok here is my code

// The "SpaceSpam" class.
import java.applet.*;
import java.awt.*;
import javax.swing.*;
import com.games4j.webAPI.*;
import java.awt.event.*;


public class SpaceSpam extends Applet implements KeyListener, ActionListener
{
    int score;
    boolean loggedIn;
    Timer timeLeft;
    int screen = 0;
    Font title, normal;
    int time = 20;

    // Place instance variables here

    public void init ()
    {
	loggedIn = Highscore.isLoggedIn(applet);
	resize (300,300);
	timeLeft = new Timer (1000, this);
	title = new Font ("Chiller", 25, 25);
	normal = new Font ("Arial", 12, 12);
	
	addKeyListener (this);

	// Place the body of the initialization method here
    } // init method


    public void paint (Graphics g)
    {
	if (!loggedIn)
	{
	    g.drawString ("log in to be able to save highscores!!!", 55, 10);
	}
	if (screen == 0)
	{
	    g.setFont (title);
	    g.drawString ("Space Spam", 110, 40);
	    g.drawString ("Press enter to start", 80, 200);
	    g.setFont (normal);
	}
	else if (screen == 1)
	{
	    g.setFont (title);
	    g.drawString ("" + score, 120, 120);
	    if (time <= 0){
	    g.setFont (normal);
	    g.drawString ("Press CTRL to return to the title screen", 55,290);
	
	    }
	    }

	// Place the body of the drawing method here
    } // paint method


    public void keyPressed (KeyEvent e)
    {       
    }


    public void keyReleased (KeyEvent e)
    {
    int key = e.getKeyCode ();

	if (key == KeyEvent.VK_SPACE && time > 0)
	{
	    score += 1;
	    repaint ();
	}
	if (key == KeyEvent.VK_ENTER)
	{
	    screen = 1;
	    repaint ();
	    timeLeft.start();
	    score = 0;
	}
	if (key == KeyEvent.VK_CONTROL){
	    screen = 0;
	    time = 60;
	    repaint();
	}
    }


    public void keyTyped (KeyEvent e)
    {
    }


    public void actionPerformed (ActionEvent e)
    {
	time -= 1;
	if (time <= 0)
	{
	    timeLeft.stop ();
	    repaint();
	    Highscore.save(applet, score);
	}
    }
} // SpaceSpam class

and here is the website

Try replacing "applet" with "this". They don't have posted javadocs for the API but I would guess those are references to the current Applet instance.

Edit: I opened the Highscore class and yes, those are Applet references, so this should work.

Edited 5 Years Ago by Ezzaral: n/a

that fixed the applet problem, but now I have another problem with this line

loggedIn = Highscore.isLoggedIn(applet);

I get 17 errors and the description it gives me is

Type javax.cryto.BadPaddingException was not found.

any idea about this one?

thanks for all the help.

Did you change that line to

loggedIn = Highscore.isLoggedIn(this);

You should also move that to the start() method instead of init().

I did and Also I have no start method. If I make one could I call it from the init() because when I tried calling a second graphics in a previous program it didn't work.

start() is a standard Applet lifecycle method that you can override. You don't need to call it yourself.

Edited 5 Years Ago by Ezzaral: n/a

I added in the start. here is my new code

// The "SpaceSpam" class.
import java.applet.*;
import java.awt.*;
import javax.swing.*;
import com.games4j.webAPI.*;
import java.awt.event.*;


public class SpaceSpam extends Applet implements KeyListener, ActionListener
{
    int score;
    boolean loggedIn;
    Timer timeLeft;
    int screen = 0;
    Font title, normal;
    int time = 20;

    // Place instance variables here

    public void start(){
    loggedIn = Highscore.isLoggedIn(this);
    }
    public void init ()
    {
        
        resize (300,300);
        timeLeft = new Timer (1000, this);
        title = new Font ("Chiller", 25, 25);
        normal = new Font ("Arial", 12, 12);
        
        addKeyListener (this);

        // Place the body of the initialization method here
    } // init method


    public void paint (Graphics g)
    {
        if (!loggedIn)
        {
            g.drawString ("log in to be able to save highscores!!!", 55, 10);
        }
        if (screen == 0)
        {
            g.setFont (title);
            g.drawString ("Space Spam", 110, 40);
            g.drawString ("Press enter to start", 80, 200);
            g.setFont (normal);
        }
        else if (screen == 1)
        {
            g.setFont (title);
            g.drawString ("" + score, 120, 120);
            if (time <= 0){
            g.setFont (normal);
            g.drawString ("Press CTRL to return to the title screen", 55,290);
        
            }
            }

        // Place the body of the drawing method here
    } // paint method


    public void keyPressed (KeyEvent e)
    {       
    }


    public void keyReleased (KeyEvent e)
    {
    int key = e.getKeyCode ();

        if (key == KeyEvent.VK_SPACE && time > 0)
        {
            score += 1;
            repaint ();
        }
        if (key == KeyEvent.VK_ENTER)
        {
            screen = 1;
            repaint ();
            timeLeft.start();
            score = 0;
        }
        if (key == KeyEvent.VK_CONTROL){
            screen = 0;
            time = 60;
            repaint();
        }
    }


    public void keyTyped (KeyEvent e)
    {
    }


    public void actionPerformed (ActionEvent e)
    {
        time -= 1;
        if (time <= 0)
        {
            timeLeft.stop ();
            repaint();
            Highscore.save(this, score);
        }
    }
} // SpaceSpam class

I am still getting the same error.

I have no further idea. If it's coming from their API classes then you may have to contact them and ask about it.

I believe I may have found the issue. I may need a java 6 IDE to be able to compile their code because it is the latest version and the newest version of java they can host is 6 so they may have updated the code and it stopped working for erlier versions of java. Do you have one that can easily compile code?

This question has already been answered. Start a new discussion instead.