Janela!

6 respostas
F
Como faço para que as imagens que este programa gera sejam impressas em uma window? eu tentei fazer criando um novo objeto window mas deu errado.

import java.applet.AppletStub;

import java.awt.*;
public

class ScreenShow extends java.applet.Applet implements Runnable,AppletStub {

int frame;

int delay;

Window janela;
Thread animator;

Dimension offDimension;
Image offImage;
Graphics offGraphics;

Image frames[];

/**
 *inicializa parametros a serem usados na thread
 */

public void init() {
	appletResize(1024,768);
String str = getParameter("fps");
int fps = (str != null) ? Integer.parseInt(str) : 10;
delay = (fps > 0) ? (1000 / fps) : 100;// delay no fps operador ternário
 Toolkit t = Toolkit.getDefaultToolkit();
frames = new Image[33];//lembrar de colocar o array com o tamanho dos arquivos
for (int i = 1 ; i < 33 ; i++) {
    frames[i-1] = t.getImage("c:/teste"+(i+1)+".gif");
}

}

/**
 * Metodo chamado qnd a applet se torna visivel
 * Cria a thread e começa
 */
public void start() {
animator = new Thread(this);
animator.start();
 
}

/**
 * metodos chamados na thread qnd ela começa
 * Faz a animação"
 */
public void run() {
// Remember the starting time
long tm = System.currentTimeMillis();
while (Thread.currentThread() == animator) {
    // Display the next frame of animation.
    repaint();

    // Delay depending on how far we are behind.
    try {
	tm += delay;
	Thread.sleep(Math.max(0, tm - System.currentTimeMillis()));
    } catch (InterruptedException e) {
	break;
    }

    // Advance the frame
    frame++;
    
}
}

/**
 * This method is called when the applet is no longer
 * visible. Set the animator variable to null so that the
 * thread will exit before displaying the next frame.
 */
public void stop() {
animator = null;
offImage = null;
offGraphics = null;
}

/**
 * Update a frame of animation.
 */
public void update(Graphics g) {
Dimension d = size();

// Create the offscreen graphics context
if ((offGraphics == null)
 || (d.width != offDimension.width)
 || (d.height != offDimension.height)) {
    offDimension = d;
    offImage = createImage(d.width, d.height);
    offGraphics = offImage.getGraphics();
}

// Erase the previous image
offGraphics.setColor(getBackground());
offGraphics.fillRect(0, 0, d.width, d.height);
offGraphics.setColor(Color.black);

// Paint the frame into the image
paintFrame(offGraphics);

// Paint the image onto the screen
g.drawImage(offImage,0,0, null);
}

/**
 * Paint the previous frame (if any).
 */
public void paint(Graphics g) {
	
	update(g);
}

/**
 * Paint a frame of animation.
 */
public void paintFrame(Graphics g) {
g.drawImage(frames[frame % 10], 0, 0, null);//mudar aki tamanho da imagem impressa
}

public void appletResize(int width,int height) {
	// TODO Auto-generated method stub
	
}

}

6 Respostas

silva.fernandes

Cara… posta os código dentro da Tag Code …

Fica melhor para visualizarmos. …

Assim

Tá vendo como o resultado é bem melhor !!!

Assim vc corre o risco do pessoal nem ler seu codigo inteiro

Falow

T+

silva.fernandes

Cara… posta os código dentro da Tag Code …

Fica melhor para visualizarmos. …

Assim

Tá vendo como o resultado é bem melhor !!!

Assim vc corre o risco do pessoal nem ler seu codigo inteiro

Falow

T+

F

Como faço para que as imagens que este programa gera sejam impressas em uma window? eu tentei fazer criando um novo objeto window mas deu errado.

import java.applet.AppletStub;
import java.awt.*;



