初学javafx 写了个小例子,没有使用图片, 代码较乱 如下:
/**//*
* JDI.fx
*
* Created on 2009-7-22, 19:06:20
*/
package gui;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.scene.paint.Color;
import javafx.scene.effect.Reflection;
import javafx.scene.shape.Line;
import javafx.scene.shape.Rectangle;
import javafx.scene.*;
import javafx.scene.effect.*;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.KeyCode;
import javafx.scene.image.*;
import javafx.animation.Timeline;
import javafx.animation.KeyFrame;
import javafx.animation.Interpolator;
import javafx.scene.control.Button;
import javafx.scene.input.MouseEvent;
/** *//**
* @author ericjoe
*/
// var k = KeyEvent.CHAR_UNDEFINED.
var complete = false;
var background=ImageView {
focusTraversable:true
onKeyPressed: function( e: KeyEvent ):Void {
if(complete==false)move(e);
}
}
var logot=0;
var logarc=Rectangle {
x: 0, y: 0
width: 200, height: 80
fill: Color.BLUEVIOLET
}
var logoline=Line {
startX: 10, startY:40
endX: 690, endY: 40
strokeWidth: 1
stroke: Color.RED
}
var gamelogo=Text {
fill:Color.BLACK
translateX:bind logot
effect:Reflection {
fraction: 0.75
topOffset: 0.0
topOpacity: 0.4
bottomOpacity: 0.0
}
font : Font {
size: 30;
}
x: -120, y: 30
content: "move game"
}
var goNum=0;
var state= bind if(complete)then "complete! use {goNum} steps" else "step:{goNum}";
var statex=0;
var gamestate=Text {
fill:Color.YELLOWGREEN
font : Font {
size: 24
}
x: 800, y: 65
content: bind state;
}
var gameline=Line {
startX: 10, startY:80
endX: 690, endY: 80
strokeWidth: 1
stroke: Color.BLUEVIOLET
}
var gameframe=Rectangle {
x: 10, y: 100
width: 580, height: 580
fill: Color.BLACK
focusTraversable:true
}
var t=[1..8];
var r= new java.util.Random();
var cards:Card[]= getCards();
function getCards():Card[]{
var n = 0;
var cardsinit:Card[];
for(i in [0..7]){
var card=Card{
recX:10+(580/3)*n
recY:100+(580/3)*(i/3)
cardTextX: 10+(580/3)*n+70
cardTextY:100+(580/3)*(i/3)+120
cardTextConten:getTextContent();
}
insert card into cardsinit;
n++;
if(n==3)then n=0;
}
t=[1..8];
cardsinit;
}
var main=true;
var changeButton=Button {
text: "change"
layoutX:900
layoutY:10
onMousePressed: function( e: MouseEvent ):Void {
cards=getCards();
btx=10+(580/3)*2;
bty=100+(580/3)*2;
complete=false;
goNum=0;
}
onKeyPressed: function( e: KeyEvent ):Void {
if(complete==false)move(e);
}
}
var htext="help";
var helpButton=Button {
text: bind htext;
layoutX:1000
layoutY:10
width:100
action: function() {
htext=if(htext=="help") then "back to game" else "help";
main=if(main==true)then false else true;
}
onKeyPressed: function( e: KeyEvent ):Void {
if(complete==false)move(e);
}
}
var rightgroup=Group {
translateX:bind statex;
content: [
changeButton,
gamestate,
helpButton
]
}
function getTextContent():Integer{
// println(t.size());
var i = t[r.nextInt(sizeof t)];
delete i from t;
return i;
}
var btx:Number=10+(580/3)*2;
var bty:Number=100+(580/3)*2;
var cardBlank = Rectangle {
x: bind btx ,
y: bind bty ,
width: 580/3, height: 580/3
fill: Color.BLACK
}
var cardsc=0.0;
var cardsGroup= Group {
opacity:bind cardsc;
focusTraversable:true
content:bind [
cards,
cardBlank
]
}
var helptext = Text {
font : Font {
size: 24
}
fill:Color.YELLOWGREEN
x: 150, y: 300
content: " use ↑↓← → to move the chess";
}
var scorrt=0;
var scorrtext = Text {
font : Font {
size: 12
}
translateX:bind scorrt;
fill:Color.YELLOWGREEN
layoutX:-110
layoutY:95
// x: 10, y: 95
content: "a javafx example";
}
var mainSence = Scene {
width: 600
height:700
fill:Color.BLACK
content:bind [
background,
rightgroup,
logoline,
scorrtext,
logarc,
gamelogo,
gameline,
gameframe,
if(main)then cardsGroup else helptext
]
}
Stage {
title: "move game"
resizable:false
scene: mainSence
分享到:
相关推荐
attention when it dropped the support for JavaFX Script and supported writing JavaFX programs using the Java programming language. In its current version, JavaFX 8 is supported in the Java platform by...
本书《Learn JavaFX 8》是一本详尽介绍 JavaFX 8 的书籍,共计 1200 页,内容非常全面且深入。 在 JavaFX 出现之前,开发者主要依赖于 AWT 和 Swing 进行图形用户界面的开发。然而,这两套框架存在诸多不足之处:...
在"Learn JavaFX 8 源代码"中,读者可以深入理解JavaFX编程的核心概念和技术。这本书由Apress在2015年出版,旨在帮助开发者掌握JavaFX 8的新特性和用法。 JavaFX 8是Java平台的重要组成部分,特别是在Swing之后,它...
Learn JavaFX 8 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
attention when it dropped the support for JavaFX Script and supported writing JavaFX programs using the Java programming language. In its current version, JavaFX 8 is supported in the Java platform by...
《Learn JavaFX 8.pdf》是一本关于JavaFX 8开发的详细教材,涵盖了JavaFX编程的众多方面。JavaFX是一种用于构建富客户端应用程序的软件平台,是Java SE的一部分,它提供了许多用于创建图形用户界面的组件。 首先,...
JavaFX是Oracle公司推出的一种用于创建富互联网应用程序(RIA)的平台,它允许开发者使用JavaFX脚本语言或Java编程语言来构建具有丰富图形界面的应用程序。JavaFX 1.2是该技术的一个早期版本,提供了许多创新特性,...
pro JavaFX 8 code 源代码 JavaFX runs on desktops (Mac, Windows, Linux), as well as embedded devices such as the Raspberry Pi. As the Internet of things (IoT) is increasingly realized, JavaFX is well ...
主要描述了javaFX8的一些新功能和程序示例
javafx 8 javafx 8 javafx 8 javafx 8 javafx 8 javafx 8 javafx 8 javafx 8 javafx 8 javafx 8 javafx 8 javafx 8 javafx 8 javafx 8 javafx 8
2.learn-javafx-8-master.zip; 3.pro-javafx-8-master.zip; 4.pro-javafx-9-master.zip; 5.javafx-9-by-example-master.zip; 6.java-apis-extensions-and-libraries-master.zip; 7.Java+APIs+Extensions+and+...
Learn the Fundamentals of JavaFX 8 from Programming Guru Herb Schildt Introducing JavaFX 8 Programming provides a fast-paced, practical introduction to JavaFX, Java’s next-generation GUI programming...
What you’ll learn How to get started with JavaFX 2, including downloading the SDK and available tools. How to express user interfaces with a declarative-style enabled by the JavaFX builder classes. ...
Javafx 8 2nd Edition Book
javafx 比较好的学习资料 Learn JavaFX 8 - Building User Experience and Interfaces with Java 8 - 1st Edition (2015)
Use the JavaFX platform to create rich-client Java applications and discover how you can use ...Experienced Java programmers looking to learn and leverage JavaFX 9 for rich client-side Java development.
In this tutorial, you learn how to build user interfaces in your JavaFX applications with the UI components available through the JavaFX API. 介绍了JavaFX所有UI控件。目录如下: 1. What Is New 2. ...
Use the JavaFX platform to create rich-client Java applications and discover how you can use ...Experienced Java programmers looking to learn and leverage JavaFX 9 for rich client-side Java development.