目前我有一个我在Netbeans中构建的游戏,并且已经能够创建一个棋盘,放置棋子并允许它们使用mouseveent移动到任何地方
但是现在我在尝试编写电路板上的部件时只遇到允许的操作时遇到了问题.
我遇到的问题是每件作品仍然被允许移动但现在当它移动时,所选的作品从板上消失,完全在鼠标释放事件中完成所有新功能
我试图添加的代码是WhitePawn,这是唯一应该允许立即移动的部分
其余的如果他们试图移动应该只返回到设置位置,无论他们被拖动的位置.我删除了与问题无关的所有代码并运行调试器.从那我知道一个事实,问题是在鼠标释放事件代码中的某个地方,我只是无法找到它.
public void mouseReleased(MouseEvent e) {
if (chessPiece == null) {
return;
}
chessPiece.setVisible(false);
Boolean success = false;
Component c = chessBoard.findComponentAt(e.getX(), e.getY());
String tmp = chessPiece.getIcon().toString();
String pieceName = tmp.substring(0, (tmp.length() - 4));
Boolean validMove = false;
//Pawn Moves
//White Pawn
if (pieceName.equals("WhitePawn")) {
if (startY == 1) {
if ((startX == (e.getX() / 75)) && ((((e.getY() / 75) - startY) == 1) || ((e.getY() / 75) - startY) == 2)) {
if ((((e.getY() / …
Run Code Online (Sandbox Code Playgroud) 快速问题我有一个名为Board.java的java文件,它创建并放置棋子,但我有一个问题,目前它只制作棋盘本身但不分配棋子
我假设我没有链接png的权利
这是我的设置的屏幕截图我正在使用Netbeans来构建我已截屏的游戏,这样你就可以看到图像存储的位置以及我到目前为止编写的程序
在你问我运行程序时我没有收到错误之前,它只会弹出一个没有碎片的空棋盘
这里还有Java文件
Board.java
package chessgame;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import static javax.swing.WindowConstants.DISPOSE_ON_CLOSE;
public class Board extends JFrame {
JLayeredPane layeredPane;
JPanel chessBoard;
JLabel chessPiece;
int xAdjustment;
int yAdjustment;
int startX;
int startY;
int initialX;
int initialY;
JPanel panels;
JLabel pieces;
public Board(){
Dimension boardSize = new Dimension(700, 700);
// This is a Layered Pane for this application
layeredPane = new JLayeredPane();
getContentPane().add(layeredPane);
layeredPane.setPreferredSize(boardSize);
//Add a chess board to the Layered Pane
chessBoard = …
Run Code Online (Sandbox Code Playgroud) 我已经创建了一个帐户,并且我的api键目前只需要一个简单的搜索框和按钮,当点击时会列出游戏和该游戏的图像
已链接以下网站信息
http://www.giantbomb.com/api/documentation
我想运行is并使用json和jquery获取输出任何帮助欢迎
这是一个工作搜索现在一些不允许用户输入新值并且出现图像问题
两个主要问题不会加载图像只是说未定义并且无法弄清楚如何只有当用户输入新标题时才能使其成为完整搜索
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$.ajax({
url: "http://api.giantbomb.com/search/",
type: "get",
data: {api_key : "key here", query: "star trek", resources : "game", field_list : "name, resource_type, image", format : "jsonp", json_callback : "gamer" },
dataType: "jsonp"
});
});
function gamer(data) {
var table = '<table>';
$.each( data.results, function( key, value ) {
table += '<tr><td>' + value.image + '</td><td>' + value.name + '</td><td>' + value.resource_type + '</td></tr>';
});
table += '</table>';
$('#myelement').html(table);
}
</script> …
Run Code Online (Sandbox Code Playgroud) java ×2
swing ×2
chess ×1
html ×1
image ×1
javascript ×1
jquery ×1
json ×1
mouseevent ×1
search ×1