Habe ein Problem! und zwar wenn ich auf das Canvas klicke soll das bild erscheinen!! es erscheint aber im moment so dass es bei nem zweiten klick erst erscheind! ich finde den fehler nicht!!
Code:
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Panel;
import java.awt.PopupMenu;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.ImageObserver;
import java.net.MalformedURLException;
import java.net.URL;
import com.sun.media.sound.Toolkit;
public class memory extends Frame{
Image img;
Image img2;
Canvas cv2;
Canvas cv;
public memory ()throws MalformedURLException{
setLayout(new FlowLayout());
cv= new Canvas();
cv.setSize(200,200);
cv.setBackground(Color.RED);
cv2= new Canvas();
cv2.setSize(200,200);
cv2.setBackground(Color.BLACK);
add(cv);
add(cv2);
cv.addMouseListener(new java.awt.event.MouseAdapter(){
public void mouseClicked(java.awt.event.MouseEvent e){
memory.this.setCursor(new Cursor(Cursor.HAND_CURSOR));
paint();
}
});
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
})
;
}
public void paint()
{
Graphics g;
g=cv.getGraphics();
img = getToolkit().getImage("catf.gif");
g.drawImage(img,4,4,this);
}
public static void main(String[] args) throws MalformedURLException {
memory d=new memory();
d.setSize(500,500);
d.show();
}
}