You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constClassName=awaitlib.ClassName;// Access your Java class
79
-
awaitClassName.javaMethodName();// Call a Java static method
78
+
constClassName=awaitlib.ClassName; // Access your Java class
79
+
awaitClassName.javaMethodName(); // Call a Java static method
80
80
}
81
81
```
82
82
@@ -86,7 +86,7 @@ This functionality is useful when you need to call back into the Java class in r
86
86
87
87
To use the native method in CheerpJ, pass the function to the [`cheerpjInit`] function as a property of the [`natives`] option. There are two ways in which you can do this.
88
88
89
-
1.**In the function definition directly**:
89
+
1.**In the function definition directly**
90
90
91
91
```js
92
92
awaitcheerpjInit({
@@ -98,7 +98,7 @@ await cheerpjInit({
98
98
});
99
99
```
100
100
101
-
2.**Or just the function name if it was defined earlier**:
101
+
2.**Or just the function name if it was defined earlier**
@@ -121,22 +121,22 @@ Here’s a full example that demonstrates the native method setup in Java and it
121
121
```java title="Example.java"
122
122
publicclassExample {
123
123
publicstaticvoidmain(String[] args) {
124
-
nativeAlert("Hello, world!");
124
+
Alert("Hello, world!");
125
125
}
126
126
127
-
publicstaticnativevoidnativeAlert(Stringmessage);
127
+
publicstaticnativevoidAlert(Stringmessage);
128
128
}
129
129
```
130
130
131
131
2. Implement the native method by creating an `async` function in JavaScript that follows the naming convention `Java_<fully-qualified-class-name>_<method-name>`.
132
132
133
133
```js title="index.html"
134
-
asyncfunctionJava_Example_nativeAlert(lib, str) {
134
+
asyncfunctionJava_Example_Alert(lib, str) {
135
135
window.alert(str);
136
136
}
137
137
```
138
138
139
-
Here, we provide an implementation for the `nativeAlert` method in the `Example` class, by creating a function named `Java_Example_nativeAlert`. The function displays an alert dialog with the message using `window.alert`.
139
+
Here, we provide an implementation for the `Alert` method in the `Example` class, by creating a function named `Java_Example_Alert`. The function displays an alert dialog with the message using `window.alert`.
140
140
141
141
3. Initialize CheerpJ with the `natives` option and pass the native method implementation to [`cheerpjInit`]:
142
142
@@ -148,13 +148,15 @@ Here, we provide an implementation for the `nativeAlert` method in the `Example`
0 commit comments