Não funciona no JInternalFrame

3 respostas
D

Beleza galera,

To precisando de uma ajudinha, tenho esse exemplo que esta funcionando com extends Frame eu precisaria que ele funciona-se com extends JInternalFrame, ja tentei varias vezes fazendo algumas alterações e nada.

import java.awt.*;
import java.awt.event.*;

public class Movie2 extends Frame implements ActionListener {
  private int tempoEspera, totalImagens, atual = 0;
  private boolean play = false;
  private Image imagem[];
  private Button bPrev, bPlay, bNext;
  private Insets in;
  private Image buffer;
  private Graphics cg;
  private int iw, ih;

  public Movie2(String diretorio, int totalImagens, int tempoEspera) {
    setTitle("Movie2");
    setLayout(null);
    this.totalImagens = totalImagens;
    this.tempoEspera = tempoEspera;
    imagem = new Image[totalImagens];
    Toolkit tk = Toolkit.getDefaultToolkit();
    MediaTracker mt = new MediaTracker(this);
    for (int i=0; i<totalImagens; i++) {
      imagem[i] = tk.getImage(diretorio+"T"+(i+1)+".gif");
      mt.addImage(imagem[i], i);
      try {
        mt.waitForID(i);
      } catch (Exception e) { }
    }
    bPrev = new Button("-"); add(bPrev);
    bPrev.addActionListener(this);
    bPlay = new Button(">"); add(bPlay);
    bPlay.addActionListener(this);
    bNext = new Button("+"); add(bNext);
    bNext.addActionListener(this);
    addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0);
      }
      public void windowOpened(WindowEvent e) {
        in = getInsets();
        iw = imagem[0].getWidth(null); // dimensões da imagem
        ih = imagem[0].getHeight(null);
        buffer = createImage(400, 160); // cria buffer
        cg = buffer.getGraphics();      // obtem contexto grafico do buffer
        cg.setColor(Color.white);       // especifica cor de fundo
        cg.fillRect(0,0,iw,ih);         // "limpa" buffer
        cg.drawImage(imagem[0],0,0,null); // desenha 1a imagem
        setSize(iw+in.left+in.right+16,ih+in.top+in.bottom);
        bPrev.setBounds(getSize().width-in.right-18,in.top+2,16,16);
        bPlay.setBounds(getSize().width-in.right-18,in.top+18,16,16);
        bNext.setBounds(getSize().width-in.right-18,in.top+34,16,16);
    }
    });
  }

  public void actionPerformed(ActionEvent e) {
    if (e.getSource()==bPlay) {
      if (atual >= totalImagens-1) {
        atual = 0;
      }
      play = true;
    } else if (e.getSource()==bPrev) {
      atual = atual>0 ? atual-1 : totalImagens-1;
    } else {
      atual = (atual+1) % totalImagens;
    }
    repaint();
  }

  public void paint(Graphics g) {
    if (play) {
      g.drawImage(buffer, in.left, in.top, null); // renderiza buffer
      atual++; // avança contador de imagens
      if (atual==totalImagens) {
        play = false; atual--;
      } else {
        cg.fillRect(0,0,iw,ih);               // "limpa" buffer
        cg.drawImage(imagem[atual],0,0,null); // desenha prox imagem
        try {
          Thread.sleep(tempoEspera);
        } catch (InterruptedException e) { }
        repaint();
      }
    } else {
      g.drawImage(buffer, in.left, in.top, null);
      cg.fillRect(0,0,iw,ih);               // "limpa" buffer
      cg.drawImage(imagem[atual],0,0,null); // desenha prox imagem
    }
  }

  public static void main(String a[]) {
    new Movie2(a.length>0 ? a[0] : "Duke/",
               a.length>1 ? Integer.parseInt(a[1]) : 10,
               a.length>2 ? Integer.parseInt(a[2]) : 200).show();
  }
}

Valeu

3 Respostas

farribeiro

denis.llopes:
Beleza galera,

To precisando de uma ajudinha, tenho esse exemplo que esta funcionando com extends Frame eu precisaria que ele funciona-se com extends JInternalFrame, ja tentei varias vezes fazendo algumas alterações e nada.

Valeu

Para que a façanha funcione você precisa de um tipo MDI Form/Child

Construa um JFrame com um JDesktop e coloque como JInternal…

E outra coisa(corrijam se estiver errado), não se dá para utilizar componentes visuais awt com swing.Será necessário reescrever seu código.

D

Eu ja fiz isto e fica dando erro no addWindowListener

E

JInternalFrame’s possuem listeners próprios, dê uma olhada em:

http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/event/InternalFrameAdapter.html

Criado 2 de julho de 2005
Ultima resposta 3 de jul. de 2005
Respostas 3
Participantes 3