Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Package – Class (application programming interface) import javax.swing.JOptionPane; method String JOptionPane.showInputDialog("Cash: "); javax.lang Class This package will be imported by default double argument method argument Double.parseDouble(str); Cash = Double.parseDouble( JOptionPane.showInputDialog("Cash: ") ); http://java.sun.com/j2se/1.4.2/docs/api/index.html 1 String class, equals method String Answer; // Answer is an object of class String; boolean IsHappy; Answer = JOptionPane.showInputDialog( "Are you happy? (Y for yes, others for N) " ); // // // // // The following condition doesn’t work if (Answer == ("Y" || "y" ) if (Answer == "Y" || Answer == "y" ) IsHappy = true; if (Answer.equals("Y“) || Answer.equals("y")) IsHappy = true; else IsHappy = false; 2 Cosmetics & HTML Cosmetics : Tools or material to make up faces = Face + (????) HTML : HyperText Markup Language Tools or material to make up hypertext document HTML Document = Hypertext + HTML Tags 3 Text and HyperText Mathematicians and Philosophers by Chung-Chih Li Rene Descartes: <html> <body> <h1> Mathematicians and Philosophers </h1> <div class="author">by Chung-Chih Li </div> "I am thinking, therefore I exist." Descartes was the most important figure in modern mathematics and philosophy, and this probably is the most famous say of Descartes; but what does it really mean? The existence is established necessarily via mankind's awareness, which seemed self-evidence to Descartes, but some obvious objections followed immediately. You may want to see the excellent debate in Meditations on First Philosophy edited by John Cottingham --, which is a collection of Descartes' Meditations, their objections, and Descartes' replies. <h3> Rene Descartes: </h3> <h4> "I am thinking, therefore I exist.“ </h4> Descartes was the most important figure in ....... <h4> "The brain is a machine. " </h4> </body> </html> "The brain is a machine." http://hal.lamar.edu/~licc/math_phi_s2.html 4 Static HTML IE need file20 click file6, file9, file100, ……. file1, file2, file3, file4, file5, file6, file7, file8, file9, file10, file11, file12, file13, file14, …………. ……………….. ……………….. ……………….. ……………….. ……………….. ……………….. File server need file34 click Internet Client Server 5 Dynamic HTML file1, file2, file3, .. quiz.html ……. Progrma1…. cgi-bin/generic-grader.pl ……………….. data1, data2, date3, 1022 ……………….. IE <form name=“x” method=“post” action="http://cs.colgate.edu/cgibin/generic-grader.pl" I.E ….. 100 out of 100 are correct.. result.html generic-grader.pl </form> answers.txt file server ? quiz.html answers.txt Form x ……. ? answers.txt Internet Client Server 6 HTML Web browser (IE, Netscape) Running a Java Application in your Web browser --- which means, an HTML document can run a program -- Big deal?? YES, Big deal. • What kinds of machines? (100 kinds!!) Java uses Virture Machine (bytecodes) HelloWorld.class • Security and safety. Java provides strong security environment 7 Pigglet: Applet: Pigglet is a little pig who is Pooh’s best friend. An applet is a little application who is Web’s best friend. Running a Java Application in your Web browser --- which means, an HTML document can have a running program Tic-Tac-Toe Applet example Many more on C:/Program Files/j2sdk_nb/j2sdk1.4.2/demo/applets 8 An html document with Java applet <html> <head> <title> TicTacToe v1.1 </title> </head> <body> <h1> TicTacToe v1.1 </h1> <hr> <applet code=TicTacToe.class width=120 height=120> </applet> <a href="TicTacToe.java">The source.</a> </body></html> 9 Your next assignment <HTML> <body> <h>COSC 1373-01/Java, Sprint 2004</h> This is an applet. <APPLET code="Asg3.class" width=350 height=200> </APPLET> <a href="Asg3.java">The source.</a> <h3> by Your name here </h3> </body> </HTML> Asg3.html 10 Java 2 supported Web browsers 1. Netscape 7 2. I.E. with Java Plug-in 1. install Java 2 Running time environment. (J2RE) j2re-1_4_0-win.exe 2. or go to http://www.java.com/en/download/windows_automatic.jsp for automated Java Plug-in installation 3. under window command mode: appletviewer Asg3.html 11 Classes: A class is a concept of something Vehicle color, wheels, seat, engine……..… .(Attributes) can run, turn, stop, carry things ……(Methods) Truck big wheels, diesel engine, cargo deck...(Attributes) …lift cargo deck…………………………(Methods) Truck extends the concept of Vehicle Applet (some people knows what an Applet should be) Asg3 (We want them all but modify or add a little.) Asg3 extends the concept ofApplet 12 Class Objects instantiation Vehicle SUV Honda Pilot Drive instantiation I J 000-AAA Integer I,J; I = new Integer(3); J = new Integer(9); Object Number Double 011-JAV Integer int i,j; i = Integer.parseInt(“1”); j = I.parseInt(“1”); 13 An applet import java.awt.Graphics; import javax.swing.JApplet; // // // // import class Graphics in java.awt package (Abstract Windows Toolkit) import class JApplet public class TestApplet extends JApplet { public void paint( Graphics g ) { super.paint( g ); g.drawString( "Welcome to Java Programming!", 40, 40 ); } } // end class TestApplet 14 Typical applet components import java.awt.Graphics; import javax.swing.JApplet; // // // // import class Graphics in java.awt package (Abstract Windows Toolkit) import class JApplet public class App extends JApplet { public void init() { } // This will be executed 1st public void start() { } // then this, 2nd public void paint( Graphics g ) { public void stop() { } // then this. 3rd } public void destroy() { } } // end class App 15 Some Terminologies Drawing: putting anything on the screen of the applet. images, text (String), buttons, graphics (line, dots, circle..) primitives. Event handling: detecting and processing anything caused by the user (or other programs) Applets inherit the methods in some classes of java.awt package to handle drawing and event handling. 16 What Applets Can't Do (for security reasons) 1. Cannot read or write files. 2. Cannot make network connections except to where it came from. 3. Cannot start other program. 4. Cannot detect certain system properties. 17 Graphics class import java.awt.Graphics; import java.awt.Color; // import class Graphics // import class Color Some useful methods of Graphics and a field of Color. g.drawString("I can draw!!", 50, 150); g.drawRect(30,30, 200, 100); g.setColor(Color.blue); g.drawArc(100, 20, 100, 100, 0, 120); g.drawArc(0, 0, 100, 100, 0, 275); g.setColor(Color.green); g.fillRect(60,60, 10,20); g.setColor(Color.red); g.drawOval(150,100, 200, 100); g.setColor(Color.yellow); g.fillOval(200, 130, 90, 50); Test Applet 18