当前位置:   article > 正文

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

《java语言程序设计》(基础篇原书第10版)第十五章复习题答案

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

Chapter15Graphics

1. Theycoordinateshouldincreaseandthexcoordinateshouldremainunchanged.

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 Graphics object for the component on the

native platform and passes this object to invoke the

paintComponent method to display the drawings.

3. ThepaintComponent()methodisdefinedintheComponentclass.TheJava

runtimesysteminvokesittopaintthingsonaSwingGUIcomponent.This

methodcannotbeinvokedbythesystemorbytheprogrammer.Thesystem

automaticallyinvokesitwhenevertheviewingareachanges.Theprogrammer

invokesitthroughinvokingtherepaint()method.Theprogrammershouldnever

directlyinvokethepaintComponent()method.

4. ThepaintComponent()methodisprotected,because(1)thismethodisalways

invokedbytheJVM,notbyaclientprogram;(2)theclientprogramneedto

overrideitinasubclass.

Ifitischangedtopublic,itisOK,butnotnecessary,becausetheprotected

modifierissufficient.

Itcannotbechangedtoprivate,becausethevisibilitycannotbeweakened.

super.paintComponent(g)invokesthesuperclass’spaintComponentmethod.In

Line 12inListing 12.2,itcausesthetextofthelabeltobepaintedfirst.Before

thistextisdisplayed,theJLabel’spaintComponent(g)methodactuallyinvokes

super.paintComponent(g)tocleartheviewingarea.InLine20inListing 12.3,it

causestheviewingareatobecleared.

5. Yes.YoushoulddeclareacustomcanvasbysubclassingJPanelratherthan

subclassingJLabelorJButton,becauselabelsaredesignedfor

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Guff_9hys/article/detail/798226
推荐阅读
相关标签
  

闽ICP备14008679号