If you change frame.setSize(150, 100)
to
frame.setSize(300, 100)
how will the frame appear?
The frame will be 300 pixels wide by 100 high, twice as wide as previous.
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( WindowConstants.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.
Is it possible to define a class that uses JFrame
as a base (a parent) class?