Splash Screen em Java - escrevendo um texto

1 resposta
mlimacarlos

Boa Noite Pessoal,

Peguei um exemplo de splash Screen pra implementar e estou com o seguinte problema no método splashText. O original cria um retângulo que é preenchido com a cor de fundo toda vez que precisa mudar o texto.Eu fiz uma imagem de fundo com ele e gostaria de apagar somente o texto. Tentei utilizar um layer alpha pra isso mas ainda não estou conseguindo. Alguma luz?

public static void splashText(String str)
    {
        if (mySplash != null && mySplash.isVisible())
        {   // important to check here so no other methods need to know if there
            // really is a Splash being displayed

            // erase the last status text
            //splashGraphics.setComposite(AlphaComposite.Clear);
            //splashGraphics.setPaint(Color.YELLOW);
            //splashGraphics.fill(splashTextArea);

            // draw the text
            
            splashGraphics.setPaint(Color.BLACK);
            splashGraphics.drawString(str, (int)(splashTextArea.getX() + 10),(int)(splashTextArea.getY() + 15));

            // make sure it's displayed
            mySplash.update();
        }
    }

1 Resposta

mlimacarlos

Bom… Achei uma outra solução. O splash antigo não dá pra inserir (pelo menos eu não sei!) uma interação com texto. Esse aqui pelo menos funciona direitinho quando eu ponho um texto sem medo dele melar o fundo.

import java.awt.*;
import java.awt.event.*;
 
public class splashScreen extends Frame implements ActionListener {
static void renderSplashFrame(Graphics2D g, int frame) {
final String[] comps = {"foo", "bar", "baz"};
g.setComposite(AlphaComposite.Clear);
g.fillRect(130,250,280,40);
g.setPaintMode();
g.setColor(Color.BLACK);
g.drawString("Loading "+comps[(frame/5)%3]+"...", 130, 260);
//g.fillRect(130,270,(frame*10)%280,20);
}
public splashScreen() {

final SplashScreen splash = SplashScreen.getSplashScreen();
 
if (splash == null) {
System.out.println("SplashScreen.getSplashScreen() returned null");
return;
}
Graphics2D g = (Graphics2D)splash.createGraphics();
if (g == null) {
System.out.println("g is null");
return;
}
for(int i=0; i<100; i++) {
renderSplashFrame(g, i);
splash.update();
try {
Thread.sleep(200);
}
catch(InterruptedException e) {
}
}
splash.close();
}

public static void main (String args[]) {
splashScreen test = new splashScreen();
}

    @Override
    public void actionPerformed(ActionEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
Criado 7 de junho de 2011
Ultima resposta 7 de jun. de 2011
Respostas 1
Participantes 1