diff --git a/README.md b/README.md index 4893418..690d99c 100644 --- a/README.md +++ b/README.md @@ -6,28 +6,28 @@ java2js can translate simple Java programs to JavaScript and runs them using a J ## Java classes included in the java2js JDK -| java.io | | | -| ------- | ----------- | ----------- | -| File | InputStream | PrintStream | +| `java.io` | | | +| :-------- | ----------- | ----------- | +| File | InputStream | PrintStream | -| java.lang | | | -| --------- | ------------- | --------- | -| Boolean | Byte | Character | -| Double | Exception | Float | -| Integer | Long | Short | -| String | StringBuilder | System | -| Thread | Throwable | | +| `java.lang` | | | +| :---------- | ------------- | --------- | +| Boolean | Byte | Character | +| Double | Exception | Float | +| Integer | Long | Short | +| String | StringBuilder | System | +| Thread | Throwable | | -| java.security | | | -| ------------- | --- | --- | -| MessageDigest | | | +| `java.security` | +| :-------------- | +| MessageDigest | -| java.time | | | -| --------- | --- | --- | -| Instant | | | +| `java.time` | +| :---------- | +| Instant | -| java.util | | | -| ------------------ | ---------------------- | ----------- | +| `java.util` | | | +| :----------------- | ---------------------- | ----------- | | AbstractCollection | AbstractList | AbstractMap | | AbstractSet | ArrayList | Arrays | | Collections | Formatter | HashMap | @@ -48,6 +48,7 @@ The java2js transpiler supports: - two dimensional arrays - lambda arrow functions - triple quote strings +- try/catch blocks ## API @@ -55,7 +56,7 @@ The java2js transpiler supports: This function imports the standard java.lang classes into the global scope. You must use it before translating or running files. -- root: (optional) path to the JS JDK folder, by default it is `./jdk` (the java2js JS JDK), for online use on codepen or similar code sharing sites you can use this link as the root path: 'https://unpkg.com/java2js/jdk' +- root: (optional) path to the JS JDK folder, by default it is `./jdk` (the java2js JS JDK), for online use on codepen or similar code sharing sites you can use this link as the root path: 'https://quinton-ashley.github.io/java2js/jdk' ### await jdk.transpile(javaFile) diff --git a/ide.js b/ide.js index b3c07bd..b15066a 100644 --- a/ide.js +++ b/ide.js @@ -2,11 +2,15 @@ jdk.log = document.getElementById('javaConsole'); await jdk.init('./jdk'); - let file0 = document.getElementById('javaFile'); - file0.onchange = async () => { + async function run() { jdk.log.value = ''; let translation = await jdk.transpile(file0.value); console.log(translation); jdk.run(); - }; + } + + let file0 = document.getElementById('javaFile'); + file0.onchange = run; + + run(); })(); diff --git a/index.html b/index.html index ac24a03..5ab2b21 100755 --- a/index.html +++ b/index.html @@ -55,7 +55,14 @@ autocorrect="off" autocapitalize="off" placeholder="Create a Java class with a main method here..." - > + > +public class HelloWorld { + public static void main(String[] args){ + System.out.println("hello world!"); + } +} +
j
diff --git a/jdk.js b/jdk.js index 48f9bd2..9d2d381 100755 --- a/jdk.js +++ b/jdk.js @@ -171,7 +171,7 @@ let imports = file.slice(0, classLine); imports = imports.match(/(?<=^import )[^;]*/gm) || []; - let className = file.slice(classLine + 13, file.indexOf(' {', classLine + 13)); + let className = file.slice(classLine + 13, file.indexOf('{', classLine + 13)); // workaround hack for converting triple quotes to a normal string file = file.replace(/"""([^"]*)"""/gm, (match, p1) => { diff --git a/jdk/java/util/Scanner.js b/jdk/java/util/Scanner.js index 2aa5173..73fc37e 100755 --- a/jdk/java/util/Scanner.js +++ b/jdk/java/util/Scanner.js @@ -32,7 +32,7 @@ jdk.imports['java.util.Scanner'].load = async () => { return await this.next(/.*\n/); } async next(pattern) { - while (this._loading || !this.hasNext(pattern)) { + while (this._loading || !(await this.hasNext(pattern))) { await new Promise((done) => setTimeout(() => done(), 100)); } let buf = this.in.stream.slice(this.in.mark); diff --git a/package.json b/package.json index d5cdb28..bc23b27 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { "name": "java2js", - "version": "1.2.4", + "version": "1.2.5", "description": "Converts Java to JavaScript and runs it with a JS JDK", "main": "jdk.js", "scripts": { - "start": "open demo.html", - "test": "open demo.html", + "start": "open index.html", + "test": "open index.html", "v": "npm version patch --force", "V": "npm version minor --force", "version": "git add -A",