Download presentation
Presentation is loading. Please wait.
Published byDwain Bryan Modified over 9 years ago
2
1 Cash = Double.parseDouble( JOptionPane.showInputDialog("Cash: ") ); Package – Class (application programming interface) http://java.sun.com/j2se/1.4.2/docs/api/index.html JOptionPane.showInputDialog("Cash: "); String import javax.swing.JOptionPane; methodargument Double.parseDouble(str); Class method argument double javax.lang This package will be imported by default
3
2 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;
4
3 Cosmetics & HTML = Face + ( ???? ) ???? HTML Document = Hypertext + HTML Tags Cosmetics : Tools or material to make up faces HTML : HyperText Markup Language Tools or material to make up hypertext document
5
4 Text and HyperText Mathematicians and Philosophers by Chung-Chih Li Rene Descartes: "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. "The brain is a machine." Mathematicians and Philosophers by Chung-Chih Li Rene Descartes: "I am thinking, therefore I exist.“ Descartes was the most important figure in....... "The brain is a machine. " http://hal.lamar.edu/~licc/math_phi_s2.html
6
5 Static HTML Client Server Internet I E file1, file2, file3, file4, file5, file6, file7, file8, file9, file10, file11, file12, file13, file14, …………. ………………..……………….. ……………….. file6, file9, file100, ……. File server need file20need file34 click
7
6 Dynamic HTML Client Server Internet I.E file1, file2, file3,.. quiz.html ……. Progrma1…. cgi-bin/generic-grader.pl ……………….. data1, data2, date3, 1022 ……………….. ? quiz.html <form name=“x” method=“post” action="http://cs.colgate.edu/cgi- bin/generic-grader.pl" ….. IE answers.txt file server generic-grader.pl Form x ……. ? answers.txt answers.txt result.html 100 out of 100 are correct..
8
7 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
9
8 Applet: An applet is a little application who is Web’s best friend. Pigglet: Pigglet is a little pig who is Pooh’s best friend. Tic-Tac-Toe Applet example Many more on C:/Program Files/j2sdk_nb/j2sdk1.4.2/demo/applets Running a Java Application in your Web browser --- which means, an HTML document can have a running program
10
9 An html document with Java applet TicTacToe v1.1 TicTacToe v1.1 The source.
11
10 Your next assignment COSC 1373-01/Java, Sprint 2004 This is an applet. The source. by Your name here Asg3.html
12
11 Java 2 supported Web browsers 1.Netscape 7 2.I.E. with Java Plug-in install Java 2 Running time environment. (J2RE) j2re-1_4_0-win.exe or go to http://www.java.com/en/download/windows_automatic.jsp for automated Java Plug-in installation under window command mode : appletviewer Asg3.html 1. 2. 3.
13
12 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) Applet (some people knows what an Applet should be) Asg3 (We want them all but modify or add a little.) Truck extends the concept of Vehicle Asg3 extends the concept ofApplet
14
13 Class Objects Vehicle SUV 011-JAV instantiation Honda Pilot instantiation 000-AAA Object Number Integer Double IJ Integer I,J; I = new Integer(3); J = new Integer(9); int i,j; i = Integer.parseInt(“1”); j = I.parseInt(“1”); Drive this not these
15
14 An applet import java.awt.Graphics; // import class Graphics in // java.awt package // (Abstract Windows Toolkit) import javax.swing.JApplet; // 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
16
15 Typical applet components import java.awt.Graphics; // import class Graphics in // java.awt package // (Abstract Windows Toolkit) import javax.swing.JApplet; // 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 ) { } // then this. 3rd public void stop() { } public void destroy() { } } // end class App
17
16 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.
18
17 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.
19
18 Graphics class import java.awt.Graphics; // import class Graphics import java.awt.Color; // import class 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); Some useful methods of Graphics and a field of Color. Test Applet
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.