import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;
import javafx.application.Application;
import javafx.geometry.Point2D;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.shape.Line;
import javafx.stage.Stage;
/** Use the old Graph.java, AbstractGraph.java, UnweightedGraph.java. Need to replace it in the future.*/
public class Exercise28_18 extends Application {
private Model model = new Model();
private static final int SIZE = 8;
private int startX = 0;
private int startY = 0;
private ArrayList<Point2D> moveHistory = null;
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
BorderPane pane = new BorderPane();
ChessBoard board = new ChessBoard();
pane.setCenter(board);
Button btPath = new Button("Path");
Button btCycle = new Button("Cycle");
HBox hBox = new HBox(5);
hBox.getChildren().addAll(btPath, btCycle);
hBox.setAlignment(Pos.CENTER);
pane.setBottom(hBox);
// Create a scene and place it in the stage
Scene scene = new Scene(pane, 250, 250);
primaryStage.setTitle("Exercise28_18"); // Set the stage title
primaryStage.setScene(scene); // Place the scene in the stage
primaryStage.show(); // Display the stage
board.repaint();
btPath.setOnAction(e -> {
resetMoveHistory();
List<Integer> list = model.findHamiltonianPath(startX, startY);
for (int i = 0; i < list.size(); i++) {
addMoveHistory(list.get(i) / 8, list.get(i) % 8);
}
board.repaint();
});
btCycle.setOnAction(e -> {
resetMoveHistory();
List<Integer> list = model.findHamiltonianCycle(startX, startY);
for (int i = 0; i < list.size(); i++) {
addMoveHistory(list.get(i) / 8, list.get(i) % 8);
}
board.repaint();
});
scene.widthProperty().addListener(ov -> board.repaint());
scene.heightProperty().addListener(ov -> board.repaint());
}
public void resetMoveHistory() {
moveHistory = new ArrayList(63);
}
public void addMoveHistory(int x, int y) {
moveHistory.add(new Point2D(x, y));
}
public void removeLastMoveHistory() {
moveHistory.remove(moveHistory.size() - 1);
}
private class ChessBoard extends Pane {
ImageView knightImageView = new ImageView("image/knight.jpg");
ChessBoard() {
this.setOnMouseClicked(e -> {
startX = (int) (e.getX() / (getWidth() / SIZE));
startY = (int) (e.getY() / (getHeight() / SIZE));
resetMoveHistory();
repaint();
});
}
protected void repaint() {
// Clear previous drawing
this.getChildren().clear();
// Add the Knight image
this.getChildren().add(knightImageView);
knightImageView.setX(startX * getWidth() / SIZE);
knightImageView.setY(startY * getHeight() / SIZE);
knightImageView.setFitWidth(getWidth() / SIZE);
knightImageView.setFitHeight(getHeight() / SIZE);
// Draw the lines
for (int i = 1; i <= SIZE; i++) {
this.getChildren().add(
new Line(0, i * getHeight() / SIZE, getWidth(), i * getHeight() / SIZE));
this.getChildren().add(
new Line(i * getWidth() / SIZE, 0, i * getWidth() / SIZE, getHeight()));
}
// Draw the moves
if (moveHistory != null) {
for (int i = 1; i < moveHistory.size(); i++) {
Point2D p1 = moveHistory.get(i - 1);
Point2D p2 = moveHistory.get(i);
this.getChildren().add(
new Line(p1.getX() * (getWidth() / SIZE) + getWidth() / SIZE / 2,
p1.getY() * (getHeight() / SIZE) + (getHeight() / SIZE / 2),
p2.getX() * (getWidth() / SIZE) + getWidth() / SIZE / 2,
p2.getY() * (getHeight() / SIZE) + getHeight() / SIZE / 2));
}
}
}
}
/**
* The main method is only needed for the IDE with limited
* JavaFX support. Not needed for running from the command line.
*/
public static void main(String[] args) {
launch(args);
}
/**
* Edge inner class inside the AbstractGraph class
*/
public static class Edge {
public int u; // Starting vertex of the edge
public int v; // Ending vertex of the edge
/**
* Construct an edge for (u, v)
*/
public Edge(int u, int v) {
this.u = u;
this.v = v;
}
}
public interface Graph {
/**
* Return the number of vertices in the graph
*/
public int getSize();
/**
* Return the vertices in the graph
*/
public Object[] getVertices();
/**
* Return the object for the specified vertex index
*/
public Object getVertex(int index);
/**
* Return the index for the specified vertex object
*/
public int getIndex(Object v);
/**
* Return the neighbors of vertex v
*/
public java.util.List getNeighbors(int v);
/**
* Return the degree for a specified vertex
*/
public int getDegree(int v);
/**
* Return the adjacency matrix
*/
public int[][] getAdjacencyMatrix();
/**
* Print the adjacency matrix
*/
public void printAdjacencyMatrix();
/**
* Print the edges
*/
public void printEdges();
/**
* Obtain a depth-first search tree
*/
public AbstractGraph.Tree dfs(int v);
/**
* Obtain a breadth-first search tree
*/
public AbstractGraph.Tree bfs(int v);
/**
* Obtain a depth-first search tree
*/
public List<Integer> getHamiltonianPath(int v);
/**
* Obtain a depth-first search tree
*/
public List<Integer> getHamiltonianCycle(int v);
/** Return a Hamiltonian cycle
* Return null if the graph does not contain a Hamiltonian cycle */
public List<Integer> getHamiltonianCycle();
}
public abstract class AbstractGraph implements Graph {
protected Object[] vertices; // Store vertices
protected LinkedList<Integer>[] neighbors; // Adjacency lists
/**
* Construct a graph from edges and vertices stored in arrays
*/
protected AbstractGraph(int[][] edges, Object[] vertices) {
this.vertices = vertices;
createAdjacencyLists(edges, vertices.length);
}
/**
* Construct a graph from edges and vertices stored in ArrayList
*/
protected AbstractGraph(List<Edge> edges, List<Object> vertices) {
this.vertices = vertices.toArray();
createAdjacencyLists(edges, vertices.size());
}
/**
* Construct a graph from edges and vertices in ArrayList
*/
protected AbstractGraph(List<Edge> edges, int numberOfVertices) {
vertices = new Integer[numberOfVertices]; // Create vertices
for (int i = 0; i < numberOfVertices; i++) {
vertices[i] = new Integer(i); // vertices is {0, 1, 2, ...}
}
createAdjacencyLists(edges, numberOfVertices);
}
/**
* Construct a graph from edges in array
*/
protected AbstractGraph(int[][] edges, int numberOfVertices) {
vertices = new Integer[numberOfVertices]; // Create vertices
for (int i = 0; i < numberOfVertices; i++) {
vertices[i] = new Integer(i); // vertices is {0, 1, 2, ...}
}
createAdjacencyLists(edges, numberOfVertices);
}
/**
* Create adjacency lists for each vertex
*/
@SuppressWarnings("unchecked")
private void createAdjacencyLists(
没有合适的资源?快使用搜索试试~ 我知道了~
java语言程序设计 梁勇 第十版答案.zip
共1634个文件
java:939个
gif:224个
png:122个
需积分: 45 83 下载量 81 浏览量
2019-07-31
12:12:35
上传
评论 22
收藏 13.9MB ZIP 举报
温馨提示
java语言程序设计 梁勇 第十版答案,真的不错!良心制作,每章都归类在一个文件夹里,方便学习和自学!
资源推荐
资源详情
资源评论
收起资源包目录
java语言程序设计 梁勇 第十版答案.zip (1634个子文件)
malaysia.bmp 92KB
malaysia.bmp 92KB
uk.bmp 17KB
canada.bmp 17KB
canada.bmp 17KB
uk.bmp 17KB
usa.bmp 16KB
usa.bmp 16KB
germany.bmp 14KB
germany.bmp 14KB
france.bmp 13KB
india.bmp 13KB
france.bmp 13KB
india.bmp 13KB
norway.bmp 3KB
norway.bmp 3KB
Exercise38_005f01_jsp.class 3KB
Exercise38_19.class 3KB
Exercise38_19.class 3KB
Exercise37_13.class 3KB
Exercise33_09.class 3KB
Exercise33_09.class 3KB
Exercise37_10.class 2KB
Exercise33_12.class 2KB
Exercise33_12.class 2KB
Exercise37_11.class 2KB
Exercise37_07.class 2KB
Exercise37_08.class 2KB
Exercise37_14.class 2KB
Exercise33_04.class 2KB
Exercise33_04.class 2KB
Exercise37_03b.class 2KB
Exercise33_11.class 2KB
Exercise33_11.class 2KB
Exercise33_05.class 2KB
Exercise33_05.class 2KB
ValidateForm.class 2KB
ValidateForm.class 2KB
Exercise37_12.class 2KB
Loan.class 2KB
Exercise33_08.class 2KB
Exercise33_08.class 2KB
Exercise37_01.class 2KB
Exercise37_06.class 2KB
Exercise38_13.class 1KB
Exercise38_13.class 1KB
Exercise37_03a.class 1KB
Exercise33_07.class 1KB
Exercise33_07.class 1KB
Exercise37_09.class 1KB
Exercise37_02.class 1KB
Exercise33_10.class 1KB
Exercise33_10.class 1KB
Exercise33_03.class 1KB
Exercise33_03.class 1KB
Exercise37_05.class 1KB
Exercise37_04.class 1KB
Exercise33_11$EvaluateExpression.class 1KB
Exercise33_12$EvaluateExpression.class 1KB
Exercise33_11$EvaluateExpression.class 1KB
Exercise33_12$EvaluateExpression.class 1KB
Exercise38_7.class 1KB
Exercise38_7.class 1KB
Exercise38_12.class 1KB
Exercise38_12.class 1KB
Exercise33_01.class 1KB
Exercise33_01.class 1KB
GuessNumberBean.class 1KB
GuessNumberBean.class 1KB
Exercise33_02.class 942B
Exercise33_02.class 942B
StateCapital.class 940B
StateCapital.class 940B
Exercise38_6.class 900B
Exercise38_6.class 900B
Exercise38_11.class 878B
Exercise38_18.class 878B
Exercise38_11.class 878B
Exercise38_18.class 878B
Exercise38_5.class 770B
Exercise38_5.class 770B
ComputeTax.class 748B
ComputeTax.class 748B
AdditionTutor.class 701B
AdditionTutor.class 701B
ComputeTax.class 664B
ComputeTax.class 652B
ComputeTax.class 652B
NumberSet.class 556B
NumberSet.class 556B
gfv3ee6.dpf 0B
gfv3ee6.dpf 0B
L20.gif 16KB
L20.gif 16KB
L19.gif 16KB
L19.gif 16KB
L22.gif 16KB
L22.gif 16KB
L46.gif 16KB
L46.gif 16KB
共 1634 条
- 1
- 2
- 3
- 4
- 5
- 6
- 17
资源评论
amazing、、、
- 粉丝: 5
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- NetOps-py通过sftp替换网络设备启动文件
- STM32单片机FPGA毕设电路原理论文报告任务驱动教学法在单片机课程教学中的应用
- STM32单片机FPGA毕设电路原理论文报告任务驱动法在单片机教学中的应用
- STM32单片机FPGA毕设电路原理论文报告人造金刚石压机智能化压力测控系统设计
- 以某列为依据匹配多项(Excel版)
- STM32单片机FPGA毕设电路原理论文报告人体短臂离心机实验台的显示控制系统
- STM32单片机FPGA毕设电路原理论文报告人工气候室监控系统的环境控制器研究
- STM32单片机FPGA毕设电路原理论文报告染整自动线张力控制系统的设计
- 数据挖掘与机器学习-实验
- 基于Linux系统Nginx的动态网站的LNMP环境源码包
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功