15.4. Radio Buttons

 
[Page 456 ( continued )]

Review Questions

Sections 13.2 “13.3

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?

Sections 13.4 “13.5

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?

Sections 13.6 “13.9

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 :
  • Draw a thick line from ( 10 , 10 ) to ( 70 , 30 ). You can draw several lines next to each other to create the effect of one thick line.

  • Draw/fill a rectangle of width 100 and height 50 with the upper-left corner at ( 10 , 10 ).

  • Draw/fill a round-cornered rectangle with width 100 , height 200 , corner horizontal diameter 40 , and corner vertical diameter 20 .

  • Draw/fill a circle with radius 30 .


    [Page 457]
  • Draw/fill an oval with width 50 and height 100 .

  • Draw the upper half of a circle with radius 50 .

  • Draw/fill a polygon connecting the following points: ( 20 , 40 ), ( 30 , 50 ), ( 40 , 90 ), ( 90 , 10 ), ( 10 , 30 ).

  • Draw a 3-D cube like the one in Figure 13.26.

    Figure 13.26. Use the drawLine method to draw a 3-D cube.

Sections 13.10 “13.12

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  } 

Sections 13.13 “13.14

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 ?
 


Introduction to Java Programming-Comprehensive Version
Introduction to Java Programming-Comprehensive Version (6th Edition)
ISBN: B000ONFLUM
EAN: N/A
Year: 2004
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net