Thoker
Thoker

Reputation: 100

method create multiple panels

How can I create multiple panels in a jframe with a method. I want to give the method a number and then the method shall create this amount of Jpanels. Is there any way how I can do this automatically, because I have to create over 100 Panels

Upvotes: 0

Views: 187

Answers (1)

Arthur
Arthur

Reputation: 1246

Usually if you want to perform an action over an over again you would use a loop. In this case I think it would be best that you use a for loop.

public void addJPanelsToJFrame(JFrame frame, int panels){
    for (int q = 0; q < panels; q++){
        frame.add(new JPanel());
    }
}

Upvotes: 1

Related Questions