28.12.2012 Views

Core JFC Java Foundation Classes 2nd edition - Read

Core JFC Java Foundation Classes 2nd edition - Read

Core JFC Java Foundation Classes 2nd edition - Read

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Images on Components: Icons 59<br />

Creating a frame and making it visible are very simple tasks in <strong>Java</strong>. It can<br />

be done as easily as this:<br />

package <strong>JFC</strong>Book.Chapter2;<br />

import j avax.swing.*;<br />

public class BasicFrame {<br />

public static void main(String [] args) {<br />

JFrame f = new JFrame("Simple Frame");<br />

f.setSize(250, 200);<br />

f.setvisible(true) ;<br />

}<br />

}<br />

Running this trivial program under Windows, using the command<br />

<strong>Java</strong> <strong>JFC</strong>Book.Chapter2.BasicFrame<br />

produces the result shown in Figure 2-2.<br />

Figure 2-2 The Swing JFrame.<br />

The string that is supplied to the constructor is used as the frame s caption.<br />

Alongside it on the caption bar are the minimize, maximize and cZo.se buttons<br />

that top-level windows usually have. If you try the minimize and maximize<br />

buttons, you will find that they both work as you expect—the minimize but-

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!