tags:

views:

426

answers:

1

In the JPanel program, I wrote this:

String size = JOptionPane.showInputDialog("What frame length?");
int s = Integer.parseInt(size);

and I use the s variable in the body of the code.

The problem is, I need to use the variable to also set the size of JFrame, and I don't know how to transfer the variable to that program.. Could I set the size inside the JPanel program?

EDIT: For JPanel, I created a Buffered Image and put a bunch of graphics on it. For the Jframe, all I did was I set the location and open the content pane for JPanel.

A: 

use SwingUtilities.getWindowAncestor

javax.swing.SwingUtilities.getWindowAncestor(yourpanel).setSize(
  new Dimension(size,size)
);
Pierre