why can't load the picture?  
Author Message
nick





PostPosted: 2004-11-25 5:00:00 Top

java-programmer, why can't load the picture?
can't load the picture
why?
thanks!

public class draw {
Frame frame;
Image bg;
Image buffer;
Graphics g;
public draw() {

frame = new Frame("hello");
frame.setSize(500, 500);
frame.show();
bg = Toolkit.getDefaultToolkit().getImage("cdog1.gif");
buffer = frame.createImage(400, 400);
g = buffer.getGraphics();
g.drawImage(bg, 0, 0, frame);
frame.getGraphics().drawImage(buffer, 0, 0, frame);
}

public static void main(String args[]) {
new draw();
}
}


 
Andrew Thompson





PostPosted: 2004-11-25 5:05:00 Top

java-programmer >> why can't load the picture? On Thu, 25 Nov 2004 04:59:50 +0800, nick wrote:

> public class draw {

Class names begin with a capital letter

public class Draw {

> Frame frame;
> Image bg;
> Image buffer;
> Graphics g;
> public draw() {
>
> frame = new Frame("hello");
> frame.setSize(500, 500);
// show was deprecated in 1.5, use setVisible(true) instead
frame.setViisible(true);
> frame.show();
> bg = Toolkit.getDefaultToolkit().getImage("cdog1.gif");

// this is a bad way to do things..
// do it in steps..

File f = new File(".", "cdog1.gif");
System.out.println("File: " + f + " exists: " + f.exists())
if ( f.exists() ) {
bg = Toolkit.getDefaultToolkit().getImage(f.toURL());
...
// add a MediaTracker here.. see the GUI FAQ[1] for further details
}

[1] <http://www.cs.uu.nl/wais/html/na-dir/computer-lang/java/gui/faq.html>

HTH

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane