why can't load the picture?

N

nick

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();
}
}
 
A

Andrew Thompson

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top