Page 723 - Introduction to Programming with Java: A Problem Solving Approach
P. 723

                Exercises
1. [after §16.2] Give three examples of how a user might cause an event to be fired.
2. [after §16.3] For each of the following, what Java API package must you import? a) JFrame and JLabel
b) FlowLayout
3. [after §16.4] For our previous GUI programs, we’ve done set-up work (setting the title, adding components, and so on) within a constructor. That’s generally preferred, but it’s not a compiler requirement. For practice purposes, write a minimal, but fully functional, program that displays this:
Your program should not include a constructor. It should include only one method—a main method with only five statements (or four statements if you find a shortcut for setting the frame’s title).
4. [after §16.6] Provide a complete program that displays this Hello World message:
          Apago PDF Enhancer
Note these label characteristics: (1) raised bevel border, (2) italics, (3) large font size (30 points), (4) tool tip that says “Life is Great!” Use this program skeleton as a starting point:
//**********************************************************
public class BigHello extends JFrame
{
public BigHello()
{
}
JLabel label = <instantiation> ; setSize(200, <height> ); setLayout(new FlowLayout()); add(label);
<3-statement code fragment> setVisible(true);
// end constructor
//**********************************************************
public static void main(String[] args)
Exercises 689
   import javax.swing.*;
import java.awt.*;












































































   721   722   723   724   725