<< Chapter < Page Chapter >> Page >

Listing 29 . Source code for the program named GM01test05.

/*GM01test05.java Copyright 2008, R.G.BaldwinRevised 02/24/08 This program illustrates vector addition in 3D.Tested using JDK 1.6 under WinXP. *********************************************************/import java.awt.*; import javax.swing.*;import java.awt.geom.*; class GM01test05{public static void main(String[] args){GUI guiObj = new GUI(); }//end main}//end controlling class GM01test05 //======================================================//class GUI extends JFrame{ //Specify the horizontal and vertical size of a JFrame// object. int hSize = 300;int vSize = 200; Image osi;//an off-screen imageint osiWidth;//off-screen image width int osiHeight;//off-screen image heightMyCanvas myCanvas;//a subclass of CanvasGUI(){//constructor //Set JFrame size, title, and close operation.setSize(hSize,vSize); setTitle("Copyright 2008,R.G.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 on the off-screen image. drawOffScreen(g2D);//Cause the overridden paint method belonging to // myCanvas to be executed.myCanvas.repaint(); }//end constructor//----------------------------------------------------// //The purpose of this method is to illustrate vector// addition in 3D void drawOffScreen(Graphics2D g2D){//Translate the origin on the off-screen image, draw a// pair of orthogonal axes on it that intersect at the // origin, and paint the background white.setCoordinateFrame(g2D);//Define two vectors that will be added. GM01.Vector3D vecA = new GM01.Vector3D(new GM01.ColMatrix3D(75,75,75));GM01.Vector3D vecB = new GM01.Vector3D( new GM01.ColMatrix3D(-15,10,-50));//Create a ref point at the origin for convenience.GM01.Point3D zeroPoint = new GM01.Point3D( new GM01.ColMatrix3D(0,0,0));//Draw vecA in MAGENTA with its tail at the origin.g2D.setColor(Color.MAGENTA); vecA.draw(g2D,zeroPoint);//Draw vecB in LIGHT_GRAY with its tail at the head// of vecA. g2D.setColor(Color.LIGHT_GRAY);GM01.Point3D temp = new GM01.Point3D(vecA.getColMatrix());vecB.draw(g2D,temp);//Draw vecB in LIGHT_GRAY with its tail at the origin. vecB.draw(g2D,zeroPoint);//Draw vecA in MAGENTA with its tail at the head// of vecB. This completes a trapezoid. g2D.setColor(Color.MAGENTA);vecA.draw(g2D,new GM01.Point3D(vecB.getColMatrix()));//Add the two vectors. GM01.Vector3D sum = vecA.add(vecB);//Draw sum in BLACK with its tail at the origin. g2D.setColor(Color.BLACK);sum.draw(g2D,zeroPoint); }//end drawOffScreen//----------------------------------------------------// //This method is used to set the origin of the// off-screen image, set the background color to WHITE, // and draw orthogonal 3D axes on the off-screen image// that intersect at the origin. private void setCoordinateFrame(Graphics2D g2D){//Translate the origin to the center. GM01.translate(g2D,0.5*osiWidth,-0.5*osiHeight);//Set background color to WHITE.g2D.setColor(Color.WHITE); GM01.fillRect(g2D,-osiWidth/2,osiHeight/2,osiWidth,osiHeight); //Draw x-axis in REDg2D.setColor(Color.RED); GM01.Point3D pointA =new GM01.Point3D(new GM01.ColMatrix3D(-75,0,0)); GM01.Point3D pointB =new GM01.Point3D(new GM01.ColMatrix3D(75,0,0)); pointA.draw(g2D);pointB.draw(g2D); new GM01.Line3D(pointA,pointB).draw(g2D);//Draw y-axis in GREENg2D.setColor(Color.GREEN); pointA =new GM01.Point3D(new GM01.ColMatrix3D(0,-75,0)); pointB =new GM01.Point3D(new GM01.ColMatrix3D(0,75,0)); pointA.draw(g2D);pointB.draw(g2D); new GM01.Line3D(pointA,pointB).draw(g2D);//Draw z-axis in BLUEg2D.setColor(Color.BLUE); pointA =new GM01.Point3D(new GM01.ColMatrix3D(0,0,-75)); pointB =new GM01.Point3D(new GM01.ColMatrix3D(0,0,75)); pointA.draw(g2D);pointB.draw(g2D); new GM01.Line3D(pointA,pointB).draw(g2D);}//end setCoordinateFrame method //====================================================////This is an inner class of the GUI class.class MyCanvas extends Canvas{ //Override the paint() method. This method will be// called when the JFrame and the Canvas appear on the // screen or when the repaint method is called on the// Canvas object. //The purpose of this method is to display the// off-screen image on the screen. public void paint(Graphics g){g.drawImage(osi,0,0,this); }//end overridden paint()}//end inner class MyCanvas}//end class GUI//======================================================//

Questions & Answers

how does Neisseria cause meningitis
Nyibol Reply
what is microbiologist
Muhammad Reply
what is errata
Muhammad
is the branch of biology that deals with the study of microorganisms.
Ntefuni Reply
What is microbiology
Mercy Reply
studies of microbes
Louisiaste
when we takee the specimen which lumbar,spin,
Ziyad Reply
How bacteria create energy to survive?
Muhamad Reply
Bacteria doesn't produce energy they are dependent upon their substrate in case of lack of nutrients they are able to make spores which helps them to sustain in harsh environments
_Adnan
But not all bacteria make spores, l mean Eukaryotic cells have Mitochondria which acts as powerhouse for them, since bacteria don't have it, what is the substitution for it?
Muhamad
they make spores
Louisiaste
what is sporadic nd endemic, epidemic
Aminu Reply
the significance of food webs for disease transmission
Abreham
food webs brings about an infection as an individual depends on number of diseased foods or carriers dully.
Mark
explain assimilatory nitrate reduction
Esinniobiwa Reply
Assimilatory nitrate reduction is a process that occurs in some microorganisms, such as bacteria and archaea, in which nitrate (NO3-) is reduced to nitrite (NO2-), and then further reduced to ammonia (NH3).
Elkana
This process is called assimilatory nitrate reduction because the nitrogen that is produced is incorporated in the cells of microorganisms where it can be used in the synthesis of amino acids and other nitrogen products
Elkana
Examples of thermophilic organisms
Shu Reply
Give Examples of thermophilic organisms
Shu
advantages of normal Flora to the host
Micheal Reply
Prevent foreign microbes to the host
Abubakar
they provide healthier benefits to their hosts
ayesha
They are friends to host only when Host immune system is strong and become enemies when the host immune system is weakened . very bad relationship!
Mark
what is cell
faisal Reply
cell is the smallest unit of life
Fauziya
cell is the smallest unit of life
Akanni
ok
Innocent
cell is the structural and functional unit of life
Hasan
is the fundamental units of Life
Musa
what are emergency diseases
Micheal Reply
There are nothing like emergency disease but there are some common medical emergency which can occur simultaneously like Bleeding,heart attack,Breathing difficulties,severe pain heart stock.Hope you will get my point .Have a nice day ❣️
_Adnan
define infection ,prevention and control
Innocent
I think infection prevention and control is the avoidance of all things we do that gives out break of infections and promotion of health practices that promote life
Lubega
Heyy Lubega hussein where are u from?
_Adnan
en français
Adama
which site have a normal flora
ESTHER Reply
Many sites of the body have it Skin Nasal cavity Oral cavity Gastro intestinal tract
Safaa
skin
Asiina
skin,Oral,Nasal,GIt
Sadik
How can Commensal can Bacteria change into pathogen?
Sadik
How can Commensal Bacteria change into pathogen?
Sadik
all
Tesfaye
by fussion
Asiina
what are the advantages of normal Flora to the host
Micheal
what are the ways of control and prevention of nosocomial infection in the hospital
Micheal
what is inflammation
Shelly Reply
part of a tissue or an organ being wounded or bruised.
Wilfred
what term is used to name and classify microorganisms?
Micheal Reply
Binomial nomenclature
adeolu
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