Java Reference
In-Depth Information
Chapter Summary
You can define a window listener class by having it implement the WindowListener
interface.
An icon is an object of the class ImageIcon and is created from a digital picture. You
can add icons to JButton s , JLabel s, and JMenuItem s .
You can use the class JScrollPane to add scroll bars to a text area.
You can draw figures such as lines, ovals, and rectangles using methods in the
class Graphics .
You can use the method setColor to specify the color of each figure or text drawn
with the method of the class Graphics .
You can define your own colors using the class Color .
Colors are defined using the RGB (red/green/blue) system.
You can use the method drawString of the class Graphics to add text to a JFrame
or JPanel .
You can use the method setFont to set the font, style modifiers, and point size for
text written with the drawString method of the Graphics class.
Answers to Self-Test Exercises
1. All the methods in Display 18.1. If there is no particular action that you want the
method to perform, you can give the method an empty body.
2. The smaller window goes away but the larger window stays. This is the default
action for the close-window button and we did not change it for the smaller
window.
3. dispose
4. The import statements are the same as in Display 18.2. The rest of the definition follows.
This definition is in the file WindowListenerDemo3 on the accompanying website.
public class WindowListenerDemo3 extends JFrame
implements WindowListener
extra code
on website
{
public static final int WIDTH = 300; //for main window
public static final int HEIGHT = 200; //for main window
public static final int SMALL_WIDTH = 200;
//for confirm window
public static final int SMALL_HEIGHT = 100;
//for confirm window
private class ConfirmWindow extends JFrame
implements ActionListener
 
Search WWH ::




Custom Search