- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试编写一个寻路迷宫算法,以尝试将 A* 实现到 JPanel 接口(interface)中。代码如下。如您所见,我使用随机数生成器随机生成迷宫方 block 的颜色。以下是源代码的基本实现:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Scanner;
import java.util.Random;
public class algo extends JPanel
implements MouseListener, MouseMotionListener
{
static int[][] map;
public void paintComponent(Graphics g) {
super.paintComponent(g);
this.setBackground(Color.WHITE);
//draw a for loop to print the map
for (int i = 0; i < map.length; i++) {
for(int j = 0; j < map[i].length; j++) {
g.setColor(Color.WHITE);
if(map[i][j] == 1) {
g.setColor(Color.BLACK);
}
g.fillRect(j * 20, i * 20, map[i].length * 20, map.length *20);
}
}
}
public static void main(String[] args) {
System.out.println("Welcome to the A* Shortest Pathfinding Robot Program \n *****"
+ "**************************"
+ "********************\n");
System.out.println("How large would you like your graph to be? Enter 2 consecutive numbers, one for length, one for width:\n");
Scanner sizeScan = new Scanner(System.in);
int length = sizeScan.nextInt();
int width = sizeScan.nextInt();
map = new int[length][width];
Random gridGenerate = new Random();
for(int i = 0; i < map.length; i++) {
for (int j = 0; j < map[i].length; j++) {
map[i][j] = gridGenerate.nextInt(2);
System.out.print(map[i][j] + " ");
}
System.out.println();
}
JFrame f = new JFrame("A Star Pathfinder");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
algo star = new algo();
f.add(star);
f.setSize(length * 20, width * 20);
f.setVisible(true);
}
@Override
public void mouseDragged(MouseEvent e) {}
@Override
public void mouseMoved(MouseEvent e) {}
@Override
public void mouseClicked(MouseEvent e) {
System.out.println("Successfully Clicked");
if (SwingUtilities.isLeftMouseButton(e)) {
System.out.println("This is the left mouse button that is clicked");
}
}
@Override
public void mouseEntered(MouseEvent e) {}
@Override
public void mouseExited(MouseEvent e) {}
@Override
public void mousePressed(MouseEvent e) {}
@Override
public void mouseReleased(MouseEvent e) {}
}
当我运行 main() 方法时,我能够成功生成迷宫:
Here is the "Maze" Generated from the code
但是,当我尝试在迷宫上实现 MouseClick() 操作时,没有任何反应。我有打印语句来尝试测试这一点,并且每种可能的解决方案都没有解决问题。
关于为什么 mouseHandler 没有响应我的请求还有其他想法吗?
最佳答案
您必须显式地将鼠标监听器添加到 JPanel。
public class algo extends JPanel implements MouseListener, MouseMotionListener {
public algo() {
this.addMouseListener(this);
this.addMouseMotionListener(this);
}
// other stuff
}
关于java - MouseClicked() 方法不适用于寻路算法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55091669/
粗略地说,单向数据绑定(bind)只是与 ng-model 绑定(bind)。当涉及 Controller 时,在页面内和 2-way 内。有人可以向我解释这个概念,以便我真正了解如何看待它吗?还有什
我想知道是否有任何替代 2 向 SSL 的方法。 2 向 SSL 是确保客户端和服务器可信通信的唯一选择吗?我有一个自签名证书供我的客户使用,我能否将自签名证书重新用于 2 种 SSL 方式,还是应该
如果是这样,你如何设置认证证书,你需要什么文件?是 .pfx 吗?您将如何在浏览器中安装它?一直试图通过浏览器测试 2 路 ssl。我有一个网络服务,尝试连接时总是返回认证身份验证失败。 最佳答案 扩
我希望能够对 XHTML 文档进行三向合并: 从文档的一些原始副本开始 一个用户编辑原始文档的副本 另一个用户编辑原始文档的单独副本 需要一个工具来合并(自动和/或可视化)两个用户所做的更改。 注意:
我有 4 张 table : ad (id, ...) website (id, title, URL, ...) space (id, website_id, ...) ad_space_count
我在 java 中有一个无状态服务,部署在 tomcat 网络服务器中,我还配置了 2 路 ssl 验证。到目前为止,一切正常。当我有一个新客户端时,我只需要将新客户端证书放入我的 trustore
我已经创建了一个带有证书的信任库和带有私钥的 keystore 。我已经放置了以下代码,加载了 trsustore 管理器和 keystore 管理器,然后创建了 SSL 上下文的实例。 每当我向网络
如果我在仅服务器身份验证中正确理解 SSL/TLS,握手后,服务器会向客户端发送它的公钥和由 CA 签名的数字签名证书。如果客户端有这个 CA 的公钥,它就可以解密证书并与服务器建立信任。如果它不信任
我有 Nginx,它使用双向 TLS 代理从客户端到 IBM DataPower 的请求。 从 Nginx 向 IBM DP 发送消息时出现错误:sll server (SERVER) ssl pee
我刚刚开始了一个项目,让我的雇主成为一个管理软件。我有一个琐碎但可能很简单的查询,我似乎找不到任何相关信息。 在对象之间建立“具有”关系的两种方式是否谨慎/良好做法。例如,Client 对象“有一个”
我在设置双向 SSL 身份验证时遇到问题。 我需要从 wso2 企业集成商访问 HTTPS 端点。 服务提供商给了我一个 pfx keystore ,其中包含我必须提供给服务器的证书和私钥。 我在我的
我正在为小型 PoC 构建 AWS Lambda 服务。 PoC 中的流程是: 通过 POST 获取(文本)输入, 执行小字符串操作 + 将操纵值存储到 DynamoDB 中,然后 通过 HTTP P
我的任务是在 Java 上下文中实现双向 TLS。我找到了一个示例 ( https://www.opencodez.com/java/implement-2-way-authentication-us
我正在尝试测试一个非常简单的双向 IM 应用程序。客户端在 android 上,服务器在我的 PC(java)上。我已经在 PC 到 PC 之间用 java 测试了这个应用程序,它工作正常。 但是在我
我有 java web 服务支持2-way ssl auth。所以我有客户端 keystore (client.p12),服务器证书在受信任的存储区中,服务器 keystore 中的客户端证书在受信任
通过 HTTPS 使用 Web 服务 我们有一个我们正在使用的网络服务。 Webservice 可以在 HTTP 和 HTTPS 协议(protocol)上运行。使用 HTTP 没问题,但如何使用 H
我在 Node.js 上有一个后端服务器,我正在尝试在 Nginx 和这个后端服务器之间设置 2 路 SSL。 但是我得到一个错误:2015/11/02 06:51:02 [错误] 12840#128
我一直在尝试连接到启用了 2 路 SSL 的服务端点。我正在使用 Spring resttemplate。我已将证书添加到 keystore 中,但出现以下错误: >org.springframewo
从 CherryPy 3.0 开始,只需指向服务器证书和私钥即可启用单向 SSL,如下所示: import cherrypy class HelloWorld(object): def ind
这个问题来自:MySQL Number of Days inside a DateRange, inside a month (Booking Table) 我有一个包含以下数据的表: CREATE
我是一名优秀的程序员,十分优秀!