Created
April 8, 2012 05:21
-
-
Save hishidama/2334932 to your computer and use it in GitHub Desktop.
ScalaでJavaFXのWebViewを使うプログラム
This file contains 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
<?xml version="1.0" encoding="UTF-8"?> | |
<?import javafx.scene.layout.*?> | |
<?import javafx.scene.web.*?> | |
<BorderPane xmlns:fx="http://javafx.com/fxml" fx:controller="example.webview.WebViewScalaController2" > | |
<center> | |
<WebView fx:id="web" /> | |
</center> | |
</BorderPane> |
This file contains 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 example.webview | |
import javafx.application.Application | |
import javafx.event.EventHandler | |
import javafx.fxml.FXML | |
import javafx.fxml.FXMLLoader | |
import javafx.fxml.Initializable | |
import javafx.scene.Scene | |
import javafx.scene.Parent | |
import javafx.scene.layout.StackPane | |
import javafx.scene.web.WebView | |
import javafx.scene.web.WebEvent | |
import javafx.stage.Stage | |
import java.net.URL | |
import java.util.ListResourceBundle | |
import java.util.ResourceBundle | |
// https://github.com/halcat0x15a/onedit/blob/master/client/src/main/scala/onedit/client/Application.scala | |
class WebViewScalaSample2 extends Application { | |
override def start(stage: Stage): Unit = { | |
println("start start") | |
println(System.getProperty("javafx.version")); | |
stage.setTitle("sample2") | |
val root: Parent = FXMLLoader.load(getClass.getResource("webview-scala-sample2.fxml"), Resource("http://google.co.jp")) | |
//println(root) | |
//stage.setScene(new Scene(root, 800, 600)) | |
stage.setScene(new Scene(root)) | |
stage.show() | |
println("start end") | |
} | |
override def stop() { | |
println("stop") | |
} | |
} | |
object WebViewScalaSample2 { | |
def main(args: Array[String]): Unit = { | |
Application.launch(classOf[WebViewScalaSample2], args: _*) | |
} | |
} | |
// https://github.com/halcat0x15a/onedit/blob/master/client/src/main/scala/onedit/client/Resource.scala | |
case class Resource(url: String) extends ListResourceBundle { | |
def getContents: Array[Array[Object]] = Array( | |
Array("url", url)) | |
} | |
// https://github.com/halcat0x15a/onedit/blob/master/client/src/main/scala/onedit/client/Root.scala | |
class WebViewScalaController2 extends Initializable { | |
@FXML private var web: WebView = _ | |
val statusChanged = new EventHandler[WebEvent[String]] { | |
def handle(event: WebEvent[String]) { | |
//println(event.getData) | |
println("event=" + event) | |
} | |
} | |
def initialize(location: URL, resources: ResourceBundle) { | |
//println(getClass + " web=" + web) | |
web.getEngine.setOnStatusChanged(statusChanged) | |
val url = resources.getString("url") | |
println("url=" + url) | |
web.getEngine.load(url) | |
//web.getEngine.load("http://google.co.jp") | |
//web.getEngine.load("http://localhost:9000/") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment