Jump to content
  • Advertisement
Sign in to follow this  

(Hopefully) Simple issue with an Applet

This topic is 2562 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

[font=arial, verdana, tahoma, sans-serif][size=2]

So I'm trying to take a game I made and package it into an applet, which, I gather, is a fairly simple process. The programming I did is all in native java using AWT components (the game is drawn to a Canvas object), so I just extracted an interface from my GameWindow class and called it AppletWindow, and made it contain a canvas, and function exactly as the GameWindow class. What I did runs fine in Eclipse, but does not function when embedded in an html file (penny for every time eclipse runs something that wont run outside eclipse...). I'm going to edit this post with thorough details, but while I tinker with it a while I thought I'd make a quick post in case this is some simple derp I'm not aware of regarding applets.[/font]

What happens is when you load the html file (currently on my desktop, and the jar is sitting next to it) the html file loads properly, and has the applet embedded in it, with the little java cup and the swirley animation around it, and an empty loading bar, which never progresses. I would assume this has something to do with the applet not starting correctly, but when I activated the java console to take a look at some of my debug output, it appears the game launches and enters the game loop as one would expect a properly functioning program to behave.

Is this possibly a symptom of the canvas not properly being displayed in the applet window? It clearly works just fine in eclipse, so I can't see anything obvious about what's going wrong here. I've tried opening the html file in chrome, firefox, and IE8 to no avail.

Thanks for any help anyone can offer! I'll update with some pics and source of the issue shortly.

EDIT: relevant code follows. Screenshots of applet not working and working in eclipse as well.

public class AppletWindow extends Applet {
private GameWindowCallback callback;
private int width;
private int height;
private BufferStrategy strategy;
private Graphics2D g;
private Canvas drawArea;

public void startRendering() {
System.out.println("Starting rendering");
if(strategy == null){
setPreferredSize(new Dimension(width, height));
this.setSize(new Dimension(width, height));
drawArea = new Canvas();
drawArea.setBounds(0, 0, width, height);

strategy = drawArea.getBufferStrategy();

mouse = new Mouse();
keyboard = new Keyboard();

if (callback != null)
private void gameLoop() {
System.out.println("Game Loop");
while (gameRunning) {
if(lastRender + 10 > System.currentTimeMillis())
g = (Graphics2D) strategy.getDrawGraphics();
g.fillRect(0, 0, width, height);

if (callback != null)

public void init() {
new TestApplet(this);
public void start() {
gameRunning = true;
public void stop() {
gameRunning = false;

Anything present in TestApplet shouldn't change anything. It's just a simple applet that only renders a single entity (the smug face) and moves it to wherever the mouse is if the mouse button is held down, and, as you can see in the screenshots, indicates that the entity has been moved.

While the game was running in chrome, I looked in the java console once again, and it is running. Observing a few stack traces yielded a lot of stuff to dig through, but probably the only relevant parts are that the program spends most of its time in line 125 (buried about 10 function calls deep, line 125 is in gameLoop, "strategy.show();") though I did manage to catch it twice on line 116 ("g.fillRect(0,0,width,height);".

Here are two pictures. The first is of the game running in the ecclipse applet loader as expected. In the console you can see the rendering begin, and the game loop start, and some relocation messages.

In the second, you can see the html file loaded(appletTest.html) and displaying properly, but the applet not displaying properly. Note the proper debug text in the console. A stack trace a few times verified that the game is indeed running (each one yielded a different state in a call, things are actually going on, it's not frozen somewhere).

Oh, and here's the contents of the html file, if that matters to anyone:
<Title>Applet Test</Title>

<Body bgcolor="lightgray">
Applet Test follows:<br>
<Applet Code="game.engine.AppletWindow.class" archive="testappplet.jar" width=400 Height=400>

Yes, testappplet.jar has 3 p's in it. I typo'd it and decided to be lazy and just reproduce it in the filename rather than open and edit the html file. I could have even done it just now, but I didn't.

So I have no idea how the applet could possibly be running but not displaying properly, I'm certain it has something to do with how I'm adding the canvas to the applet not properly leading to it being displayed. I've tried the internet, but noone seems to be very helpful on this subject (can't find anyone else with the same problem, and most articles on applets come from the early 12th century).

Sorry for the massive wall of text, I'm just trying to be thorough about providing information about the problem. I really just hope someone comes in and says "right after add(drawArea); add this line of code XXX" and that fixes it, but I'm sure there's some deeper problem I've gone and screwed myself with.

Thanks again,

Share this post

Link to post
Share on other sites
isn't there a draw function of some sort that should be getting called or paint or repaint or something? I'm not much for java so I wouldn't completely know.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!