public
class ScreenShow extends java.applet.Applet implements Runnable,AppletStub {
int frame;
int delay;
Window janela;

Thread animator;

Dimension offDimension;
Image offImage;
Graphics offGraphics;

Image frames[];

/**
*inicializa parametros a serem usados na thread
*/

public void init() {
appletResize(1024,76;
String str = getParameter("fps");
int fps = (str != null) ? Integer.parseInt(str) : 10;
delay = (fps > 0) ? (1000 / fps) : 100;// delay no fps operador ternário
Toolkit t = Toolkit.getDefaultToolkit();
frames = new Image[33];//lembrar de colocar o array com o tamanho dos arquivos
for (int i = 1 ; i < 33 ; i++) {
frames[i-1] = t.getImage("c:/teste"+(i+1)+".gif");
}

}

/**
* Metodo chamado qnd a applet se torna visivel
* Cria a thread e começa
*/
public void start() {
animator = new Thread(this);
animator.start();

}

/**
* metodos chamados na thread qnd ela começa
* Faz a animação"
*/
public void run() {
// Remember the starting time
long tm = System.currentTimeMillis();
while (Thread.currentThread() == animator) {
// Display the next frame of animation.
repaint();

// Delay depending on how far we are behind.
try {
tm += delay;
Thread.sleep(Math.max(0, tm - System.currentTimeMillis()));
} catch (InterruptedException e) {
break;
}

// Advance the frame
frame++;

}
}

/**
* This method is called when the applet is no longer
* visible. Set the animator variable to null so that the
* thread will exit before displaying the next frame.
*/
public void stop() {
animator = null;
offImage = null;
offGraphics = null;
}

/**
* Update a frame of animation.
*/
public void update(Graphics g) {
Dimension d = size();

// Create the offscreen graphics context
if ((offGraphics == null)
|| (d.width != offDimension.width)
|| (d.height != offDimension.height)) {
offDimension = d;
offImage = createImage(d.width, d.height);
offGraphics = offImage.getGraphics();
}

// Erase the previous image
offGraphics.setColor(getBackground());
offGraphics.fillRect(0, 0, d.width, d.height);
offGraphics.setColor(Color.black);

// Paint the frame into the image
paintFrame(offGraphics);

// Paint the image onto the screen
g.drawImage(offImage,0,0, null);
}

/**
* Paint the previous frame (if any).
*/
public void paint(Graphics g) {

update(g);
}

/**
* Paint a frame of animation.
*/
public void paintFrame(Graphics g) {
g.drawImage(frames[frame % 10], 0, 0, null);//mudar aki tamanho da imagem impressa
}

public void appletResize(int width,int height) {
// TODO Auto-generated method stub

}


}
silva.fernandes

public void init() { appletResize(1024,76;

Falta fechar um parenteses …

T+

rodrigo1

bom ... fiz algumas modificações ... vê se é o que vc tava querendo ...

import javax.swing.JApplet;

public class OpenScreenShow extends JApplet {

	ScreenShow sc = null;
	
	public void init() {
		sc = new ScreenShow(getParameter("fps"));
		sc.setVisible(true);
	}
	
	public void start() {
		sc.start();
	}
	
	public void stop() {
		sc.stop();
	}

}
import java.awt.*;
import javax.swing.JFrame;

public class ScreenShow extends JFrame implements Runnable{
	int frame;

	int delay;

	Thread animator;

	Dimension offDimension;

	Image offImage;

	Graphics offGraphics;

	Image frames[];

	/**
	 * inicializa parametros a serem usados na thread
	 */

	public ScreenShow(String str) {
		setSize(300, 300);
		int fps = (str != null) ? Integer.parseInt(str) : 10;
		delay = (fps > 0) ? (1000 / fps) : 100;// delay no fps operador
												// ternário
		Toolkit t = Toolkit.getDefaultToolkit();
		frames = new Image[33];// lembrar de colocar o array com o tamanho dos
								// arquivos
		for (int i = 1; i < 33; i++) {
			frames[i - 1] = t.getImage("c:/teste" + (i + 1) + ".gif");
		}

	}

	/**
	 * Metodo chamado qnd a applet se torna visivel Cria a thread e começa
	 */
	public void start() {
		animator = new Thread(this);
		animator.start();
	}
	

	/**
	 * metodos chamados na thread qnd ela começa Faz a animação"
	 */
	public void run() {
		// Remember the starting time
		long tm = System.currentTimeMillis();
		while (Thread.currentThread() == animator) {
			// Display the next frame of animation.
			repaint();

			// Delay depending on how far we are behind.
			try {
				tm += delay;
				Thread.sleep(Math.max(0, tm - System.currentTimeMillis()));
			} catch (InterruptedException e) {
				break;
			}

			// Advance the frame
			frame++;

		}
	}

	/**
	 * This method is called when the applet is no longer visible. Set the
	 * animator variable to null so that the thread will exit before displaying
	 * the next frame.
	 */
	public void stop() {
		animator = null;
		offImage = null;
		offGraphics = null;
	}

	/**
	 * Update a frame of animation.
	 */
	public void update(Graphics g) {
		Dimension d = size();

		// Create the offscreen graphics context
		if ((offGraphics == null) || (d.width != offDimension.width)
				|| (d.height != offDimension.height)) {
			offDimension = d;
			offImage = createImage(d.width, d.height);
			offGraphics = offImage.getGraphics();
		}

		// Erase the previous image
		offGraphics.setColor(getBackground());
		offGraphics.fillRect(0, 0, d.width, d.height);
		offGraphics.setColor(Color.black);

		// Paint the frame into the image
		paintFrame(offGraphics);

		// Paint the image onto the screen
		g.drawImage(offImage, 100, 100, null);
		
	}

	/**
	 * Paint the previous frame (if any).
	 */
	public void paint(Graphics g) {
		update(g);
	}

	/**
	 * Paint a frame of animation.
	 */
	public void paintFrame(Graphics g) {
		g.drawImage(frames[frame % 10], 0, 0, null);// mudar aki tamanho da
		// imagem impressa
	}

}

flw...

F

Nossa kra eu nao vi direito ainda, mas testei agora e ta pegando, e tah ate mais rapido do q antes, BRIGADAO kra vlw msm!!! :smiley: :smiley:

bem o lado da janela ta funcionando, agora qnd mudo para algo superior a 10 da um

Exception in thread “Image Fetcher 0” java.lang.OutOfMemoryError: Java heap space

axo q tow com algum vazamento d memoria ow seila, vow da uma estudada nisso, d qlqr forma esse lance da janela me ajudo mto kra

Criado 31 de outubro de 2006
Ultima resposta 6 de nov. de 2006
Respostas 6
Participantes 3