<< Chapter < Page Chapter >> Page >

Listing 28 . Source code for the program named GM01test01.

/*GM01test01.java Copyright 2008, R.G.BaldwinRevised 02/18/08 This program tests many 3D aspects of the GM01 libraryusing both text and graphics. Tested using JDK 1.6 under WinXP.*********************************************************/ import java.awt.*;import javax.swing.*; import java.awt.geom.*;class GM01test01{ public static void main(String[]args){ GUI guiObj = new GUI();}//end main }//end controlling class GM01test01//======================================================// class GUI extends JFrame{//Specify the horizontal and vertical size of a JFrame // object.int hSize = 400; int vSize = 400;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,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());//Test many 3D library features using text.testUsingText();//Test many 3D library features using graphics. drawOffScreen(g2D);//Cause the overridden paint method belonging to // myCanvas to be executed.myCanvas.repaint(); }//end constructor//----------------------------------------------------// //The purpose of this method is to test various// 3D aspects of the library using text. public void testUsingText(){System.out.println( "Test overridden toString of ColMatrix3D");GM01.ColMatrix3D tempA = new GM01.ColMatrix3D(1.5,2.5,3.5);System.out.println(tempA); System.out.println();System.out.println("Test setData and getData of ColMatrix3D"); tempA.setData(0,4.5);System.out.println(tempA.getData(0)); tempA.setData(1,5.5);System.out.println(tempA.getData(1)); tempA.setData(2,6.5);System.out.println(tempA.getData(2)); System.out.println();System.out.println("Test equals method of ColMatrix3D"); GM01.ColMatrix3D tempB =new GM01.ColMatrix3D(1.5,2.5,3.5); System.out.println(tempA.equals(tempB));tempB.setData(0,4.5); tempB.setData(1,5.5);tempB.setData(2,6.5); System.out.println(tempA.equals(tempB));System.out.println();System.out.println("Test add method of ColMatrix3D"); System.out.println(tempA.add(tempB));System.out.println();System.out.println( "Test subtract method of ColMatrix3D");System.out.println(tempA.subtract(tempB)); System.out.println();System.out.println("Test toString method of Point3D");GM01.Point3D pointA = new GM01.Point3D(tempA); System.out.println(pointA);System.out.println();System.out.println( "Test setData and getData of Point3D");pointA.setData(0,1.1); System.out.println(pointA.getData(0));pointA.setData(1,2.2); System.out.println(pointA.getData(1));pointA.setData(2,3.3); System.out.println(pointA.getData(2));System.out.println();System.out.println("Test getColMatrix of Point3D"); System.out.println(pointA.getColMatrix());System.out.println();System.out.println("Test equals method of Point3D");GM01.Point3D pointB = new GM01.Point3D(tempB); System.out.println(pointA.equals(pointB));pointA = new GM01.Point3D(tempB); System.out.println(pointA.equals(pointB));System.out.println();//See the method named drawOffScreen for a test of // the draw method of the Point3D class.System.out.println("Test getDisplacementVector method of Point3D"); pointA =new GM01.Point3D(new GM01.ColMatrix3D(1.5,2.5,3.5)); System.out.println(pointA);System.out.println(pointB); System.out.println(pointA.getDisplacementVector(pointB)); System.out.println();System.out.println("Test addVectorToPoint method of Point3D"); System.out.println(pointA);System.out.println(pointA.addVectorToPoint( new GM01.Vector3D(new GM01.ColMatrix3D(5.5,6.5,7.5)))); System.out.println();System.out.println("Test toString method of Vector3D"); GM01.Vector3D vecA = new GM01.Vector3D(new GM01.ColMatrix3D(1.5,2.5,3.5)); System.out.println(vecA);System.out.println();System.out.println( "Test setData and getData methods of Vector3D");vecA.setData(0,4.5); System.out.println(vecA.getData(0));vecA.setData(1,5.5); System.out.println(vecA.getData(1));vecA.setData(2,6.5); System.out.println(vecA.getData(2));System.out.println();//See the method named drawOffScreen for a test of // the draw method of the Vector3D class.System.out.println("Test getColMatrix method of Vector3D"); System.out.println(vecA.getColMatrix());System.out.println();System.out.println("Test equals method of Vector3D"); GM01.Vector3D vecB = new GM01.Vector3D(new GM01.ColMatrix3D(1.5,2.5,3.5)); System.out.println(vecA.equals(vecB));vecB.setData(0,4.5); vecB.setData(1,5.5);vecB.setData(2,6.5); System.out.println(vecA.equals(vecB));System.out.println("Test add method of Vector3D");System.out.println(vecA); vecB = new GM01.Vector3D(new GM01.ColMatrix3D(-1.5,2.5,3.5)); System.out.println(vecB);System.out.println(vecA.add(vecB)); System.out.println();System.out.println("Test getLength method of Vector3D"); vecA = new GM01.Vector3D(new GM01.ColMatrix3D(3.0,4.0,5.0)); System.out.println(vecA);System.out.println(vecA.getLength()); System.out.println();System.out.println("Test toString method of Line3D");GM01.Line3D lineA = new GM01.Line3D(pointA,pointB); System.out.println(lineA);System.out.println();System.out.println("Test setTail, setHead, getTail, " + "\nand getHead methods of Line3D");lineA.setTail(pointB); lineA.setHead(pointA);System.out.println(lineA.getTail()); System.out.println(lineA.getHead());System.out.println(); }//end testUsingText//----------------------------------------------------////The purpose of this method is to test various // 3D aspects of the library using graphics.void drawOffScreen(Graphics2D g2D){//Translate the origin on the off-screen // image and draw a pair of orthogonal axes on it.setCoordinateFrame(g2D); //Define eight points that define the corners of// a box in 3D that is centered on the origin.GM01.Point3D[] points = new GM01.Point3D[8]; //Right sidepoints[0] =new GM01.Point3D(new GM01.ColMatrix3D(75,75,75)); points[1]= new GM01.Point3D(new GM01.ColMatrix3D(75,75,-75));points[2] =new GM01.Point3D(new GM01.ColMatrix3D(75,-75,-75)); points[3]= new GM01.Point3D(new GM01.ColMatrix3D(75,-75,75));//Left side points[4]= new GM01.Point3D(new GM01.ColMatrix3D(-75,75,75));points[5] =new GM01.Point3D(new GM01.ColMatrix3D(-75,75,-75)); points[6]= new GM01.Point3D(new GM01.ColMatrix3D(-75,-75,-75));points[7] =new GM01.Point3D(new GM01.ColMatrix3D(-75,-75,75));//Draw seven of the points in BLACK g2D.setColor(Color.BLACK);for(int cnt = 1;cnt<points.length;cnt++){ points[cnt].draw(g2D); }//end for loop//Draw the right top front point in RED to identify// it. g2D.setColor(Color.RED);points[0].draw(g2D);g2D.setColor(Color.BLACK);//Draw lines that connect the points to define the // twelve edges of the box.//Right side new GM01.Line3D(points[0],points[1]).draw(g2D);new GM01.Line3D(points[1],points[2]).draw(g2D); new GM01.Line3D(points[2],points[3]).draw(g2D);new GM01.Line3D(points[3],points[0]).draw(g2D);//Left side new GM01.Line3D(points[4],points[5]).draw(g2D);new GM01.Line3D(points[5],points[6]).draw(g2D); new GM01.Line3D(points[6],points[7]).draw(g2D);new GM01.Line3D(points[7],points[4]).draw(g2D);//Front new GM01.Line3D(points[0],points[4]).draw(g2D);new GM01.Line3D(points[3],points[7]).draw(g2D);//Back new GM01.Line3D(points[1],points[5]).draw(g2D);new GM01.Line3D(points[2],points[6]).draw(g2D);//Define a vector. GM01.Vector3D vecA = new GM01.Vector3D(new GM01.ColMatrix3D(75,-75,-75));//Draw the vector with its tail at the upper-left // corner of the box. The length and direction of the// vector will cause its head to be at the origin. g2D.setColor(Color.MAGENTA);vecA.draw(g2D,points[4]);}//end drawOffScreen //----------------------------------------------------////This method is used to set the origin of the // off-screen image and to draw orthogonal 3D axes on// the off-screen image that intersect at the origin. // The lengths of the axes are set so as to match the// interior dimensions of the box and points are drawn // where the axes intersect the surfaces of the box.private void setCoordinateFrame(Graphics2D g2D){ //Translate the origin to the center.GM01.translate(g2D,0.5*osiWidth,-0.5*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