Question:

What is wrong with this java program?

by  |  earlier

0 LIKES UnLike

import java.applet.*;

import java.awt.*;

import java.util.*;

public class test extends Applet{

Image i;

public void init()

{

repaint();

}

public void paint(Graphics g) {

i = getImage(getCodeBase(),"Picture 3.png");

g.drawImage(i,0,0,this);

}

}

// to me this program should run fine

 Tags:

   Report

1 ANSWERS


  1. Applets aren't just another Panel.  They are meant to be used in a "browser" environment, i.e. they are meant to execute in a browser or applet-running Java virtual machine, not just any standard JVM.  You are calling the getCodeBase() method, which relies on interaction with the system to retrieve that URL data from the host application (browser), which, in your case, doesn't exist.

    If you choose to instantiate an applet directly and use it within a non-applet environment, you cannot make use of methods that rely on interfacing with the applet environment, namely the getCodeBase(), getDocumentBase(), getParameter(), and getAppletContext() methods.

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.