Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Java-Applet-Methode von JavaScript aus

Empfohlene Antworten

Veröffentlicht

Hallo zusammen !

Ich hab ein kleines Problem mit dem Aufruf einer Java-Applet-Methode von JavaScript aus.

Mein Applet-Code sieht in etwa so aus :


public class MyApp extends Applet

{

  public static int giveNumber()

  {

    return 4;

  }

}

Jetzt möchte ich diese Methode von einer HTML-Seite per Javascript aufrufen, in etwa so :

function anyFunction()

{

  var zahl;

  zahl = document.myApplet.giveNumer();

}

Und hier hört der Spaß auf, JavaScript behauptet nämlich das Objekt stellt die gewünschte Methode nicht zur Verfügung. Ich hab jetzt mal diverse Bücher in der Bücherei gewälzt aber auch nichts wirklich vernünftiges dazu gefunden. Wer weiss, wo der Fehler bei mir liegt ? Wenn ich dagegen eine Methode aufrufe, die mir keinen Wert zurückgibt, sondern irgendeinen Wert setzt wie beispielsweise

document.myApplet.setAnything("TEXT")

dann funktioniert das einwandfrei.

Also wo liegt der Fehler ?

Ciao

Christian

Hi,

du musst das static weglassen.

Wenn die Methode so heißt:


  public int giveNumber()

  {    

    return 4;

  }

funktioniert auch. Darum funktioniert deine "set"-Methode auch.

MFG

Danke, hat funktioniert !

Christian

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.