Ola pessoal !!
Tudo beleza !?
Estou desenvovendo um jogo com figuras geométricas, e estou
com algumas dificuldades em relação as figuras:
E possivel pintar e repintar sobre
um bufferedimage?
JANELA
package jog;
import javax.swing.*;
import java.awt.*;
import java.awt.image.*;
public class Janela {
public static void main(String[] args) {
JFrame frm = new JFrame("Teste Imagem");
JPanel pan = new JPanel();
JLabel lbl = new JLabel( Figuras.Circulo() );
pan.add( lbl );
frm.getContentPane().add( pan );
frm.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frm.pack();
frm.show();
}
}
FIGURAS
package jog;
import javax.swing.*;
import java.awt.*;
import java.awt.image.*;
public class Figuras {
static BufferedImage buffer = new BufferedImage( 350, 350, BufferedImage.TRANSLUCENT );
// CIRCULO //
static ImageIcon Circulo() {
Graphics2D g = buffer.createGraphics();
g.setColor( Color.RED);
g.fillOval( 0, 0, 50, 50 );
return new ImageIcon( buffer );
}
// QUADRADO //
public static ImageIcon Quadrado() {
Graphics2D g = buffer.createGraphics();
g.setColor( Color.YELLOW );
g.fillRect( 0, 0, 50, 50 );
return new ImageIcon( buffer );
}
}