【发布时间】:2012-03-31 20:25:51
【问题描述】:
我一直在从事 Java Swing 项目,我需要检索创建面板的对象/实例,以便调用特定于该实例的简单保存方法。
您有一个带有 JTabbedPane 的 JFrame,该 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.
}
【问题讨论】:
-
我认为,为了获得最佳的具体帮助,您需要告诉我们您当前代码的更多详细信息。您是否使用代码生成软件来创建 GUI,例如 NetBean 的 gui creator?
-
不,我正在手工制作,以便更好地了解 Java 和 Swing。