JApplet behaving unexpectedly
Posted
by
JohnW
on Stack Overflow
See other posts from Stack Overflow
or by JohnW
Published on 2012-06-10T00:28:45Z
Indexed on
2012/06/10
4:40 UTC
Read the original article
Hit count: 214
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JApplet;
import javax.swing.Timer;
public class CountingSheep extends JApplet
{
private Image sheepImage;
private Image backgroundImage;
private GameBoard gameBoard;
private scoreBoard scoreBoard;
public void init()
{
loadImages();
gameBoard = new GameBoard(sheepImage, backgroundImage);
scoreBoard = new scoreBoard();
getContentPane().add(gameBoard);
getContentPane().add(scoreBoard);
}
public void loadImages()
{
sheepImage = getImage(getDocumentBase(), "sheep.png");
backgroundImage = getImage(getDocumentBase(), "bg.jpg");
}
}
Update guys:
Alright, first of all, thank you very much for all the help you've given so far (specifically creemam and Hovercraft Full of Eels), and your persistence. You've helped me out a lot as this is incredibly important (i.e. me passing my degree). The problem now is:
The program works correctly when nothing but the GameBoard
class is added to the JApplet
, however, when I try to add the ScoreBoard
class, both Panel
classes do not show on the Applet. I'm guessing this is now down to positioning? Any ideas?
EDIT: Gone back to the previously asked question Hovercraft, and found it was due to the layout of the contentPane and the order at with the components were added. Thanks to all of you so much. People like you make the development community a bit of alright.
© Stack Overflow or respective owner