Tag: parent

访问容器字段

我有一个非常愚蠢的问题要问。 我正在使用NetBeans构建一个小应用程序,我遇到了以下问题; 我的主类叫做mainApp ,正在扩展一个JFrame ,后者又包含一个名为drawingBoard的JPanel ,我也会因为各种(和偏离主题)的原因而扩展。 核心问题是,在某些时候我需要访问mainApp一个字段,但是由于NetBeans实例化我的主类的方式..(作为匿名类)我无法获得对容器的引用(这是我的mainApp)。 如何获取mainApp的引用并在mainApp设置其字段的值?

请求java中有关jlabel和parent的一些说明

在互联网上发现这个代码,它是在几年前发布的,所以我决定在这里要求澄清一些我不太了解的行。 在mousePressed方法中,他的意思是: chessPiece = null他说如果JLabel chessPiece有一个图像,那么它应该被改为null ? chessBoard.findComponentAt(e.getX(), e.getY())返回JPanel方块? 最后,当Component c获得其父级时,谁是父级? 整个代码如下: public class ChessGameDemo extends JFrame implements MouseListener, MouseMotionListener { JLayeredPane layeredPane; JPanel chessBoard; JLabel chessPiece; int xAdjustment; int yAdjustment; private static final String imageFolderPath = “src/resources/images/”; public ChessGameDemo() { Dimension boardSize = new Dimension(600, 600); // Use a Layered Pane for this this […]