在 String 变量之后命名 JFrame

Naming a JFrame after a String variable

当您创建一个新的 JFrame 时,您只需键入:

    JFrame x = new JFrame();

我想知道是否有一个名称可以在 "x = a String" 中创建 JFrame 这是我的代码片段:

    public static void createWindow(String name, String title, int width, int height) {

        JFrame x /*I want it to be name*/ = new JFrame();
        name.setTitle(title);
        name.setSize(width, height);
        name.setVisible(true);

    }

然后应该使用此命令示例从另一个地方调用它:

createWindow(Name, Title, 200, 200);

并制作一个 JFrame,但如何将 'Name' 变量输入到 x 中?

解决这个问题的一种方法是使用地图。因此,如果说我想要多个框架名称,那么我可以做的是:

Map<String, JFrame> map ..
map.put("myframe1", new JFrame..);
..
JFrame x = map.get(name);//this is what you could do in your method