Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't Call Java Function

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Hello,

I'm having a mare calling a Java function.

Here is my HTML and JS call...
Code:
<applet code="[URL unfurl="true"]https://www.mydomain/make_pc_beep.class"[/URL] width="0" height="0" name="beepPC" mayscript></applet>

Code:
document.beepPC.beep_pc();
i've also tried
Code:
document.applets("beepPC").beep_pc();

all I get is
object doesn't support this property or method.

any ideas whats wrong?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Try giving your applet an ID:

Code:
<applet code="[URL unfurl="true"]https://www.mydomain/make_pc_beep.class"[/URL] width="0" height="0" [!]id[/!]="beepPC" mayscript></applet>

and using document.getElementById to target it.

Failing that, ensure that your applet has a "beep-pc" method that is public (I think... I'm no Java developer).

Hope this helps,
Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
same thing using ID! , I'm no Java developer either, though it is my Applet, here is the code
Code:
import java.awt.*;
import java.applet.*;

public class make_pc_beep {
    
        public static void main(String args[]){
            System.out.print("\007"); 
            System.out.flush();
        }            
    
        public static void beep_pc() {
            System.out.print("\007"); 
            System.out.flush();
        }   
    
}

I can compile it with javac.exe no problem and when run with java.exe it works fine.

I just cannot get JS to run it from a webpage. I don't know if this is a Java issue or JS, but i have posterd in the Java forum, but i'm not getting errors with Java only JS.

Something is a miss and I can't work it out, any other ideas?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
A quick search on Google reveals you probably need to extend your class fromt he Applet class, so try this:

Code:
public class make_pc_beep [!]extends Applet[/!] {

Hope this helps,
Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
That hasn't helped :-( , why is it so hard to make the PC speaker sound?




"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
lol - I'd already tried the jguru one, which is where I got the idea to roll my own when i couldn't get it to work.

You'll also notice that the last post on that code was someone having dificulty with exactly the same error "doesn't support that property or method" , so I've tried the example on jsdetails, but again get the same error.

So I checked the Java Console and the error showing is

yet the file does exist! I even thought it might be a server config issue, so i've added the .class to IIS Mime Types , as it wasn't there , but it hasn't helped.

any other suggestions?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
I for got to add the caused by part of the error msg
Caused by: java.io.IOException: open HTTP connection failed.
at sun.applet.AppletClassLoader.getBytes(Unknown Source)
at sun.applet.AppletClassLoader.access$100(Unknown Source)
at sun.applet.AppletClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Also, make sure the applet has fully downloaded before trying to call the method - i.e. want for an onload event first, for example, before trying to call the beep method.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
ok from more googling I found the tag declaration was wrong, it should be...
Code:
<applet code="make_pc_beep.class" [b]codebase="[URL unfurl="true"]https://www.mydomain/"[/URL][/b] width="0" height="0" id="beepPC" mayscript></applet>

Now I don't get any error, nor does JS error, the problem is I don't hear a beep when the JS function is called via a button , that in turn calls the method of the Java class.

So no errors, but also no sound? , so now what?

how do I tell if the class has actually loaded? and why is the method not beeping the PC speaker?


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top