<< Chapter < Page Chapter >> Page >

What if it doesn't fit?

If the new Picture object isn't large enough to completely fill the area inside the borders of the World object, it will be placed in the upper-left corner of the World object and the remainder of the World object will be a light gray color.

If the Picture object is too large, an upper-left rectangular portion of the Picture object, sufficient to fill the World object, will be displayed. The remainder of the Picture object will not be visible even if you manually resize the World object to make it larger.

Constructors for the Picture class

Figure 6 shows the javadocs for the constructors for Ericson's Picture class.

Figure 6 - Constructors for the Picture class.

Screen shot of constructor documentation.

Replace the default picture object

The right-hand portion of the last statement in Listing 5 uses the last constructor in Figure 6 to instantiate a new Picture object that encapsulates the image contained in the image file named Prob01.jpg .

(Click here to download a copy of the file named Prob01.jpg.)

What about the size of the Picture object?

I was careful to use an image that was a little wider than and exactly as tall as the dimensions of my World object (300 x 274) . Therefore, the image completely filled the world as shown in Figure 1 .

Pass the reference to a setter method

The reference belonging to the new Picture object was passed to the setPicture method of the World object (a setter method) in Listing 5. This caused the new picture containing the penguin to replace the default all-white picture thatforms the background for the World object. (See Figure 1 .)

A subclass of the SimplePicture class

Ericson's Picture class is a subclass of (extends) the class named SimplePicture . Therefore, an object of the Picture class encapsulates all of the methods defined in the Picture class in addition to all of the methods defined in the SimplePicture class.

A subclass of the Object class

Further, the SimplePicture class is a subclass of (extends) the Object class. Therefore, an object of the Picture class also encapsulates all of the methods defined in the Object class.

The AddMessage method

One of the methods defined in the SimplePicture class and inherited into the Picture class is named AddMessage .

The addMessage method requires three parameters:

  • a string and
  • two coordinate values of type int .

The addMessage method will draw the string as text characters onto the image at the location specified by the two coordinate values.

(The origin of the coordinate system is the upper-left corner of the image with positive horizontal values going to the right and positive verticalvalues going down.)

Add text to the image

The code in Listing 6 uses two levels of indirection to add my name as a message to the picture that forms the background of the world as shown in Figure 1 .

Listing 6 . Add text to the image.
mars.getPicture().addMessage( "Dick Baldwin",10,20);

Get and access the World object

To begin with, Listing 6 goes to the variable named mars to get a reference to the World object. This reference is used to access the World object.

Access the Picture object via a getter method

Questions & Answers

what is defense mechanism
Chinaza Reply
what is defense mechanisms
Chinaza
I'm interested in biological psychology and cognitive psychology
Tanya Reply
what does preconceived mean
sammie Reply
physiological Psychology
Nwosu Reply
How can I develope my cognitive domain
Amanyire Reply
why is communication effective
Dakolo Reply
Communication is effective because it allows individuals to share ideas, thoughts, and information with others.
effective communication can lead to improved outcomes in various settings, including personal relationships, business environments, and educational settings. By communicating effectively, individuals can negotiate effectively, solve problems collaboratively, and work towards common goals.
it starts up serve and return practice/assessments.it helps find voice talking therapy also assessments through relaxed conversation.
miss
Every time someone flushes a toilet in the apartment building, the person begins to jumb back automatically after hearing the flush, before the water temperature changes. Identify the types of learning, if it is classical conditioning identify the NS, UCS, CS and CR. If it is operant conditioning, identify the type of consequence positive reinforcement, negative reinforcement or punishment
Wekolamo Reply
please i need answer
Wekolamo
because it helps many people around the world to understand how to interact with other people and understand them well, for example at work (job).
Manix Reply
Agreed 👍 There are many parts of our brains and behaviors, we really need to get to know. Blessings for everyone and happy Sunday!
ARC
A child is a member of community not society elucidate ?
JESSY Reply
Isn't practices worldwide, be it psychology, be it science. isn't much just a false belief of control over something the mind cannot truly comprehend?
Simon Reply
compare and contrast skinner's perspective on personality development on freud
namakula Reply
Skinner skipped the whole unconscious phenomenon and rather emphasized on classical conditioning
war
explain how nature and nurture affect the development and later the productivity of an individual.
Amesalu Reply
nature is an hereditary factor while nurture is an environmental factor which constitute an individual personality. so if an individual's parent has a deviant behavior and was also brought up in an deviant environment, observation of the behavior and the inborn trait we make the individual deviant.
Samuel
I am taking this course because I am hoping that I could somehow learn more about my chosen field of interest and due to the fact that being a PsyD really ignites my passion as an individual the more I hope to learn about developing and literally explore the complexity of my critical thinking skills
Zyryn Reply
good👍
Jonathan
and having a good philosophy of the world is like a sandwich and a peanut butter 👍
Jonathan
generally amnesi how long yrs memory loss
Kelu Reply
interpersonal relationships
Abdulfatai Reply
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Object-oriented programming (oop) with java. OpenStax CNX. Jun 29, 2016 Download for free at https://legacy.cnx.org/content/col11441/1.201
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?

Ask