简体   繁体   中英

How to pass URL of folder to codebase in applet?

I have apple.html in C:/Java1 and apple1.class in C:/Java , I have given path of class file in applet codebase but cannot initialize the applet.

Here is code

apple.html in C:/Java1

<applet code="apple.class" codebase="file:/C:/Java/" alt="Applet not printed value" width="200" height="200">
</applet>

apple1.class in c:/Java

import java.awt.*;
import java.awt.*;
import java.awt.Graphics;
import java.applet.*; 
import java.lang.*;

public class apple1 extends Applet  
{
       public void paint(Graphics g) 
       {
           g.drawString("hi...I am", 50, 50); 
       } 
}

when I run code using

appletviewer applet.html

It gives applet not initialized.

The codebase is wrong use like

codebase="file:///C:/Java/"

EDIT:

The class name allso need to change

code="apple.class"

but the class name in java file is apple1 .

also the code in the paint method doesn't call super.paint() , and don't ask why nothing appears in the browser. But you didn't use the browser yet, so it may be in the future.

Try codebase="../Java" . This will give a path relative to the location of the HTML page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM