EE408 Lab 3: Further Exploring JFrame and JavaDoc


1%

Due: 5 PM, Friday September 12.


Create a Java project in Eclipse to display a JFrame on screen. Use this project as the starting point for the following exercises.


1. Add a label to the center of the JFrame by calling

JLabel label = new JLabel("Welcome to EE408.");
frame.add(label);

Set the size of your frame to 200x300 by calling

frame.setSize(new Dimension(200,300));

You may have noticed that there is another setSize() that takes two int as parameters. This is an example of overloading - the name setSize is used by two different methods.

Move the frame to the center of the computer screen. Suppose the width and height of the computer screen are WxH in pixels. This can be accomplished by calling

frame.setLocation((W-200)/2, (H-300)/2); or

frame.setLocation(new Dimension((W-200)/2, (H-300)/2));

The screen size can be found out using the following code:

Toolkit toolkit = frame.getToolkit();
Dimension d = toolkit.getScreenSize();


2. In general, one way to to understand a class better is to study its JavaDoc.

Search online for the JavaDoc for JFrame in a web browser (using the keywords "JFrame 1.6" because there are multiple releases of JavaDoc for JFrame, but we need to study the latest version, 1.6).

Browse through the JFrame JavaDoc and pay particular attention to the following main elements contained in it:

package name
class name
superclasses (from oldest to youngest)
a list of interfaces this class implements
a list of subclasses of this class

a summary description of this class
a table of Field Summary
a table of Constructor Summary
a table of Method Summary (sorted alphabetically)

detailed specifications for Field, Constructor, and Method.

Find the two constructors we used in class.

Are there any methods in JFrame we used? If no, in which classes are methods like setSize(), setLocation(), and getToolkit() defined? Why does it work this way?


3. Step 1 introduces 3 new classes Toolkit, Dimension, and JLabel. Find out to which packages these three classes belong.


Demonstrate to me once you are done with these exercises so that I can grade.

Have a good weekend.