2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > java语言程序设计基础篇课后答案_《Java语言程序设计:基础篇》课后复习题答案-第十五

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

时间:2020-11-27 01:34:33

相关推荐

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

《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

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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。