Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

write "applet loading" instead of plain gray box

 
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
 
Rancher
Posts: 43016
76
  • 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: 43016
76
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic