Created
June 8, 2014 14:44
-
-
Save tenntenn/5054b4d88dcd7bfad4f8 to your computer and use it in GitHub Desktop.
Go言語でJavaFXを動かしてみた ref: http://qiita.com/tenntenn/items/e61822b265bc2b8f6c88
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ go get github.com/gopherjs/gopherjs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
func main() { | |
println("hello, GopherJS") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ go build -o /dev/null && gopherjs build hello.go |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ node hello.js | |
hello, GopherJS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/gopherjs/gopherjs/js" | |
) | |
func main() { | |
Object := js.Global.Get("Object") | |
obj := Object.New() | |
obj.Set("name", "hoge") | |
println(obj.Get("name")) | |
JSON := js.Global.Get("JSON") | |
println(JSON.Call("stringify", obj)) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
go build -o /dev/null sample1.go && gopherjs build sample1.go && node sample1.js | |
hoge | |
{"name":"hoge"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/gopherjs/gopherjs/js" | |
) | |
var java = js.Global.Get("Java") | |
func main() { | |
js.Global.Set("start", start) | |
} | |
func start(stage js.Object) { | |
stage.Set("title", "Hello, GopherJS") | |
WebView := java.Call("type", "javafx.scene.web.WebView") | |
webview := WebView.New() | |
webview.Call("getEngine").Call("load", "http://gopherjs.github.io/playground") | |
Scene := java.Call("type", "javafx.scene.Scene") | |
scene := Scene.New(webview, 600, 600) | |
stage.Call("setScene", scene) | |
stage.Call("show") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ go build -o /dev/null sample2.go && gopherjs build sample2.go && jjs -fx sample2.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/gopherjs/gopherjs/js" | |
) | |
var java = js.Global.Get("Java") | |
var ( | |
Group = java.Call("type", "javafx.scene.Group") | |
Scene = java.Call("type", "javafx.scene.Scene") | |
ObjModelImporter = java.Call("type", "com.interactivemesh.jfx.importer.obj.ObjModelImporter") | |
DrawMode = java.Call("type", "javafx.scene.shape.DrawMode") | |
PerspectiveCamera = java.Call("type", "javafx.scene.PerspectiveCamera") | |
Point3D = java.Call("type", "javafx.geometry.Point3D") | |
) | |
func start(stage js.Object) { | |
root := Group.New() | |
objImporter := ObjModelImporter.New() | |
objImporter.Call("read", "gopher.obj") | |
objMesh := objImporter.Call("getImport") | |
objImporter.Call("close") | |
for i := 0; i < objMesh.Length(); i++ { | |
root.Call("getChildren").Call("addAll", objMesh.Index(i)) | |
objMesh.Index(i).Call("drawModeProperty").Call("set", DrawMode.Get("FILL")) | |
} | |
root.Call("setRotationAxis", Point3D.New(0.0, 1.0, 0.0)) | |
root.Call("setRotate", 210.0) | |
scene := Scene.New(root, 600, 600) | |
camera := PerspectiveCamera.New(true) | |
scene.Call("setCamera", camera) | |
camera.Call("setTranslateZ", -10.0) | |
stage.Call("setScene", scene) | |
stage.Set("title", "Hello, Gopher3D") | |
stage.Call("show") | |
} | |
func main() { | |
js.Global.Set("start", start) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ go build -o /dev/null gopher3d.go && gopherjs build gopher3d.go && jjs -fx gopher3d.js -cp jimObjModelImporterJFX.jar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment