<< Chapter < Page Chapter >> Page >

The screen output from the program is shown in Figure 1 .

Figure 1 Screen output from the program named VectorAdd01.

Missing image.

You will recall that the game-math library represents a Vector object graphically as a straight line with a small circle at the head. Thus, there arefive vectors drawn in Figure 1 . I will explain the meaning of the output in conjunction with the explanation of the program.

Beginning of the program named VectorAdd01

Listing 4 shows the entire class named VectorAdd01 along with the beginning of the class named GUI including the constructor for the GUI class.

Listing 4 . Beginning of the program named VectorAdd01.

class VectorAdd01{ public static void main(String[]args){ GUI guiObj = new GUI();}//end main }//end controlling class VectorAdd01//======================================================// class GUI extends JFrame{//Specify the horizontal and vertical size of a JFrame // object.int hSize = 275; int vSize = 200;Image osi;//an off-screen image int osiWidth;//off-screen image widthint osiHeight;//off-screen image height MyCanvas myCanvas;//a subclass of CanvasGUI(){//constructor//Set JFrame size, title, and close operation. setSize(hSize,vSize);setTitle("Copyright 2008,Baldwin"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//Create a new drawing canvas and add it to the// center of the JFrame. myCanvas = new MyCanvas();this.getContentPane().add(myCanvas);//This object must be visible before you can get an // off-screen image. It must also be visible before// you can compute the size of the canvas. setVisible(true);osiWidth = myCanvas.getWidth(); osiHeight = myCanvas.getHeight();//Create an off-screen image and get a graphics // context on it.osi = createImage(osiWidth,osiHeight); Graphics2D g2D = (Graphics2D)(osi.getGraphics());//Draw some graphical objects on the off-screen// image that represent underlying data objects in // 2D space.drawOffScreen(g2D); //Cause the overridden paint method belonging to// myCanvas to be executed. myCanvas.repaint();}//end constructor

Very familiar code

The code in Listing 4 is very similar to code that I explained in the earlier module titled GAME 2302-0110: Updating the Math Library for Graphics . Therefore, I won't explain that code again in this module.

This code is mainly needed to get everything set up for graphics.

Note that the code in Listing 4 makes a call to the method named drawOffScreen near the end of the listing. That is where we find the interesting code.

Beginning of the method named drawOffScreen

The beginning of the drawOffScreen method is shown in Listing 5 .

The purpose of this method is to add some Vector objects and to cause visual manifestations of the raw Vector objects and the resultant Vector objects to be drawn onto an off-screen image.

Listing 5 . Beginning of the method named drawOffScreen.
void drawOffScreen(Graphics2D g2D){ setCoordinateFrame(g2D);

Listing 5 begins by calling the method named setCoordinateFrame , which is shown in its entirety in Listing 6 . I will put the discussion of the drawOffScreen method on hold while I explain the method named setCoordinateFrame .

Questions & Answers

what is mutation
Janga Reply
what is a cell
Sifune Reply
how is urine form
Sifune
what is antagonism?
mahase Reply
classification of plants, gymnosperm features.
Linsy Reply
what is the features of gymnosperm
Linsy
how many types of solid did we have
Samuel Reply
what is an ionic bond
Samuel
What is Atoms
Daprince Reply
what is fallopian tube
Merolyn
what is bladder
Merolyn
what's bulbourethral gland
Eduek Reply
urine is formed in the nephron of the renal medulla in the kidney. It starts from filtration, then selective reabsorption and finally secretion
onuoha Reply
State the evolution relation and relevance between endoplasmic reticulum and cytoskeleton as it relates to cell.
Jeremiah
what is heart
Konadu Reply
how is urine formed in human
Konadu
how is urine formed in human
Rahma
what is the diference between a cavity and a canal
Pelagie Reply
what is the causative agent of malaria
Diamond
malaria is caused by an insect called mosquito.
Naomi
Malaria is cause by female anopheles mosquito
Isaac
Malaria is caused by plasmodium Female anopheles mosquitoe is d carrier
Olalekan
a canal is more needed in a root but a cavity is a bad effect
Commander
what are pathogens
Don Reply
In biology, a pathogen (Greek: πάθος pathos "suffering", "passion" and -γενής -genēs "producer of") in the oldest and broadest sense, is anything that can produce disease. A pathogen may also be referred to as an infectious agent, or simply a germ. The term pathogen came into use in the 1880s.[1][2
Zainab
A virus
Commander
Definition of respiration
Muhsin Reply
respiration is the process in which we breath in oxygen and breath out carbon dioxide
Achor
how are lungs work
Commander
where does digestion begins
Achiri Reply
in the mouth
EZEKIEL
what are the functions of follicle stimulating harmones?
Rashima Reply
stimulates the follicle to release the mature ovum into the oviduct
Davonte
what are the functions of Endocrine and pituitary gland
Chinaza
endocrine secrete hormone and regulate body process
Achor
while pituitary gland is an example of endocrine system and it's found in the Brain
Achor
what's biology?
Egbodo Reply
Biology is the study of living organisms, divided into many specialized field that cover their morphology, physiology,anatomy, behaviour,origin and distribution.
Lisah
biology is the study of life.
Alfreda
Biology is the study of how living organisms live and survive in a specific environment
Sifune
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, Game 2302 - mathematical applications for game development. OpenStax CNX. Jan 09, 2016 Download for free at https://legacy.cnx.org/content/col11450/1.33
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Game 2302 - mathematical applications for game development' conversation and receive update notifications?

Ask