Netbean  java8    source code  :http://files.cnblogs.com/files/rojas/HNT.zip

screenshot:

1  model

  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package hnt.model;
  7.  
  8. /**
  9. *
  10. * @author yang
  11. */
  12. public class Pan {
  13.  
  14. private String ptag;
  15. private double psize;
  16.  
  17. public Pan(String ptag, double psize) {
  18. this.ptag = ptag;
  19. this.psize = psize;
  20. }
  21.  
  22. /**
  23. * @return the ptag
  24. */
  25. public String getPtag() {
  26. return ptag;
  27. }
  28.  
  29. /**
  30. * @param ptag the ptag to set
  31. */
  32. public void setPtag(String ptag) {
  33. this.ptag = ptag;
  34. }
  35.  
  36. /**
  37. * @return the psize
  38. */
  39. public double getPsize() {
  40. return psize;
  41. }
  42.  
  43. /**
  44. * @param psize the psize to set
  45. */
  46. public void setPsize(double psize) {
  47. this.psize = psize;
  48. }
  49.  
  50. }

2 common logic

  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package hnt.control;
  7.  
  8. import hnt.model.Pan;
  9. import java.util.Stack;
  10.  
  11. /**
  12. *
  13. * @author yang
  14. */
  15. public class Logic {
  16.  
  17. public void setNewPole(Stack<Pan> pole, int capcity) {
  18. int i = capcity - ;
  19. while (i >= ) {
  20. pole.push(new Pan("p" + i, i * + ));
  21. i--;
  22. }
  23. }
  24.  
  25. public int MovePan(Stack<Pan> soruce, Stack<Pan> target) {
  26.  
  27. if (soruce.size() == ) {
  28. return ;
  29. }
  30.  
  31. if (target.size() == ) {
  32. target.push(soruce.pop());
  33. return ;
  34. } else {
  35. Pan pans = soruce.peek();
  36. Pan pant = target.peek();
  37. if (CheckSize(pans, pant)) {
  38. target.push(soruce.pop());
  39. return ;
  40. }
  41. return ;
  42. }
  43.  
  44. }
  45.  
  46. private boolean CheckSize(Pan pans, Pan pant) {
  47. boolean canMove = false;
  48.  
  49. if (pans.getPsize() < pant.getPsize()) {
  50. canMove = true;
  51. }
  52. return canMove;
  53. }
  54.  
  55. }

3 call point

  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package hnt;
  7.  
  8. import java.io.IOException;
  9. import javafx.application.Application;
  10. import javafx.fxml.FXMLLoader;
  11. import javafx.scene.Scene;
  12. import javafx.scene.layout.BorderPane;
  13. import javafx.scene.layout.StackPane;
  14. import javafx.stage.Stage;
  15.  
  16. /**
  17. *
  18. * @author yang
  19. */
  20. public class HNT extends Application {
  21.  
  22. @Override
  23. public void start(Stage primaryStage) throws IOException {
  24.  
  25. FXMLLoader loader=new FXMLLoader();
  26. loader.setLocation(HNT.class.getResource("/hnt/showHNT.fxml"));
  27. BorderPane bp= loader.load();
  28.  
  29. ShowHNTController shnt= loader.getController();
  30. //shnt.doinitialize();
  31.  
  32. StackPane root = new StackPane();
  33. root.getChildren().add(bp);
  34.  
  35. Scene scene = new Scene(root, , );
  36.  
  37. primaryStage.setTitle("Hello World!");
  38. primaryStage.setScene(scene);
  39. primaryStage.show();
  40. }
  41.  
  42. /**
  43. * @param args the command line arguments
  44. */
  45. public static void main(String[] args) {
  46. launch(args);
  47. }
  48.  
  49. }

