• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

write "applet loading" instead of plain gray box

 
Hector Rui
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone
If someone can helpme please. I'll like to know how to change the gray color and write a loading message when loading an applet. I'm using graphics not images.

thankyou
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The process of loading an applet is under the control of the JVM; that includes what gets displayed. The earliest point in time where you can do anything is in the init() method.
 
Hector Rui
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thankyou
I use this example but it is for loading an applet that use images my applet use graphics. how do I substitute the image on this applet with my graphics.

import java.applet.*;
import java.awt.*;
import java.net.*;

public class loadingApplet extends Applet implements Runnable
{
private Image bigGIF;
private Thread thread;
private MediaTracker mt;
private boolean loaded;
private String message;


public void init()
{
super.init();

String gif = this.getCodeBase().toString() + "waytoobig.gif";
message = "Loading (be more original than this!) ...";

try
{
bigGIF = this.getImage(new URL(gif));
}
catch (MalformedURLException e) { }

mt = new MediaTracker(this);
mt.addImage(bigGIF, 1);

loaded = false;

thread = new Thread(this);
thread.start();
}


public void paint(Graphics g)
{
if (loaded)
{
g.drawImage(bigGIF, 0, 0, this);
}
else // (!loaded)
{
g.setColor(Color.blue);
g.fillRect(0, 0, this.size().width, this.size().height);

g.setColor(Color.white);
g.drawString(message, 10, 20);
}
}


public void run()
{
try
{
paint(this.getGraphics());

while(mt.statusAll(true) != MediaTracker.COMPLETE)
{
message += "..";
paint(this.getGraphics());
thread.sleep(500);
}
}
catch (InterruptedException e)
{
}
finally
{
loaded = true;
paint(this.getGraphics());
}
}


}
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All your graphics are done in the paint method by invoking nethods of the Graphics object - just like the example shows in the case of the image not being loaded.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic