HOME   PRODUCTS   SOLUTIONS   PARTNERS   STORE   COMPANY     
Java Examples
  • Call AWT
    package require java
    

    create an awt frame

    set f [java::new java.awt.Frame]
    $f setTitle "Hello World!"
    

    create an awt textarea, write text, and add to component

    set text [java::new java.awt.TextArea]
    $text setText "Java text example in MyrmecoX."
    $f {add java.awt.Component} $text
    

    set frame position, pack and show

    $f setLocation 256 100; $f pack; $f toFront; $f show
    
  • Java Regression Testing
  • Following example shows how easy to use MyrmecoX to test the Java codes with tcltest.

    package require java
    package require tcltest
    

    Test Java charAt() method. "1.1" is the name, or identifier, of the test.

    tcltest::test 1.1 {
      java.lang.String.charAt() method work?}  { 
    

    test and compare the return result. If the 7th char is not H, the test will return an error result. We can write any test scripts in the test body.

    	set s [::java::new String "I am a Java String"]
    	$s charAt 7 
    } H