Skip to content

Commit fa1c4bb

Browse files
committed
Import files from scalafx sub-project scalafx-hello-world.
1 parent b62cbdb commit fa1c4bb

File tree

6 files changed

+150
-1
lines changed

6 files changed

+150
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ project/plugins/project/
1515
# Scala-IDE specific
1616
.scala_dependencies
1717
.worksheet
18+
19+
/.idea/
20+
/project/project

README.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,52 @@
11
scalafx-hello-world
22
===================
33

4-
Simple example of a ScalaFX application
4+
Simple example of a ScalaFX application using [Simple-Build-Tool](http://www.scala-sbt.org/) (SBT).
5+
6+
Content
7+
-------
8+
9+
src/main/scala/hello/ScalaFXHelloWorld.scala - sample ScalaFX application.
10+
11+
build.sbt - the main SBT configuration file.
12+
project/build.properties - version of SBT to use.
13+
project/plugins.sbt - plugins used for creation of IDEA and Eclipse projects.
14+
15+
16+
17+
How to build and Run
18+
--------------------
19+
20+
1. Install [Java 7 JDK](http://www.oracle.com/technetwork/java/javase/downloads/index.html)
21+
22+
2. Install [SBT](http://www.scala-sbt.org/)
23+
24+
3. Run the example: change o directory containing this example and use SBT to
25+
build and run the example:
26+
27+
%> sbt run
28+
29+
It will download needed dependencies, including Scala and ScalaFX, and run
30+
the example code.
31+
32+
33+
Crete project for IDEA or Eclipse
34+
---------------------------------
35+
36+
If you want to create project that can be used with IntelliJ IDEA, inside
37+
this project directory, at command prompt type:
38+
39+
%> sbt gen-idea
40+
41+
42+
If you want to create project that can be used with Eclipse, inside
43+
this project directory, at command prompt type:
44+
45+
%> sbt eclipse
46+
47+
48+
Additional Information
49+
----------------------
50+
51+
Detailed description of similar example can be found in the blog post
52+
["Getting Started with ScalaFX: Compile and Run"](http://codingonthestaircase.wordpress.com/2013/05/17/getting-started-with-scalafx-compile-and-run-2/).

build.sbt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Name of the project
2+
name := "ScalaFX Hello World"
3+
4+
// Project version
5+
version := "1.0.8"
6+
7+
// Version of Scala used by the project
8+
scalaVersion := "2.10.4"
9+
10+
// Add dependency on ScalaFX library, for use with JavaFX 2.2/Java 7
11+
libraryDependencies += "org.scalafx" %% "scalafx" % "1.0.0-R8"
12+
13+
// Add dependency on ScalaFX library, for use with JavaFX 8/Java 8
14+
// libraryDependencies += "org.scalafx" %% "scalafx" % "8.0.0-M3"
15+
16+
// Add dependency on JavaFX library (only for Java 7)
17+
unmanagedJars in Compile += Attributed.blank(file(scala.util.Properties.javaHome) / "/lib/jfxrt.jar")
18+
19+
// Fork a new JVM for 'run' and 'test:run', to avoid JavaFX double initialization problems
20+
fork := true

project/build.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sbt.version=0.13.5
2+

project/plugin.sbt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
scalacOptions ++= Seq("-unchecked", "-deprecation")
2+
3+
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.5.0")
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) 2011-2013, ScalaFX Project
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
* * Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* * Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
* * Neither the name of the ScalaFX Project nor the
13+
* names of its contributors may be used to endorse or promote products
14+
* derived from this software without specific prior written permission.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
* DISCLAIMED. IN NO EVENT SHALL THE SCALAFX PROJECT OR ITS CONTRIBUTORS BE LIABLE
20+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23+
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
*/
27+
28+
package hello
29+
30+
import scalafx.application.JFXApp
31+
import scalafx.application.JFXApp.PrimaryStage
32+
import scalafx.geometry.Insets
33+
import scalafx.scene.Scene
34+
import scalafx.scene.effect.DropShadow
35+
import scalafx.scene.layout.HBox
36+
import scalafx.scene.paint.Color._
37+
import scalafx.scene.paint.{Stops, LinearGradient}
38+
import scalafx.scene.text.Text
39+
40+
object ScalaFXHelloWorld extends JFXApp {
41+
42+
stage = new PrimaryStage {
43+
title = "ScalaFX Hello World"
44+
scene = new Scene {
45+
fill = BLACK
46+
content = new HBox {
47+
padding = Insets(20)
48+
content = Seq(
49+
new Text {
50+
text = "Hello "
51+
style = "-fx-font-size: 100pt"
52+
fill = new LinearGradient(
53+
endX = 0,
54+
stops = Stops(PALEGREEN, SEAGREEN))
55+
},
56+
new Text {
57+
text = "World!!!"
58+
style = "-fx-font-size: 100pt"
59+
fill = new LinearGradient(
60+
endX = 0,
61+
stops = Stops(CYAN, DODGERBLUE)
62+
)
63+
effect = new DropShadow {
64+
color = DODGERBLUE
65+
radius = 25
66+
spread = 0.25
67+
}
68+
}
69+
)
70+
}
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)