user3341016
user3341016

Reputation:

Naming a JFrame after a String variable

when you create a new JFrame you simply type:

    JFrame x = new JFrame();

And what I wonder is if there is a name to create a JFrame where "x = a String" Here is a snippet of my code:

    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);

    }

This should then be called from another place with this command example:

createWindow(Name, Title, 200, 200);

and make a JFrame, but how do I input the 'Name' variable into x?

Upvotes: 1

Views: 187

Answers (1)

SMA
SMA

Reputation: 37033

One way you could work this out is using map. So if say i want multiple frame names then what i could do is:

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

Upvotes: 1

Related Questions