Hello,
lately I've been trying to make an applet that has a background image and a couple of canvas objects on it holding an image each.
I created the class ImageCanvas which extends Canvas adn draws a picture in the canvas.
Next I have to place the canvas on the applet and there I got stuck because I don't know how to control the position of every canvas. How can I put a canvas exactly there where I want it to be?
Here is my code so far:
The applet does work: it displays the background image "crossing.g if" and in the center of the window it place the Canvas, but I want to have some more canvasses and place them where I want them.
Thank you,
Andre
lately I've been trying to make an applet that has a background image and a couple of canvas objects on it holding an image each.
I created the class ImageCanvas which extends Canvas adn draws a picture in the canvas.
Next I have to place the canvas on the applet and there I got stuck because I don't know how to control the position of every canvas. How can I put a canvas exactly there where I want it to be?
Here is my code so far:
Code:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import java.util.*;
import java.net.*;
import java.awt.Graphics;
public class TLCS extends Applet {
Image image;
ImageCanvas canvas1;
Graphics g;
public void init()
{
setSize(774,536);
Toolkit toolkit = Toolkit.getDefaultToolkit();
image = toolkit.getImage("Crossing.gif");
canvas1 = new ImageCanvas();
canvas1.setBounds(50, 80, 39, 99);
//setLocation(50, 100);
add(canvas1);
}
public void paint(Graphics g)
{
g.drawImage(image, 0, 0, this);
}
}
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Font;
import java.awt.Image;
import java.awt.Graphics;
import java.awt.SystemColor;
import java.awt.Toolkit;
public class ImageCanvas extends Canvas {
private Image image;
protected int width = 39;
protected int height = 99;
Image img;
public ImageCanvas() {
//this.image = image;
setSize(39,99);
}
public void paint(Graphics g)
{
Toolkit toolkit = Toolkit.getDefaultToolkit();
img = toolkit.getImage("red3.gif");
g.drawImage(img, 0, 0, this);
}
}
Thank you,
Andre
Comment