4 control

  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package hnt;
  7.  
  8. import hnt.control.Logic;
  9. import hnt.model.Pan;
  10. import java.net.URL;
  11. import java.util.ArrayList;
  12. import java.util.HashMap;
  13. import java.util.List;
  14. import java.util.Map;
  15. import java.util.ResourceBundle;
  16. import java.util.Stack;
  17. import javafx.collections.FXCollections;
  18. import javafx.collections.ObservableList;
  19. import javafx.event.ActionEvent;
  20.  
  21. import javafx.fxml.FXML;
  22. import javafx.fxml.Initializable;
  23. import javafx.scene.control.Button;
  24. import javafx.scene.control.Label;
  25. import javafx.scene.control.ListView;
  26. import javafx.scene.control.TextField;
  27.  
  28. /**
  29. * FXML Controller class
  30. *
  31. * @author yang
  32. */
  33. public class ShowHNTController implements Initializable {
  34.  
  35. Logic l = new Logic();
  36. Stack<Pan> source = new Stack<>();
  37. Stack<Pan> target = new Stack<>();
  38.  
  39. private int capcity = ;
  40.  
  41. @FXML
  42. TextField tfcapcity = new TextField("" + getCapcity());
  43.  
  44. @FXML
  45. public void handleTextChange(final ActionEvent event) {
  46.  
  47. TextField tmptf = (TextField) event.getSource();
  48. //System.out.println("----------------- "+tmptf.getText());
  49. setCapcity(Integer.parseInt(tmptf.getText()));
  50. refreshListView();
  51. }
  52.  
  53. public void refreshListView() {
  54.  
  55. Stack<Pan> pole = new Stack();
  56. l.setNewPole(pole, getCapcity());
  57.  
  58. obsA = translate2SomeSymbol(pole);
  59. poleA.setItems(obsA);
  60.  
  61. selecteditem.add("A");
  62. obsB.clear();
  63. obsC.clear();
  64. mapAear.put("obsA", obsA);
  65. mapAear.put("obsB", obsB);
  66. mapAear.put("obsC", obsC);
  67.  
  68. poleA.setItems(mapAear.get("obsA"));
  69. poleB.setItems(mapAear.get("obsB"));
  70. poleC.setItems(mapAear.get("obsC"));
  71.  
  72. //clear status
  73. selecteditem = new ArrayList<>();
  74. source.removeAllElements();
  75. target.removeAllElements();
  76.  
  77. System.out.println(" come to refreshListView()");
  78. }
  79.  
  80. List<String> selecteditem = new ArrayList<>();
  81.  
  82. int countMoveTimes = ;
  83. @FXML
  84. Label MoveTimes = new Label("MoveTimes :" + countMoveTimes);
  85.  
  86. @FXML
  87. Button A;
  88.  
  89. @FXML
  90. Button B;
  91.  
  92. @FXML
  93. Button C;
  94.  
  95. static ObservableList<Button> obsA = FXCollections.observableArrayList();
  96.  
  97. @FXML
  98. ListView<Button> poleA = new ListView<>(obsA);
  99.  
  100. static ObservableList<Button> obsB = FXCollections.observableArrayList();
  101.  
  102. @FXML
  103. ListView<Button> poleB = new ListView<>(obsB);
  104.  
  105. static ObservableList<Button> obsC = FXCollections.observableArrayList();
  106.  
  107. @FXML
  108. ListView<Button> poleC = new ListView<>(obsC);
  109.  
  110. // String Aear[]={"obsA","obsB","obsC"};
  111. static Map<String, ObservableList> mapAear = new HashMap<>();
  112.  
  113. /**
  114. * Initializes the controller class.
  115. */
  116. @Override
  117. public void initialize(URL url, ResourceBundle rb) {
  118.  
  119. // String Aear[]={"obsA","obsB","obsC"};
  120. //MoveTimes = new Label("MoveTimes");
  121. Stack<Pan> pole = new Stack();
  122. l.setNewPole(pole, getCapcity());
  123.  
  124. obsA = translate2SomeSymbol(pole);
  125. poleA.setItems(obsA);
  126.  
  127. selecteditem.add("A");
  128.  
  129. mapAear.put("obsA", obsA);
  130. mapAear.put("obsB", obsB);
  131. mapAear.put("obsC", obsC);
  132. System.out.println(" come to ShowHNTController");
  133. }
  134.  
  135. //to button
  136. private ObservableList translate2SomeSymbol(Stack<Pan> pole) {
  137. ObservableList<Button> obs = FXCollections.observableArrayList();
  138. int pdelay=pole.size();
  139. for (Pan pole1 : pole) {
  140. Button bt = new Button();
  141. bt.setText(pole1.getPtag());
  142. bt.setRotate();
  143. bt.setMaxWidth(pole1.getPsize());
  144. bt.setTranslateX();
  145. obs.add(bt);
  146. }
  147.  
  148. return obs;
  149. }
  150.  
  151. // to SomeSymbol
  152. private Stack<Pan> retranslate2SomeSymbol(ObservableList<Button> bts) {
  153. // ObservableList<Button> obs=FXCollections.observableArrayList();
  154. Stack<Pan> pole = new Stack<>();
  155. for (Button bt : bts) {
  156. Pan p = new Pan(bt.getText(), bt.getWidth());
  157. pole.add(p);
  158. }
  159. return pole;
  160. }
  161.  
  162. String buttoncolor = "-fx-base: #b6e7c9;";
  163.  
  164. public void ChangeColor(String which, String colorstr) {
  165. // String buttoncolor="-fx-base: #b6e7c9;";
  166. for (String key : mapAear.keySet()) {
  167. if (key.contains(which) && (mapAear.get(key).size() > )) {
  168. Button bt = (Button) mapAear.get(key).get(mapAear.get(key).size() - );
  169. bt.setStyle(colorstr);
  170. }
  171. }
  172.  
  173. }
  174.  
  175. @FXML
  176. public void handleClick(final ActionEvent event) {
  177.  
  178. Button bt = (Button) event.getSource();
  179. //System.out.println(" from which "+bt.getText()+" width "+bt.getWidth());
  180.  
  181. if (selecteditem.isEmpty()) {
  182. selecteditem.add(bt.getText());
  183. ChangeColor(bt.getText(), buttoncolor);
  184. return;
  185. } else {
  186. if (selecteditem.size() >= ) {
  187. selecteditem.remove();
  188. selecteditem.add(bt.getText());
  189. ChangeColor(bt.getText(), buttoncolor);
  190. } else {
  191. selecteditem.add(bt.getText());
  192. ChangeColor(bt.getText(), buttoncolor);
  193. }
  194. }
  195.  
  196. // move action
  197. if ((selecteditem.size() > ) && (!selecteditem.get().equals("")) && (!selecteditem.get().equals(selecteditem.get()))) {
  198.  
  199. // System.out.println(" selected name " +obsA.getClass().getName());
  200. for (String key : mapAear.keySet()) {
  201. if (key.contains(selecteditem.get())) {
  202. source = retranslate2SomeSymbol(mapAear.get(key));
  203. }
  204. if (key.contains(selecteditem.get())) {
  205. target = retranslate2SomeSymbol(mapAear.get(key));
  206. }
  207. }
  208.  
  209. ////===============
  210. l.MovePan(source, target);
  211.  
  212. for (String key : mapAear.keySet()) {
  213. if (key.contains(selecteditem.get())) {
  214. mapAear.replace(key, translate2SomeSymbol(source));
  215. }
  216. if (key.contains(selecteditem.get())) {
  217. mapAear.replace(key, translate2SomeSymbol(target));
  218. }
  219. }
  220. ChangeColor(bt.getText(), "");
  221. poleA.setItems(mapAear.get("obsA"));
  222. poleB.setItems(mapAear.get("obsB"));
  223. poleC.setItems(mapAear.get("obsC"));
  224.  
  225. //MoveTimes =new Label("MoveTimes");
  226. countMoveTimes += ;
  227. MoveTimes.setText("MoveTimes:" + countMoveTimes);
  228.  
  229. //clear status
  230. selecteditem = new ArrayList<>();
  231. source.removeAllElements();
  232. target.removeAllElements();
  233. }
  234.  
  235. }
  236.  
  237. /**
  238. * @return the capcity
  239. */
  240. public int getCapcity() {
  241. return capcity;
  242. }
  243.  
  244. /**
  245. * @param capcity the capcity to set
  246. */
  247. public void setCapcity(int capcity) {
  248. this.capcity = capcity;
  249. }
  250.  
  251. }

