My project works in the Greenfoot editor, but when I export it to a .jar file, the Greenfoot does not repaint the screen, it just paints over the last frame. Any ideas?
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.*;
import java.util.*;
public class SJHS extends World
{
public int score, level;
int playing;
GreenfootSound backgroundMusic[] = {new GreenfootSound("yaketysax.mp3"), new GreenfootSound("yaketysax.mp3"), new GreenfootSound("yaketysax.mp3"), new GreenfootSound("yaketysax.mp3"), new GreenfootSound("yaketysax.mp3"), new GreenfootSound("yaketysax.mp3"), new GreenfootSound("yaketysax.mp3"), new GreenfootSound("yaketysax.mp3"), new GreenfootSound("yaketysax.mp3"), new GreenfootSound("yaketysax.mp3"), new GreenfootSound("yaketysax.mp3"), new GreenfootSound("yaketysax.mp3"), new GreenfootSound("centipede.mp3")};
/**
* Constructor for objects of class SJHS.
*
*/
public SJHS()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(1100, 600, 1);
addObject(new Moloney(), 300, 200);
Generator.generateWorld(this, new ArrayList<Room>());
playing = Greenfoot.getRandomNumber(backgroundMusic.length);
for (int i = 0; i < backgroundMusic.length - 1; i++)
{
backgroundMusic[i].setVolume(45);
}
for (int i = backgroundMusic.length - 1; i < backgroundMusic.length; i++)
{
backgroundMusic[i].setVolume(100);
}
backgroundMusic[playing].play();
updateScore();
}
public void act()
{
handleMusic();
if (getObjects(Moloney.class).size() == 0)
{
getBackground().drawString("You lose!", getWidth() / 2, getHeight() / 2);
}
else if (getObjects(Student.class).size() == 0)
{
level++;
Moloney moloney = (Moloney)getObjects(Moloney.class).get(0);
for (int i = 0; i < Math.log(level * 12) / Math.log(1.2); i++)
{
Student placed = new Student();
addObject(placed, Greenfoot.getRandomNumber(getWidth()), Greenfoot.getRandomNumber(getHeight()));
while (moloney.intersectingStudent())
placed.setLocation(Greenfoot.getRandomNumber(getWidth()), Greenfoot.getRandomNumber(getHeight()));
}
}
}
public void handleMusic()
{
if (!backgroundMusic[playing].isPlaying())
{
playing = Greenfoot.getRandomNumber(backgroundMusic.length);
backgroundMusic[playing].setVolume(45);
backgroundMusic[playing].play();
}
}
public void updateScore()
{
GreenfootImage background = new GreenfootImage(getWidth(), getHeight());
Font larger = background.getFont().deriveFont(28.0f);
background.setFont(larger);
background.setColor(Color.black);
background.drawString("Click to shoot Dress Codes at people. Don't let the students run into you!", 45, 50);
background.drawString("Score: " + score, 45, 100);
background.drawString("Level: " + level, 45, 150);
setBackground(background);
}
}
GreenfootImage background = getBackground();