Good Day to all.. after reading more about Applets
Here.QUOTE
the applet can be initialized once and only once....
with that said. I assumed that the init() method will only be called once. But through back and forth testing in firefox and IE. (i.e. Clearing Cookies, browsing history in every trial) ... I've noticed the init() method is always called every time I revisit the site.
Heres what I've been doing:
1. Open a Fresh Browser ( Cleared Cookies and everything )
2. Go to mySite where I've uploaded the Applet for testing.
3. Wait until the progress bar finished while looking at the JAVA CONSOLE for the loading images status.
4. After the game finally start. I clicked the browser Go Back Button.
5. After #4 I clicked the Browser Go Forward Button.
After those this is what I've observed:
1. The Browser status display a applet started which is correct because thats what it supposed to do.
2. The JAVA CONSOLE display IMAGES BEING DOWNLOADED AGAIN3. Because of #2 I'm Assuming that the APPLET is CALLING the INIT() method again.[/b] NOW THAT IS MY PROBLEM.
I can't let user re download all images again after revisiting the site without even closing the browser..
Here is My Site where I uploaded the applet.Here is my APPLET CLASS
java
public class HelloJava3 extends JApplet
implements ActionListener
{
Timer t, t2;
ImageIcon bg, bgLayout;
JLabel bgLabel, bgLayoutLabel;
HelloComponent3 gameEngine;
JPanel panel;
JProgressBar pgBar;
int progress = 0, sliderUp = 0, sliderDown = 200;
Boolean animateIntrance =false;
AnimationComponent entranceUp, entranceDown;
AnimationComponent countImage = new AnimationComponent();
public AnimationComponent st, sr, sr2;
SwingWorker worker = new SwingWorker(){
protected HelloComponent3 doInBackground(){
AnimationComponent countImage = new AnimationComponent();
gameEngine = new HelloComponent3();
System.out.println(countImage.getImageLoadedCount());
return gameEngine;
}
public void done(){
gameEngine.setBounds(0,0,500,400);
panel.add (gameEngine);
gameEngine.requestFocus() ;
panel.repaint();
}
};
public void init(){
progress = 48;
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
createGUI(); }
});
} catch (InterruptedException e) {}
catch (InvocationTargetException e) {}
worker.execute();
t = new Timer( 1, this);
t.start();
entranceUp = new AnimationComponent("sliderWindowUp.png");
entranceDown = new AnimationComponent("sliderWindowDown.png");
entranceDown.setBounds(0,sliderDown,500,200);
entranceUp.setBounds(0,sliderUp,500,200);
panel.add(entranceUp);
panel.add(entranceDown);
}
public void start(){
}
public void stop(){}
public void destroy(){}
public void createGUI(){
bgLabel = new JLabel("NOW LOADING", JLabel.CENTER );
pgBar = new JProgressBar(0, progress);
pgBar.setValue(0);
pgBar.setStringPainted(true);
pgBar.setBounds(150,180,200,20);
panel = new JPanel();
panel.setLayout(null);
panel.setBounds(0,0,500,400);
bgLabel.setBounds(145,160,200,20);
panel.add( bgLabel );
panel.add( pgBar );
getContentPane().add(panel);
}
public void actionPerformed(ActionEvent e){
pgBar.setValue(countImage.getImageLoadedCount());
if(countImage.getImageLoadedCount() == progress && !animateIntrance){
t.stop();
t2 = new Timer(1, this);
t2.start();
pgBar.setVisible(false);
bgLabel.setVisible(false);
animateIntrance = true;
}
if(animateIntrance){
entranceDown.setLocation(0,sliderDown++);
entranceUp.setLocation(0,sliderUp--);
if(sliderDown > 400){
animateIntrance = false;
entranceDown.setVisible(false);
entranceUp.setVisible(false);
t2.stop();
}
}
}
class gameLayout extends JPanel{
}
}
The init method execute a swing worker that loads up my gameEngine and download all the images need for the game.
I badly need to resolve this performance issue first before actually continuing on my game proper. I'm kind of stuck here.
This post has been edited by mensahero: 4 Jun, 2008 - 07:11 AM