i rebuild the code i posted earlier, and the problem is a totally diferent one for now lol, i rebuilt this "advertisement" to work on run so it can be stoped during animations and all that (i think xD), well here's the code, it works the first time, but the program is suppost to do is, run the first time with imag1 and som1 and the strings defined....but its suppost to respond correctly to keyboard events running the program with the corresponding informations depending on the key pressed......can anyone see whats the problem here? i'm getting crazy with this....ty for the help
CODE
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.lang.*;
public class trabalho_pub2 extends Applet implements KeyListener,MouseListener{
public Image imag1,imag2,imag3,imagem,logo;
public AudioClip som1,som2,som3,som;
public int x=0,y=0,a=0,b=0,c=0,d=0;
public int m=0,n=0,o=0,p=0,cont=0,accao=0;
public int cor=0,fase=0,anim=2,r=-100,t=500;
public String s="",s1="",s2="";
public Font f1=new Font("Comic Sans MS",Font.BOLD,20);
public Font f2=new Font("Comic Sans MS",Font.PLAIN,16);
public char ch='a';
public void init() {
resize(500,500);
imag1=getImage(getDocumentBase(), "mariusz.jpg");
imag2=getImage(getDocumentBase(), "batido.jpg");
imag3=getImage(getDocumentBase(), "larilas.jpg");
logo=getImage(getDocumentBase(), "logo.jpg");
som1=getAudioClip(getDocumentBase(), "strongam.wav");
som2=getAudioClip(getDocumentBase(), "bigboom.wav");
som3=getAudioClip(getDocumentBase(), "alaska.wav");
setBackground(Color.white);
addKeyListener( this );
addMouseListener( this );
}
public void mouseEntered( MouseEvent e ) { }
public void mouseExited( MouseEvent e ) { }
public void mousePressed( MouseEvent e ) { }
public void mouseReleased( MouseEvent e ) { }
public void mouseClicked( MouseEvent e ) {
accao=5;
repaint();
ch='a';
start();
}
public void keyPressed( KeyEvent e ) { }
public void keyReleased( KeyEvent e ) { }
public void keyTyped( KeyEvent e ) {
ch=e.getKeyChar();
if (ch=='s'||ch=='n')
{
fase=1;
start();
}
}
public void start() {
if (ch=='a')
{
s="Quere ser FORTE como um Touro?";
s1="Prima 'S' para Sim.";
s2="Prima 'N' para Não.";
imagem=imag1;
som=som1;
x=135;y=80;
fase=0;cor=0;anim=0;
a=70;b=360;c=390;d=420;
}
if (ch=='s')
{
imagem=imag2;
som=som2;
x=100;y=35;
s="E aqui está a formula mágica...";
s1="...para atingir o seu objectivo!!";
s2="(Prima o rato para voltar)";
a=110;b=400;c=430;d=460;
cor=1;anim=1;
}
if (ch=='n')
{
imagem=imag3;
som=som3;
x=31;y=50;
s="Pfffff!!! Flor de estufa...";
s1="Toma CELL-TECH HARDCORE!";
s2="(Prima o rato para voltar)";
a=120;b=400;c=430;d=460;
cor=2;anim=2;
}
run();
}
public void run() {
accao=0;
repaint();
som.play();
while (anim==1)
{
if (r<500&&t>-100)
{
accao=1;
repaint();
try{
Thread.sleep(60);
}catch (Exception e) {}
accao=2;
repaint();
t=t-4;r=r+4;
}
else
{
r=-100;t=500;
}
}
while (anim==2)
{
accao=3;
repaint();
try{
Thread.sleep(100);
}catch (Exception e) {}
accao=4;
repaint();
m=m+4;n=n+4;o=o+4;p=p+4;
}
}
public void update(Graphics g) {
paint(g);
}
public void paint(Graphics g) {
if(accao==0)
{
g.drawImage(imagem,x,y,this);
if (cor==0)
{
g.setColor(Color.black);
}
if (cor==1)
{
g.setColor(Color.red);
}
if (cor==2)
{
g.setColor(Color.pink);
}
g.setFont(f1);
g.drawString(s,a,b);
g.setFont(f2);
g.drawString(s1,a,c);
g.setColor(Color.black);
if (imagem==imag1) g.drawString(s2,a,d);
else g.drawString(s2,a+20,d);
}
if (accao==1)
{
g.drawImage(imagem,x,y,this);
g.drawImage(logo,5,r,100,100,this);
g.drawImage(logo,395,t,100,100,this);
}
if (accao==2)
{
g.clearRect(5,r,100,100);
g.clearRect(395,t,100,100);
}
if (accao==3)
{
g.drawImage(imagem,x,y,this);
g.setColor(Color.red);
//esquerda
g.fillArc(30,390,60,60,m,44);
g.fillArc(30,390,60,60,n,44);
g.fillArc(30,390,60,60,o,44);
g.fillArc(30,390,60,60,p,44);
//direita
g.fillArc(390,390,60,60,m,44);
g.fillArc(390,390,60,60,n,44);
g.fillArc(390,390,60,60,o,44);
g.fillArc(390,390,60,60,p,44);
g.setColor(Color.yellow);
//esquerda
g.fillOval(52,413,17,17);
//direita
g.fillOval(412,413,17,17);
}
if (accao==4)
{
g.clearRect(30,390,60,60);
g.clearRect(390,390,60,60);
}
if (accao==5)
{
g.clearRect(0,0,500,500);
}
}
}