13.1 | Suppose that you want to draw a new message below an existing message. Should the x, y coordinate increase or decrease? |
13.2 | Why does jlblBanner.getGraphics() in line 9 in Listing 13.1 return null ? What is the reason for showing the message dialog box in line 19 in Listing 13.1? In line 9, jlblBanner.getGraphics() is used to return a Graphics object. In line 21, why do you have to use frame.jlblBanner.getGraphics() in the main method? |
13.3 | Describe the paintComponent method. Where is it defined? How is it invoked? Can it be directly invoked? Can the program cause this method to be invoked? |
13.4 | Why is the paintComponent method protected? What happens if you change it to public or private in a subclass? Why is super.paintComponent(g) invoked in line 25 in Listing 13.2 and in line 21 in Listing 13.3? |
13.5 | Can you draw things on any Swing GUI component? Why should you use a panel as a canvas for drawings rather than a label or a button? |
13.6 | Describe the methods for drawing strings, lines, rectangles, round-cornered rectangles, 3D rectangles, ovals, arcs, polygons, and polylines. |
13.7 | Describe the methods for filling rectangles, round-cornered rectangle, ovals, arcs, and polygons. |
13.8 | How do you get and set colors and fonts in a Graphics object? |
13.9 | Write a statement to draw the following shapes :
|
13.10 | How do you find the leading, ascent, descent, and height of a font? How do you find the exact length of a string in a Graphics object? |
13.11 | If message is not initialized in line 8 in Listing 13.9, MessagePanel.java, what would happen when you create a MessagePanel using its no-arg constructor? |
13.12 | The following program is supposed to display a message on the panel, but nothing is displayed. There are problems in lines 2 and 14. Identify them. 1 public class TestDrawMessage extends javax.swing.JFrame { 2 public void TestDrawMessage() { 3 add( new DrawMessage()); 4 } 5 6 public static void main(String[] args) { 7 javax.swing.JFrame frame = new TestDrawMessage(); 8 frame.setSize( 100 , 200 ); 9 frame.setVisible( true ); 10 } 11 } 12 13 class DrawMessage extends javax.swing.JPanel { 14 protected void PaintComponent(java.awt.Graphics g) { 15 super .paintComponent(g); 16 g.drawString("Welcome to Java", 20 , 20 ); 17 } 18 } |
13.13 | How do you create an Image object from the ImageIcon object? |
13.14 | How do you create an ImageIcon object from an Image object? |
13.15 | Describe the drawImage method in the Graphics class. |
13.16 | Explain the differences between displaying images in a JLabel and in a JPanel . |
13.17 | Which package contains ImageIcon , and which contains Image ? |