Pessoal,
Caso algu�m tenha paci�ncia e um tempo sobrando gostaria que analizassem o
seguinte c�digo e me dissesse porque minha
mensagem n�o aparece na tela e minha imagem aparece, mas s� depois que dou
um "Refresh" no navegador.
import java.applet.*;
import java.awt.*;
public class vega extends Applet implements Runnable
{
Graphics g;
Image background;
int width;
int height;
boolean done_loading_image = true;
Thread my_thread = null;
boolean thread_running = true;
String message = "Ferrari F-550";
int message_length;
char char_array[];
public void init()
{
g = getGraphics();
background = getImage(getCodeBase(), "ferrari550.jpg");
Image offScrImage = createImage(size().width,
size().height);
Graphics offScrGC = offScrImage.getGraphics();
String parameter = getParameter("MESSAGE");
if (parameter != null)
message = parameter;
message_length = message.length();
char_array = new char[message_length];
message.getChars(0, message_length, char_array, 0);
}
public void start()
{
if (my_thread == null)
my_thread = new Thread(this);
}
public void run_thread()
{
if (!thread_running)
{
my_thread.start();
thread_running = true;
}
}
void delay()
{
try
{
Thread.sleep(300);
}
catch (InterruptedException e)
{
}
}
public void run()
{
repaint();
int red_character = 0;
Font font = new Font("Courier New", Font.BOLD, 20);
g.setFont(font);
FontMetrics font_metrics = g.getFontMetrics();
int string_width = font_metrics.stringWidth(message);
int string_height = font_metrics.getHeight();
while (true)
{
int x = (width - string_width)/2;
g.setColor(Color.white);
g.fillRect(x, height+10, string_width,
string_height);
for (int i = 0; i < message_length; i++)
{
if (i == red_character)
g.setColor(Color.red);
else
g.setColor(Color.black);
g.drawChars(char_array, i, 1, x,
height+30);
x +=
font_metrics.charWidth(char_array[i]);
}
if (++red_character == message_length)
red_character = 0;
else
while (char_array[red_character] ==
' ')
red_character++;
delay();
}
}
public boolean imageUpdate(Image img, int infoflags, int x, int y,
int w, int h)
{
if (infoflags == ALLBITS)
{
width = background.getWidth(this);
height = background.getHeight(this);
resize(width, height+40);
done_loading_image = false;
repaint();
run_thread();
return true;
}
else
return false;
}
public void paint(Graphics g)
{
if (!done_loading_image)
showStatus("loading image...");
else
{
showStatus("Image done");
g.drawImage(background, 0, 0, null);
}
}
}
Bruno Mar�al Lacerda Fonseca
Desenvolvedor - ICQ: 65526070
TBA Inform�tica Ltda
* Para n�o receber mais e-mails desta lista envie um e-mail para
[[EMAIL PROTECTED]]
e no corpo do email escreva [unsubscribe <seu-email>] ou acesse
http://apoio.cits.br:8080/guest/RemoteListSummary/javabr
Veja as mensagens antigas em http://www.mail-archive.com/javabr%40cits.br/