gpt4 book ai didi

java - 从 Java Swing 组件中检索对象

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:13:51 25 4
gpt4 key购买 nike

我一直致力于 Java Swing 项目,我需要检索创建面板的对象/实例,以便调用特定于该实例的简单保存方法。

您有一个带有 JTabbedPane 的 JFrame,它具有通过实例化一个构建 JPanel 并将其添加到 JTabbedPane 的类创建的选项卡,我需要从 JTabbedPane 上的选定 JPanel/选项卡中找到特定实例,然后调用它保存方法。

有什么想法吗?感谢您的宝贵时间!

public class frame extends JFrame implements ActionListener{
Builds a frame dubbed "frame" that is static.
Builds a static JTabbedPane dubbed "pane"and adds it to the frame.
Creates a button that creates a new instance of sheet.

public void actionPerformed(MAGIC!){
See if a button on the panel has been pressed and uses the currently selected tab to locate the correct instance of sheet to run it's save method.
}
}

public class sheet extends JPanel{
In constructor makes a JPanel and adds it to "pane"

Describes a save method that outputs a variable unique to the instance.
}

最佳答案

我发现我需要做的就是将新的选项卡对象存储在 ArrayList derp 中。感谢你们的尝试,虽然伙计们!

关于java - 从 Java Swing 组件中检索对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9959393/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com