How to test Swing from html

87 views
Skip to first unread message

Chang Shin

unread,
Sep 26, 2017, 3:15:45 PM9/26/17
to CheerpJ Developers
Here is what I did:

1. created simple swing java project in Eclipe. The main class is MainApp.java
2. ceated the jar file from maven.
3. copied the jar file into cheerpj_preview folder.
4. ./cheerpjfy.py application.jar and got the application.jar.js
5. Here is the html in the folder:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
            <title>CheerpJ test</title>
            <script src="https://cjrtnc.leaningtech.com/loader.js"></script>
            </head>
    <body>
    </body>
    <script>
        cheerpjInit();
        cheerpjCreateDisplay(800,600);
        cheerpjRunMain("MainApp", "/app/application.jar");
        </script>
</html>

How do I test it from test.html and debug if something is wrong?

Chang Shin

Jeff Martin

unread,
Sep 26, 2017, 3:47:44 PM9/26/17
to Chang Shin, CheerpJ Developers
I use the http-server utility to start a simple web server in my test directory - it starts by simply opening a terminal in that directory and typing “http-server”. I use the flag “-c20” to tell it to have any pages it serves up expire after 20 seconds, so I can easily make changes and re-run.


Then you can access the app at http://127.0.0.1:8080/test.html . If you turn on the JavaScript console for your browser, you can see if there are any errors. Here is a very simple one page Swing app that I wrote that might help you:


jeff


--
You received this message because you are subscribed to the Google Groups "CheerpJ Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cheerpj-develop...@googlegroups.com.
To post to this group, send email to cheerpj-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/cheerpj-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/cheerpj-developers/14a846b8-ac78-4e23-80a2-9f28e24e7489%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chang Shin

unread,
Sep 26, 2017, 4:44:25 PM9/26/17
to CheerpJ Developers
Hi Jeff,

I got the http-server utillity and type "http-server c20" in the folder.

Changs-MacBook-Pro:cheerpj_preview chang$ http-server -c20
Starting up http-server, serving ./
Available on:
  http://127.0.0.1:8080
  http://10.1.23.101:8080
  http://10.1.23.165:8080
Hit CTRL-C to stop the server
[Tue Sep 26 2017 13:36:48 GMT-0700 (PDT)] "GET /test.html" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:55.0) Gecko/20100101 Firefox/55.0"
[Tue Sep 26 2017 13:36:49 GMT-0700 (PDT)] "HEAD /application.jar" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:55.0) Gecko/20100101 Firefox/55.0"
[Tue Sep 26 2017 13:36:50 GMT-0700 (PDT)] "GET /application.jar" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:55.0) Gecko/20100101 Firefox/55.0"

http://127.0.0.1:8080/test.html
The swing application does not show.  I have attached MainApp.java source code.
The files in the folder:

Changs-MacBook-Pro:cheerpj_preview chang$ pwd
/Users/chang/Downloads/cheerpj_preview
Changs-MacBook-Pro:cheerpj_preview chang$ ls -al
total 92184
drwxr-xr-x@  12 chang  staff       408 Sep 26 12:07 .
drwxrwxrwx+ 103 chang  staff      3502 Sep 26 09:17 ..
-rw-r--r--@   1 chang  staff      6148 Sep 26 09:13 .DS_Store
-rw-r--r--@   1 chang  staff      9302 Sep 23 03:23 LICENSE.md
-rw-r--r--    1 chang  staff      3391 Sep 26 10:11 application.jar
-rw-r--r--    1 chang  staff      4689 Sep 26 12:00 application.jar.js
drwxr-xr-x@   5 chang  staff       170 Sep 23 03:23 bin
drwxr-xr-x@   5 chang  staff       170 Sep 26 09:13 cheerp_bl
-rwxr-xr-x@   1 chang  staff     16000 Sep 22 07:47 cheerpjfy.py
-rw-r--r--@   1 chang  staff  13403725 Sep 22 07:47 rt.jar
-rw-r--r--    1 chang  staff  33735904 Sep 26 09:19 rt.jar.js
-rwxrwxrwx@   1 chang  staff       395 Sep 26 13:36 test.html
Changs-MacBook-Pro:cheerpj_preview chang$

Chang Shin
To unsubscribe from this group and stop receiving emails from it, send an email to cheerpj-developers+unsub...@googlegroups.com.
To post to this group, send email to cheerpj-developers@googlegroups.com.
MainApp.java

Jeff Martin

unread,
Sep 26, 2017, 4:47:28 PM9/26/17
to Chang Shin, CheerpJ Developers
What do you see in the JavaScript console of the browser?

jeff


To unsubscribe from this group and stop receiving emails from it, send an email to cheerpj-develop...@googlegroups.com.
To post to this group, send email to cheerpj-d...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
<MainApp.java>

Jeff Martin

unread,
Sep 26, 2017, 6:04:15 PM9/26/17
to Chang Shin, CheerpJ Developers
Ah, you need to specify the package in the first arg to cheerpjRunMain():

cheerpjRunMain(“card_reader.card_reader_swing.MainApp”, “application.jar”);

jeff


On Sep 26, 2017, at 4:56 PM, Chang Shin <changs...@gmail.com> wrote:

I have attached the main java code. The project has package.

Chang Shin

