Back ground Image

Hi.

I磎 trying to create a Image to use it as a buffer.

createImage(width, height) work ok in JApplet but in a JFrame not.

a use this alternative code but i can`t do it work well

buffer = this.getGraphicsConfiguration().createCompatibleImage(Const.w,Const.h,Transparency.OPAQUE);

this is the paint:

public void paint(Graphics g)

{

/**Parte del doble buffer*/

Graphics screengc = null;

screengc = g;

g = buffer.getGraphics();

/*Inicio de la parte dibujable**/

MensajePrueba.showMessage(g);

/**intocable: parte del doble buffer**/

screengc.drawImage(buffer,0,0,null);

}

an this is the of ShowMessage:

public void showMessage(Graphics g)

{

/*Demasiado Joda fue generar todo el fondo del mensaje*/

Rectangle2D tamano,tamano1,tamano2;

if (Fondo != null)

{

Graphics2D g1=(Graphics2D)Fondo.getGraphics();

g1.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

Font f = new Font("Arial",Font.BOLD,12);

if (numLine == 1)

{

tamano = f.getStringBounds(text,g1.getFontRenderContext());

AdjustSize(posX,posY,(int)tamano.getWidth(),(int)tamano.getHeight());

}

if (numLine == 2)

{

tamano = f.getStringBounds(text,g1.getFontRenderContext());

tamano1 = f.getStringBounds(text1,g1.getFontRenderContext());

if (tamano.getWidth() > tamano1.getWidth())

{

AdjustSize(posX,posY,(int)tamano.getWidth(),(int)tamano.getHeight());

}

else

{

AdjustSize(posX,posY,(int)tamano1.getWidth(),(int)tamano1.getHeight());

}

}

if (numLine == 3)

{

tamano = f.getStringBounds(text,g1.getFontRenderContext());

tamano1 = f.getStringBounds(text1,g1.getFontRenderContext());

tamano2 = f.getStringBounds(text2,g1.getFontRenderContext());

if ((tamano.getWidth() > tamano1.getWidth()) && (tamano.getWidth() > tamano2.getWidth()))

{

AdjustSize(posX,posY,(int)tamano.getWidth(),(int)tamano.getHeight());

}

else

{

if (tamano1.getWidth() > tamano2.getWidth())

{

AdjustSize(posX,posY,(int)tamano1.getWidth(),(int)tamano1.getHeight());

}

else

{

AdjustSize(posX,posY,(int)tamano2.getWidth(),(int)tamano2.getHeight());

}

}

}

g1.setPaint(frontColor);

g1.setStroke(stroke);

g1.fill(new RoundRectangle2D.Double(0,0,width,height, 10, 10));

g1.setPaint(Color.black);

g1.draw(new RoundRectangle2D.Double(0,0,width,height, 10, 10));

g1.setPaint(backColor);

g1.setStroke(stroke1);

g1.fill(new Rectangle2D.Double(5,5,width-10,height-10));

g1.setPaint(Color.black);

g1.draw(new Rectangle2D.Double(5,5,width-10,height-10));

/*Voy a a馻dir el texto, luego pienso como hago las multiples lineas*/

g1.setFont(f);

g1.setPaint(Color.white);

if (numLine == 1)

{

g1.drawString(text,10,20);

}

if (numLine == 2)

{

g1.drawString(text,10,20);

g1.drawString(text1,10,35);

}

if (numLine == 3)

{

g1.drawString(text,10,20);

g1.drawString(text1,10,35);

g1.drawString(text2,10,50);

}

/*Pinta todo lo dibujado al final : NO TOCAR*/

g.drawImage(Fondo,posX,posY,width,height,null);

}

}

i磎 trying to make an RPG.

[3473 byte] By [Kalindorea] at [2007-9-29 20:00:10]
# 1

You can create a buffer like this:

import java.awt.*;

import javax.swing.*;

public class Test extends JFrame {

private Image buffer;

public static void main(String[] args) {

(new Test()).show();

}

public Test() {

super();

setSize(300,200);

setDefaultCloseOperation(EXIT_ON_CLOSE);

}

public void paint(Graphics g) {

if (buffer == null) buffer = createImage(300,200);

showMessage(buffer.getGraphics());

g.drawImage(buffer,0,0,this);

}

public void showMessage(Graphics g) {

g.setColor(Color.BLUE);

g.fillRect(0,0,50,50);

}

}

fcedrica at 2007-7-16 0:14:49 > top of Java-index,Other Topics,Java Game Development...