MAVEN开发javaFX 2.0

Install the Standalone JavaFX SDK

The standalone JavaFX SDK should only be installed if you are using a JDK older than 7u2.

To install the JavaFX SDK: 

  1. Verify your system requirements.

  2. Go to the JavaFX Downloads page.

  3. Find the JavaFX SDK downloads, click the link for your operating system, and follow the prompts to save the executable file.

  4. Run the .exe file and complete the steps in the installation wizard.

    The default installation directory for the SDK is C:\Program Files\Oracle\JavaFX 2.0 SDK. See JavaFX Samples for the directories and content.

    The default installation directory for the Runtime is C:\Program Files\Oracle\JavaFX 2.0 Runtime.

转载: http://docs.oracle.com/javafx/2.0/installation/jfxpub-installation.htm#CHDIAEJA


Maven using JavaFX 2.0 SDK  simple steps

  1. Go to JavaFX 2.0 SDK\rt\lib in your shell (command prompt)

  2. Execute mvn install:install-file -Dfile=jfxrt.jar -DgroupId=com.oracle -DartifactId=javafx -Dpackaging=jar -Dversion=2.0

  3. Copy bin folder from your JavaFX 2.0 SDK\rt\ directory to your .m2\repository\com\oracle\javafx directory

       4.<dependency>
   <groupId>com.oracle</groupId> <artifactId>javafx</artifactId> <version>2.0</version> <scope>compile</scope> </dependency>


转载:http://stackoverflow.com/questions/7105660/javafx-2-0-netbeans-maven


Example

package dustin.examples;

import static java.lang.System.err;
import java.lang.reflect.Field;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.RectangleBuilder;
import javafx.stage.Stage;

/**
* Simple JavaFX 2 application that prints out values of standardly available
* Color fields.
*
* @author Dustin
*/
public class JavaFxColorDemo extends Application
{
/** Width of label for colorn name. */
private final static int COLOR_NAME_WIDTH = 150;
/** Width of rectangle that displays color. */
private final static int COLOR_RECT_WIDTH = 50;
/** Height of rectangle that displays color. */
private final static int COLOR_RECT_HEIGHT = 25;

private final TextField redField = TextFieldBuilder.create()
.text("Red Value").build();
private final TextField greenField = TextFieldBuilder.create()
.text("Green Value").build();
private final TextField blueField = TextFieldBuilder.create()
.text("Blue Value").build();
private final Rectangle customColorRectangle = RectangleBuilder.create()
.width(COLOR_RECT_WIDTH).height(COLOR_RECT_HEIGHT)
.fill(Color.WHITE).stroke(Color.BLACK).build();

/**
* Build a pane containing details about the instance of Color provided.
*
* @param color Instance of Color about which generated Pane should describe.
* @return Pane representing information on provided Color instance.
*/
private Pane buildColorBox(final Color color, final String colorName)
{
final HBox colorBox = new HBox();
final Label colorNameLabel = new Label(colorName);
colorNameLabel.setMinWidth(COLOR_NAME_WIDTH);
colorBox.getChildren().add(colorNameLabel);
final Rectangle colorRectangle = new Rectangle(COLOR_RECT_WIDTH, COLOR_RECT_HEIGHT);
colorRectangle.setFill(color);
colorRectangle.setStroke(Color.BLACK);
colorBox.getChildren().add(colorRectangle);
final String rgbString =
String.valueOf(color.getRed())
+ " / " + String.valueOf(color.getGreen())
+ " / " + String.valueOf(color.getBlue())
+ " // " + String.valueOf(color.getOpacity());
final Label rgbLabel = new Label(rgbString);
rgbLabel.setTooltip(new Tooltip("Red / Green / Blue // Opacity"));
colorBox.getChildren().add(rgbLabel);
return colorBox;
}

/**
* Extracts a double between 0.0 and 1.0 inclusive from the provided String.
*
* @param colorString String from which a double is extracted.
* @return Double between 0.0 and 1.0 inclusive based on provided String;
* will be 0.0 if provided String cannot be parsed.
*/
private double extractValidColor(final String colorString)
{
double colorValue = 0.0;
try
{
colorValue = Double.valueOf(colorString);
}
catch (Exception exception)
{
colorValue = 0.0;
err.println("Treating '" + colorString + "' as " + colorValue);
}
finally
{
if (colorValue < 0)
{
colorValue = 0.0;
err.println("Treating '" + colorString + "' as " + colorValue);
}
else if (colorValue > 1)
{
colorValue = 1.0;
err.println("Treating '" + colorString + "' as " + colorValue);
}
}
return colorValue;
}

/**
* Build pane with ability to specify own RGB values and see color.
*
* @return Pane with ability to specify colors.
*/
private Pane buildCustomColorPane()
{
final HBox customBox = new HBox();
final Button button = new Button("Display Color");
button.setPrefWidth(COLOR_NAME_WIDTH);
button.setOnMouseClicked(new EventHandler<MouseEvent>()
{
@Override
public void handle(MouseEvent t)
{
final Color customColor =
new Color(extractValidColor(redField.getText()),
extractValidColor(greenField.getText()),
extractValidColor(blueField.getText()),
1.0);
customColorRectangle.setFill(customColor);
}
});
customBox.getChildren().add(button);
customBox.getChildren().add(this.customColorRectangle);
customBox.getChildren().add(this.redField);
customBox.getChildren().add(this.greenField);
customBox.getChildren().add(this.blueField);
return customBox;
}

/**
* Build the main pane indicating JavaFX 2's pre-defined Color instances.
*
* @return Pane containing JavaFX 2's pre-defined Color instances.
*/
private Pane buildColorsPane()
{
final VBox colorsPane = new VBox();
final Field[] fields = Color.class.getFields(); // only want public
for (final Field field : fields)
{
if (field.getType() == Color.class)
{
try
{
final Color color = (Color) field.get(null);
final String colorName = field.getName();
colorsPane.getChildren().add(buildColorBox(color, colorName));
}
catch (IllegalAccessException illegalAccessEx)
{
err.println(
"Securty Manager does not allow access of field '"
+ field.getName() + "'.");
}
}
}
colorsPane.getChildren().add(buildCustomColorPane());
return colorsPane;
}

/**
* Start method overridden from parent Application class.
*
* @param stage Primary stage.
* @throws Exception JavaFX application exception.
*/
@Override
public void start(final Stage stage) throws Exception
{
final Group rootGroup = new Group();
final Scene scene = new Scene(rootGroup, 700, 725, Color.WHITE);
final ScrollPane scrollPane = new ScrollPane();
scrollPane.setPrefWidth(scene.getWidth());
scrollPane.setPrefHeight(scene.getHeight());
scrollPane.setContent(buildColorsPane());
rootGroup.getChildren().add(scrollPane);
stage.setScene(scene);
stage.setTitle("JavaFX Standard Colors Demonstration");
stage.show();
}

/**
* Main function for running JavaFX application.
*
* @param arguments Command-line arguments; none expected.
*/
public static void main(final String[] arguments)
{
Application.launch(arguments);
}
}


转载: http://www.javaworld.com/community/?q=node/8331

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值