- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这基本上创建了一个按钮的网格布局,设计为使用多个类的体育场。我在另一个类中使用此类,该类创建相同的面板以及 jtextfields 来显示价格、行、部分等。每当用户将鼠标悬停在按钮上时,它就会用有关该座位的信息填充 jtextfields。但是,一旦鼠标进入任何一个按钮,每次输入新按钮时我都会收到此错误:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at StadiumPanel.mouseEntered(StadiumPanel.java:72)
at java.awt.AWTEventMulticaster.mouseEntered(AWTEventMulticaster.java:300)
at java.awt.Component.processMouseEvent(Component.java:6514)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3320)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.trackMouseEnterExit(Container.java:4620)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4474)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
这是我的类(class):
import javax.swing.*;
import java.awt.*;
import java.awt.Color;
import java.awt.event.*;
import javax.swing.border.LineBorder;
public class StadiumPanel extends BoardPanel implements MouseListener {
public Seat[][] seatButtons;
SeatInfo sI;
public int priceFinal;
public int secFinal;
public int rowFinal;
public int numFinal;
public StadiumPanel(Stadium s) {
Seat[][] seatButtons = s.getSeats();
setLayout(new GridLayout(27,35));
setBorder(new LineBorder(Color.BLACK, 1));
setBackground(Color.WHITE);
for (int r=0; r<27; r++) {
for (int c=0; c<35; c++) {
if (seatButtons[r][c] != null) {
if (seatButtons[r][c].getSection() == 1) {
JButton b = new JButton();
b.setBackground(Color.red);
b.addMouseListener(this);
add(b);
}
else if (seatButtons[r][c].getSection() == 2) {
JButton b = new JButton();
b.setBackground(Color.green);
b.addMouseListener(this);
add(b);
}
else if (seatButtons[r][c].getSection() == 3) {
JButton b = new JButton();
b.setBackground(Color.blue);
b.addMouseListener(this);
add(b);
}
else if (seatButtons[r][c].getSection() == 4) {
JButton b = new JButton();
b.setBackground(Color.yellow);
b.addMouseListener(this);
add(b);
}
}
else if (seatButtons[r][c] == null) {
JLabel b = new JLabel();
b.setBackground(Color.white);
add(b);
}
}
}
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
for (int r=0; r<27; r++) {
for (int c=0; c<35; c++) {
if ((e.getSource() == seatButtons[r][c]) && (seatButtons[r][c] != null)) {
priceFinal = seatButtons[r][c].getPrice();
secFinal = seatButtons[r][c].getSection();
rowFinal = seatButtons[r][c].getRow();
numFinal = seatButtons[r][c].getNumber();
sI.setPrice(String.valueOf(priceFinal));
sI.setRow(String.valueOf(rowFinal));
sI.setSec(String.valueOf(secFinal));
sI.setNum(String.valueOf(numFinal));
sI.updateText();
}
}
}
}
public void mouseExited(MouseEvent e) {
}
public void mouseClicked(MouseEvent e) {
}
public static void main(String args[]) {
JFrame f = new JFrame("Stadium Panel Test");
f.getContentPane().add(new StadiumPanel(new Stadium()));
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(649, 500);
f.setVisible(true);
}
}
最佳答案
在构造函数中,您仅使用局部变量。您永远不会使用或填充类中的字段 Field Seat[][] SeatButtons
。您尝试在鼠标事件中使用它,但它是“null”。
关于java - mouseEntered(MouseEvent e) 上线程 "AWT-EventQueue-0"java.lang.NullPointerException 中出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22284846/
我正在用 typescript 编写一个 react 应用程序,我试图同时处理右键单击和左键单击。 这是我的界面 interface ButtonProps { value: CellValu
在 Intellij 诉 2018.3.2 中。每次将 $event 传递给方法时,我都会收到此错误。 在模板中我有: {{ header }} 然后在类里面: public toggle(event
我的棋盘游戏取得进展,因此只需单击鼠标,就会执行一些任务,例如播放一些动画、接收棋盘的新 Pane (我问了我的最后一个问题,现在效果很好)、对玩家进行更改数据等 所以,这是我的事件处理程序 grid
我正在使用 Haxe+OpenFL 制作游戏。我之前曾针对 js,然后我切换到 neko,以下构造停止工作: if(e.shiftKey) do smth Ofc 自更改目标以来,我没有更改此代码
SwingUtilities 包有一个很好的函数 convertMouseEvent,可以将一个组件上的鼠标事件转换为另一个组件上的鼠标事件: MouseEvent convertedEvent =
这看起来很简单,但我无法处理这个问题我总是在控制台中收到相同的消息: Type error: Type '(event: MouseEvent) => void' is not assignable
我发生了什么事,你能告诉我2做了什么吗? 我正在创建一个需要钩子(Hook)来替换状态的网站。我在我的index.js 上。错误发生在菜单内 div 内的 onClicks 上。菜单来自materia
我正在尝试使用 openCVsharp 方法在 c# 中获取鼠标位置并在 c# 中打开窗口。 首先我定义一个回调函数: public void mc(MouseEvent me, int x, int
我正在处理一个正在编写的程序,我需要能够检测鼠标何时离开窗口/ Canvas 。但是,据我所知,处理没有任何类似于 mouseOut 事件的内容。有什么方法可以使用回调或事件或类似性质的东西来完成此任
我正在编写一个正在处理的程序,我需要能够检测鼠标何时离开窗口/ Canvas 。然而,据我所知,processing 没有任何类似于 mouseOut 事件的东西。有什么方法可以使用回调或事件或类似性
Visual Studio Code 显示目标变量是 EventTarget输入以下 TypeScript 代码: document.addEventListener('click', (event)
如果尝试在QML定义的信号中将MouseEvent用作arg,则在加载时会出现以下错误: Invalid signal parameter type: MouseEvent Qt文档中与此有关的信息存
是否可以在Openlayer3上获得鼠标右键单击事件?如果是这样,我如何获得右键单击位置的纬度和经度。 我通过以下方式获得了右键单击事件 map.getViewport().addEventListe
我希望在 Gtk::DrawableArea 上使用 mouseevents 画一条线。我想要的是这样的: 点击线路按钮激活线路事件 选择绘图区域中的第一个点(已绘制) 现在选择绘图区域中的第二个点(
程序涉及到EventHandlers和MouseEvents的应用。该程序的目标是呈现一个空白场景,用户可以左键单击(主要)并向事件发生时鼠标所在的场景添加一个圆形对象。可以添加的圈数无关紧要。当用户
我正在尝试为单元测试创建带有某些修饰符的 MouseEvent。我使用的是 J2SE,以下代码无法通过: public void testMouseEventProblem() { Mouse
我有一个使用自己的 AS3 类构建的菜单,当单击此菜单中的链接时,它会根据从外部 XML 文件传入的一些变量触发一个函数。 菜单由四个小节组成,我希望用户能够从与该菜单完全分开的按钮跳转到该小节的父级
我有两个相交的矩形。当鼠标悬停在它们上方时,我希望两者的不透明度都发生变化。当鼠标悬停在其中一个上时它会起作用。但是当鼠标在矩形的交叉区域时,只有上面的矩形改变了它的不透明度。你能告诉我在这种情况下如
这是带有行单击的 JavaFX 表的基本示例: public class MainApp extends Application { private TableView table =
标题设法提出了大部分问题,但是,我很好奇使用 LMB 单击的哪一部分会触发视觉突出显示。 我所说的视觉突出显示是蓝色框(如果您使用默认设置),它显示您选择的文本,以便您可以看到它。据我所知,实际的选择
我是一名优秀的程序员,十分优秀!