《Java语言程序设计:基础篇》课后复习题答案-第十五章.

更新时间:2023-07-23 03:59:03 阅读: 评论:0

Chapter 15Graphics
1. The y coordinate should increa and the x coordinate should remain unchanged.
2. The Graphics class–an abstract class—provides a
device-independent graphics interface for displaying figures and images on the screen on different
platforms. Whenever a component (e.g.,a button, a label, a panel is displayed, the JVM automatically creates a object for the component on the native platform and pass this object to invoke the paintComponent method to display the drawings.
3. The paintComponent(method is defined in the Component class. The Java runtime system invokes it to paint things on a Swing GUI component. This method cannot be invoked by the system or by the programmer. The system automatically invokes it whenever the viewing area changes. The programmer invokes it through invoking the repaint(method. The programmer should never directly invoke the paintComponent(method.
乱了流年
4. The paintComponent(method is protected, becau (1this method is always invoked by the JVM, not by a client program; (2the client program need to override it in a subclass.
If it is changed to public, it is OK, but not necessary, becau the protected modifier is sufficient.
蒋欣图片天气预报pptIt cannot be changed to private, becau the visibility cannot be weakened. super.paintComponent(ginvokes the superclass’s paintComponent method. In Line 12in Listing 12.2, it caus the text of the label to be painted first. Before this text is displayed, the JLabel’s paintComponent(gmethod actually invokes super.paintComponent(gto clear the viewing area. In Line 20in Listing 12.3, it caus the viewing area to be cleared.
5. Yes. You should declare a custom canvas by subclassing JPanel rather than subclassing JLabel or JButton, becau labels are designed for the purpo to display a label or and buttons are for showing a push button.
6. See the Sections 12.6, 12.8, and 12.9.
7. See the Sections 12.6, 12.8, and 12.9.
8. You can u the tColor(Colorto t a color in the graphics context and u the tFont(Fontmethod to t a font in the graphics context.
9. Draw a thick line from (10,10 to (70,30. You must draw veral lines next to each other to create the effect of one thick line.
Answer:
for (inti =0; i <10; i++
g.drawLine(10,10+i, 70, 30+i;
Draw/filla rectangle of width 100and height 50with the upper-left corner at (10, 10.
Answer:
观察昆虫的日记
g.drawRect(10,10, 100, 50;
g.fillRect(10,10, 100, 50;
冬天的花有哪些Draw/filla rounded rectangle with width 100, height 200, corner horizontal diameter 40, and corner vertical diameter 20.
Answer:
g.drawRoundRect(10,10, 100, 200, 40, 20;
g.fillRoundRect(10,10, 100, 200, 40, 20;
Draw/filla circle with radius 30.
Answer:接吻节
g.drawOval(10,10, 60, 60;
g.fillOval(10,10, 60, 60;
Draw an oval with width 50and height 100.最新冷笑话
Answer:
g.drawOval(10,1050, 100;
Draw the upper half of a circle with radius 50.
Answer:
g.drawArc(10,10, 100, 100, 0, 180;
Draw a polygon connecting the following points:(20,40, (30,50, (40,90, (90, 10, (10,30.
Answer:
int x[]={20,30, 40, 90, 10};
int y[]={40,50, 90, 10, 30};
g.drawPolygon(x,y, x.length;
g.fillPolygon(x,y, x.length;
10. First obtain the FontMetrics for a font ud in the Graphics context using
g.getFontMetrics(FontMetrics(Font.You can then u the FontMetrics’s getAscent(,getDescent(,getLeading(,getHeight(methods to obtain the font’s
ascent, descent, leading, and height. U getWidth(Stringto obtain the string width for the font.
11. When you create a MessagePanel, its paintComponent method is invoked. Since message is null, invoking g.drawString(message,xCoordinate, yCoordinate caus a NullPointerException.
12. Two errors:(1constructor TestDrawMessage cannot have void. (2
PaintComponent should be paintComponent.
13. Image(.
14. U new ImageIcon(image.
复习用英语怎么说
15. The drawImage(...method displays the image on the viewing area. 16. An image displayed on a label is non-stretchable, but an image displayed on a panel is stretchable.
17. The images cannot be stretched in JLabel. The images can be stretched in JPanel.

本文发布于:2023-07-23 03:59:03,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1092857.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:观察   昆虫   日记
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图