5 FXML

  1. <?xml version="1.0" encoding="UTF-8"?>
  2.  
  3. <?import javafx.geometry.*?>
  4. <?import javafx.scene.text.*?>
  5. <?import java.lang.*?>
  6. <?import java.util.*?>
  7. <?import javafx.scene.*?>
  8. <?import javafx.scene.control.*?>
  9. <?import javafx.scene.layout.*?>
  10.  
  11. <BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="hnt.ShowHNTController">
  12. <bottom>
  13. <HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0" spacing="100.0" BorderPane.alignment="CENTER">
  14. <children>
  15. <Button fx:id="A" minHeight="20.0" minWidth="20.0" mnemonicParsing="false" onAction="#handleClick" prefHeight="23.0" prefWidth="100.0" text="A" />
  16. <Button fx:id="B" mnemonicParsing="false" onAction="#handleClick" prefHeight="23.0" prefWidth="100.0" text="B" />
  17. <Button fx:id="C" mnemonicParsing="false" onAction="#handleClick" prefHeight="23.0" prefWidth="100.0" text="C" />
  18. </children>
  19. </HBox>
  20. </bottom>
  21. <center>
  22. <HBox prefHeight="100.0" prefWidth="200.0" BorderPane.alignment="CENTER">
  23. <children>
  24. <ListView fx:id="poleA" prefHeight="200.0" prefWidth="200.0" rotate="180.0" />
  25. <ListView fx:id="poleB" prefHeight="200.0" prefWidth="200.0" rotate="180.0" />
  26. <ListView fx:id="poleC" prefHeight="200.0" prefWidth="200.0" rotate="180.0" />
  27. </children>
  28. </HBox>
  29. </center>
  30. <top>
  31. <VBox prefHeight="52.0" prefWidth="600.0" BorderPane.alignment="CENTER">
  32. <children>
  33. <Label alignment="CENTER" prefHeight="15.0" prefWidth="600.0" text="HNT" textAlignment="CENTER">
  34. <font>
  35. <Font size="27.0" />
  36. </font>
  37. </Label>
  38. <HBox prefHeight="100.0" prefWidth="200.0" spacing="10.0">
  39. <children>
  40. <Label fx:id="MoveTimes" prefHeight="15.0" prefWidth="365.0" text="Move Times">
  41. <padding>
  42. <Insets left="20.0" />
  43. </padding>
  44. </Label>
  45. <Label prefHeight="15.0" prefWidth="42.0" text="Capcity:" />
  46. <TextField fx:id="tfcapcity" onAction="#handleTextChange" text="">
  47. <HBox.margin>
  48. <Insets />
  49. </HBox.margin>
  50. <padding>
  51. <Insets bottom="10.0" />
  52. </padding>
  53. </TextField>
  54. </children>
  55. </HBox>
  56. </children>
  57. </VBox>
  58. </top>
  59. </BorderPane>

