Como desenhar em cima de uma figura?

1 resposta
O
Eu estou querendo desenhar em cima de uma figura e não estou 

 conseguindo.  Peguei um exemplo num livro na net mas ele não está 

funcionando alguem  poderia me ajudar??

o fonte é esse:

import java.awt.<em>;

import java.awt.event.</em>;

import java.awt.image.<em>;

import <a href="http://java.io">java.io</a>.</em>;

import com.sun.image.codec.jpeg.*;
public class ImageDuplicity extends Component {

public static void main(String[] args) {

ApplicationFrame f = new ApplicationFrame(ImageDuplicity v1.0);

f.setLayout(new BorderLayout());

Component c = new ImageDuplicity();

f.add(c, BorderLayout.CENTER);

f.setSize(200, 250);

f.center();

f.setVisible(true);

}

private BufferedImage mImage;

public void paint(Graphics g) {

Graphics2D g2 = (Graphics2D)g;

// If the offscreen image is not defined, create it.

if (mImage == null) createOffscreenImage();

// Render the offscreen image.

g2.drawImage(mImage, 0, 0, this);

}

private void createOffscreenImage() {

// Create a BufferedImage the same size as this component.

Dimension d = getSize();

int w = d.width, h = d.height;

mImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);

// Obtain the Graphics2D for the offscreen image.

Graphics2D g2 = mImage.createGraphics();

g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,

RenderingHints.VALUE_ANTIALIAS_ON);

// Load an image from a file.

//Java 2D Graphics

try {

String filename = Raphael.jpg;

InputStream in = getClass().getResourceAsStream(filename);

JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(in);

BufferedImage image = decoder.decodeAsBufferedImage();

in.close();

// Draw the loaded image on the offscreen image.

g2.drawImage(image, 0, 0, w, h, null);

}

catch (Exception e) { System.out.print(e); }

// Draw some concentric ellipses.

g2.setStroke(new BasicStroke(2));

Color[] colors = { Color.red, Color.blue, Color.green };

for (int i = -32; i < 40; i += 8 ) {

g2.setPaint(colors[Math.abs(i) % 3]);

g2.drawOval(i, i, w - i * 2, h - i * 2);

}

}

}

e o erro que acontece na compilação é esse:

cannot resolve symbol
ApplicationFrame f = new ApplicationFrame(“ImageDuplicity v1.0”);
na linha 9.

Agradeço desde já.

1 Resposta

israelwm

Bom obviamente que ele naum está achando a classe

está tudo certo no import?

<blockquote>import java.awt.<em>;

import java.awt.event.</em>;

import java.awt.image.<em>;

import <a href="http://java.io">java.io</a>.</em>;

import com.sun.image.codec.jpeg.*; </blockquote>

Essa classe ApplicationFrame, vc sabe daonde q ela é?

Criado 13 de abril de 2005
Ultima resposta 13 de abr. de 2005
Respostas 1
Participantes 2