On Tue, Sep 26, 2017 at 2:47 PM, Jeff Martin <je...@reportmill.com> wrote:
Maybe try changing the second arg of cheerpjRunMain() from “/app/application.jar” to “application.jar”. Although, it does seem like application.jar is being fetched - judging from the output of http-server, so probably that’s okay.

Also, does your MainApp class have a package? I didn’t get the MainApp.java file - must have gotten stripped. For my first test, my main method looked something like this:

public static void main(String args[])
{
    JFrame frame = new JFrame(“Hello World”);
    frame.setContentPane(new JLabel(“Hello World”));
    frame.setBounds(200,200,200,200);
    frame.setVisible(true);
}

jeff



On Sep 26, 2017, at 4:04 PM, Chang Shin <changs...@gmail.com> wrote:

Hi Jeff,

I posted it two times. The two posts were not updated on the google frum . So I replied it again.

Reporting error: Unhandled exception N4java4lang20NullPointerException/_m4_08Shutdown5halt0EIEV@https://cjrtnc.leaningtech.com/runtime/rt.jar.java.lang.js:2195:1
_m4V08Shutdown4haltEIEV@https://cjrtnc.leaningtech.com/runtime/rt.jar.java.lang.js:2299:2530
_m4V08Shutdown4exitEIEV@https://cjrtnc.leaningtech.com/runtime/rt.jar.java.lang.js:2299:4509
_m4F07Runtime4exitEIEV@https://cjrtnc.leaningtech.com/runtime/rt.jar.js:4355:508
_o4VZystem4exitEIEV@https://cjrtnc.leaningtech.com/runtime/rt.jar.js:5138:8690
anonymous@https://cjrtnc.leaningtech.com/loader.js line 124 > Function:3:338
runContinuationStack@https://cjrtnc.leaningtech.com/loader.js:287:8
cheerpjSchedule@https://cjrtnc.leaningtech.com/loader.js:714:4
classLoadComplete@https://cjrtnc.leaningtech.com/loader.js:177:3
  loader.js:2162:2
Unhandled exception N4java4lang20NullPointerException/_m4_08Shutdown5halt0EIEV@https://cjrtnc.leaningtech.com/runtime/rt.jar.java.lang.js:2195:1
_m4V08Shutdown4haltEIEV@https://cjrtnc.leaningtech.com/runtime/rt.jar.java.lang.js:2299:2530
_m4V08Shutdown4exitEIEV@https://cjrtnc.leaningtech.com/runtime/rt.jar.java.lang.js:2299:4509
_m4F07Runtime4exitEIEV@https://cjrtnc.leaningtech.com/runtime/rt.jar.js:4355:508
_o4VZystem4exitEIEV@https://cjrtnc.leaningtech.com/runtime/rt.jar.js:5138:8690
anonymous@https://cjrtnc.leaningtech.com/loader.js line 124 > Function:3:338
runContinuationStack@https://cjrtnc.leaningtech.com/loader.js:287:8
cheerpjSchedule@https://cjrtnc.leaningtech.com/loader.js:714:4
classLoadComplete@https://cjrtnc.leaningtech.com/loader.js:177:3
  loader.js:1607:3
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://docs.google.com/forms/d/e/1FAIpQLScErDRKZvSy1JAdiRSZfAsjf711VWdSdkczuSYHfIHQbtyFXA/formResponse. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).  (unknown)
CheerpJ is initializing  loader.js:2109:3
Error: Could not find or load main class MainApp  cheerpOS.js:797:3

  cheerpOS.js:797:3

Chang Shin
       

To unsubscribe from this group and stop receiving emails from it, send an email to cheerpj-developers+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "CheerpJ Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cheerpj-developers+unsubscribe@googlegroups.com.

To post to this group, send email to cheerpj-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/cheerpj-developers.




<MainApp.java>

Jeff Martin

unread,
Sep 26, 2017, 8:47:32 PM9/26/17
to Chang Shin, CheerpJ Developers
I don’t know much about the programatic interface to USB from Java, but I imagine this area is going to be a challenge, given the security constraints of the JavaScript sandbox. I see there’s an emerging WebUSB protocol - so eventually this should be possible, but I imagine it will take a bit of runtime work and might only be possible in certain browsers.

jeff

On Sep 26, 2017, at 6:40 PM, Chang Shin <changs...@gmail.com> wrote:

Hi Jeff,

I created the Swing with card reader and tested it on Mac.
The jar file running reconized the USB card reader. However Cheerjp html does not recognize the usb card reader.
I have attached three files ( one the swing code andscreenshots)

Chang Shin<Screen Shot 2017-09-26 at 4.34.25 PM.png><Screen Shot 2017-09-26 at 4.34.59 PM.png>
<MainApp.java>

kartik sirigeri

unread,
Mar 8, 2018, 4:34:02 AM3/8/18
to CheerpJ Developers
Hi,

I am also getting this error, 'Error: Could not find or load main class'
I have mentioned the fully qalified main class name in cheerpjRunMain().
Any suggestion?

I am using the latest binaries of cheerpj (beta 3).

-Kartik
}

jeff



To unsubscribe from this group and stop receiving emails from it, send an email to cheerpj-developers+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "CheerpJ Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cheerpj-developers+unsub...@googlegroups.com.




<MainApp.java>

Reply all
Reply to author
Forward
0 new messages