go to previous page   go to home page   go to next page

If you change frame.setSize(150, 100)
to frame.setSize(300, 100) how will the frame appear?

Answer:

The frame will be 300 pixels wide by 100 high, twice as wide as previous.

Dimensions of a Frame

The setSize() method of JFrame changes the size of the frame on the computer monitor. The size can be changed as the program runs. For example, the following program works (although it is mostly useless):

import java.awt.*;
import javax.swing.*;

public class TestFrameExpand
{
  public static void main ( String[] args )
  {
    int height=100, width=200;
    JFrame frame = new JFrame("Test Frame Extra");

    frame.setVisible( true );
    frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

    for ( int extra=0; extra<500; extra+=1 )
      frame.setSize( width+extra, height+extra );
  }
}

The frame starts out with size 200 by 100, and then grows larger.

QUESTION 7:

Would it useful to say where on the monitor the frame appears?