Hi all :)
So here's what's going on. I'm working on building an Entrapment game, and I started off by simply building an application, with the intent of converting it to an applet later. All went well, and my java program worked fine, so I decided to convert it to an applet.
Here is where I started having problems. So far I have not been able to get the darned program to do anything! Everything compiles fine, but when I run the applet it simply says 'applet loaded', and nothing shows up.
I think that the problem is that it's not repainting, however I have no idea why. As you can see, I have a System.exit line in the repaint method. This should cause the program to generate an error as soon as it is hit during run-time; however no errors are given during either compilation or run-time. What I'm wondering here is why the program doesn't initiate the paint method when repaint() is called?
Sorry for the messy code... look at the init() method and the paint() method and you'll see what I'm talking about...
Code://import resources
import java.util.Scanner; //use to get input from various sources
import javax.swing.*; //use in basic GUI programs where the user types input into basic windows
import java.text.DecimalFormat; //use to format text
import java.util.Random; //use to generate random numbers
import java.io.*; //use to read/write files
import java.awt.*; //use for interactive/media
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.awt.image.*;
import javax.imageio.*;
public class Main extends JApplet
{
public Arrow arrow = null;
public void init()
{
try
{
offscreen = /*createImage(720,480);*/ImageIO.read(new File("background.png"));
} catch (IOException e) {System.out.println("sprite not found!");}
g = offscreen.getGraphics();
setBackground(Color.black);
repaint();
startGame();
}
public void startGame()
{
Game newGame = new Game();
while (newGame.lives>0)
{
score += newGame.Run(this);
newGame.level++;
}
}
// **************************** METHODS ***************************
private int x;
private int y;
private Image sprite;
private Image offscreen;
private Graphics g;
private int number = 0;
private int indxa = 0;
private int indxb = 0;
public Wall walls = null;
private Ball balls = null;
public int pointsRct[] = new int[5];
public int timeBonus = 1000;
public int score = 0;
public void Draw(String path, int X, int Y)
{
try{
x = X;
sprite = ImageIO.read(new File(path));
y = Y;
indxa++;
}catch (IOException e) {System.out.println("no sprite found!");}
}
public void paint(Graphics finalDraw)
{
System.exit(0);
//draw the wall being built
g.clearRect(0,0,720,480);
g.setColor(Color.CYAN);
g.fillRect(pointsRct[1],pointsRct[2],pointsRct[3],pointsRct[4]);
//draw the walls already constructed
walls.wallsPhilled = -182; // this is done so as to accurately count the walls, excluding those given
g.setColor(Color.BLUE);
for (int a = 0; a<walls.wall.length; a++)
{
for (int b = 0; b<walls.wall[a].length; b++)
{
if(walls.wall[a][b] == true)
{
g.fillRect(a*8,b*8,8,8);
walls.wallsPhilled++;
}
}
}
//draw the balls
g.setColor(Color.RED);
for (int a = 0; a<balls.balls; a++)
{
g.fillOval((int)balls.x[a],(int)balls.y[a],8,8);
}
//draw the text
if (walls.wallsPhilled<4000)
{
g.drawString(walls.wallsPhilled + " / 4000", 335, 12);
}
else
{
g.drawString("Level cleared! Click to continue", 250, 12);
g.drawString(walls.wallsPhilled + " / 4000", 450, 12);
}
g.drawString("Score: " + score, 10, 12);
g.drawString("Time Bonus: " + timeBonus, 600, 12);
if (timeBonus>0)
timeBonus --;
while (indxb<=indxa)
{
g.drawImage(sprite,x,y,null);
indxb++;
}
indxa = 0;
indxb = 0;
super.paint(finalDraw);
finalDraw.drawImage(offscreen,0,0,null);
}
public void update(Graphics g2)
{
paint(g2);
}
public void wallHandleIs(Wall WH)
{
walls = WH;
}
public void ballHandleIs(Ball BH)
{
balls = BH;
}
}