javafx Hanoi的更多相关文章

  1. Hanoi问题java解法

    用什么语言解法都差不多,思路都是一样,递归,这其中只要注重于开始和结果的状态就可以了,对于中间过程,并不需要深究.(我细细思考了一下,还是算了.=_=) 代码其实很简单注重的是思路. 问题描述:有一个 ...

  2. 问题记录:JavaFx 鼠标滑轮滚动事件监听!

    问题描述: 在listview的item里面添加鼠标拖拽排序功能.代码如下: setOnMouseDragged(event -> { //设定鼠标长按0.3秒后才可拖拽 防止误操作 isCan ...

  3. JavaFx客户端服务器C/S架构搭建

    客户端获取服务器端软件更新版本方法: package com.platform.ui.update; import java.io.BufferedInputStream; import java.i ...

  4. JavaFX 教程资料收集

    1. JavaFX中文资料 http://www.javafxchina.net/blog/docs/tutorial1/ 2. JavaFX入门教程 http://www.xrpmoon.com/c ...

  5. HDU1329 Hanoi Tower Troubles Again!——S.B.S.

    Hanoi Tower Troubles Again! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  6. ZOJ-1239 Hanoi Tower Troubles Again!

    链接:ZOJ1239 Hanoi Tower Troubles Again! Description People stopped moving discs from peg to peg after ...

  7. 在 linux 上部署并运行 JavaFX 项目

    环境 redhat 6.4.eclipse安装JavaFX插件 项目详情及代码参见 在linux上配置并创建JavaFX项目 ,该部署即此文章中项目的部署 配置build.fxbuild 生成buil ...

  8. 在linux上配置并创建JavaFX项目

    本环境为linux配置,因为这里的JavaFX项目是为定制Oracle监控工具而写的.现Oracle已收购Java好几年,用它自己的产生监控自己的东西还是很兼容的.此处Eclipse 为4.5版本. ...

  9. javafx之登陆界面的跳转

    界面布局用到的是fxml而非纯java代码,工具是javafx sence builder 账号:account 密码:password 登陆成功: 可以点击退出登陆返回到登陆页面 工程目录: pac ...

随机推荐

  1. ViewPager设置不能滚动

    设置ViewPager不能滑动 1:设置当前选中的页面 public void setCurrentItem(int item) { mPopulatePending = false; setCurr ...

  2. <Sicily>Funny Game

    一.题目描述 Two players, Singa and Suny, play, starting with two natural numbers. Singa, the first player ...

  3. OGG切换步骤

    步骤描述 提前准备好切换方案:以及其他相关人员的配合 切换至容灾数据库: (1)停止前端业务,确认目标端数据已经追平 (2)数据校验,确认数据一致 (3)停止生产库OGG进程(停止后可以直接删除) ( ...

  4. NetBios, NetBios over TCP/IP, SMB 之间的关系

    首先提到的是NetBios,NetBios是Network Basic Input/Output System的缩写,提供了一种允许局域网内不同电脑能够通信的功能.严格来说,NetBios是一套API ...

  5. 使用jemdoc制作个人主页

    jemdoc官网说明: http://jemdoc.jaboc.net/index.html 作者的个人主页:https://jemnz.com/ 将下载的jemdoc.py文件和需要转化的xxx.j ...

  6. HDU 4939 Stupid Tower Defense 简单DP

    题意: 地图为长为n个单位长度的直线,每通过一个单位长度需要t秒. 有3种塔,红塔可以在当前格子每秒造成x点伤害,绿塔可以在之后格子造成y点伤害,蓝塔可以使通过单位长度的时间增加z秒. 让你安排塔的排 ...

  7. 【Round #36 (Div. 2 only) C】Socks Pairs

    [题目链接]:https://csacademy.com/contest/round-36/task/socks-pairs/ [题意] 给你n种颜色的袜子,每种颜色颜色的袜子有ai只; 假设你在取袜 ...

  8. HDFS 文件系统流程图。PB级文件存储时序图。

    大小文件通吃, 热点hash功能. 全局唯一KV索引. 百度网盘模式.断点续传功能.MR分析功能. 来自为知笔记(Wiz)

  9. cocos2d-x 2.2.0 怎样在lua中注冊回调函数给C++

    cocos2d-x内部使用tolua进行lua绑定.可是引擎并没有提供一个通用的接口让我们能够把一个lua函数注冊给C++层面的回调事件. 翻看引擎的lua绑定代码,我们能够仿照引擎中的方法来做. 值 ...

  10. HDU 5389 Zero Escape(DP + 滚动数组)

    Zero Escape Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) To ...