*rawr* Core JApplet file

I would very much like to create a “core” file as the basis of my game, displayed in an applet

Basically, I need 2 files (see below)

Core.java - contains methods:
stop()
run()
init()
gameLoop()
update()

Manager.java - contains methods (and some others, but these are the methods im having issues with)
setMode()
getGraphics()
update()

I’m using ScreenManager.java as my guide
(from Chapter 2 of Developing Games in Java - I book I’ve recently purchased and am totally in love with)
The problem is, I want to learn how to make full screen games, but I also want to learn how to implement this code into a JApplet (not a full screen window) and I’m having some trouble making the connection.
(I have another 30 Chapter book on just Java, and only 1 Chapter covers Applets. Not to mention the author of Developing Games in Java assumes the reader is only interested in Full Screen Windows)

Think you can help, but haven’t read the Book?
Seriously, it’s an awesome book, and I recommend it to anyone who’s new to game programming in Java. The source code for ScreenManager.java is found in Chapter 2.
You can visit the author’s website and take a look at the code in the book here.

Think you can help, but you don’t know what the heck I’m talking about?
That’s ok, I’m a little cooky. I appreciate any help you can give me. Basically I want to make a JApplet without drawing graphics using:

public void paint ( Graphics g )
{
   super.paint ( g );
   g.drawString( "Hello World~!", 25, 25 );
}

If you decide to grant me some of your code, I thank you in advance; however I do request that the code you write is VERY VERY VERY simple. I do not want to steal anyone else’s code. I really want to read it, understand it, and then expand on it using my own brain.

Thanks in advance.

Hi

I’m not sure if I understood the question, so correct me if I’m wrong.

Basically you want to create an applet class (Core.java) and then use Manager.java to handle the actual drawing? Since you want to create an applet, you won’t need any of the display mode stuff in ScreenManager.

Here is some simple code:

Core.java

import java.applet.*;
import java.awt.*;

public class Core extends Applet implements Runnable
{
	private Image dbImage;
	private Graphics dbg;

	public void init()
	{
		setBackground (Color.BLACK);
	}

	public void start ()
	{
		Thread th = new Thread (this);
		th.start ();
	}

	public void stop()
	{

	}

	public void destroy()
	{

	}

	public void run ()
	{
		Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
                //game loop
		while (true)
		{
			repaint();

			try
			{
				Thread.sleep (20);
			}
			catch (InterruptedException ex)
			{

			}

			Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
		}
	}

	public void update (Graphics g)
	{
		if (dbImage == null)
		{
			dbImage = createImage (this.getSize().width, this.getSize().height);
			dbg = dbImage.getGraphics ();
		}

		dbg.setColor (getBackground ());
		dbg.fillRect (0, 0, this.getSize().width, this.getSize().height);

		dbg.setColor (getForeground());
		paint (dbg);

		g.drawImage (dbImage, 0, 0, this);
	}

	public void paint (Graphics g)
	{
		
	}
}

Manager.java


import java.awt.*;

public class Manager extends Core{

    public void update(Graphics g)
    {
        super.update(g);
    }

    public void paint(Graphics g)
    {
        super.paint(g);
        g.setColor  (Color.WHITE);
	g.drawString( "Hello World~!", 25, 25 );
    }

}

thats exactly what i was looking for, thank you~!
i knew it was something fairly “simple” to achieve, im just not very familiar with Applets (hence why I want to learn more about using them)
thanks again :smiley: