1 cash = double.parsedouble( joptionpane.showinputdialog("cash: ") ); package – class...
TRANSCRIPT
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; method argument
Double.parseDouble(str);
Class method argument
double
javax.langThis package will be imported by default
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;
elseIsHappy = false;
3
Cosmetics & HTML
= Face + (????)
HTML Document = Hypertext + HTML TagsHTML Document = Hypertext + HTML Tags
Cosmetics :Tools or material to make up faces
HTML : HyperText Markup LanguageTools or material to make up hypertext document
4
Text and HyperTextMathematicians 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."
<html><body><h1> Mathematicians and Philosophers </h1>
<div class="author">by Chung-Chih Li </div>
<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>
http://hal.lamar.edu/~licc/math_phi_s2.html
5
Static HTML
ClientServer
Internet
I E
file1, file2, file3, file4, file5, file6, file7, file8, file9, file10, file11, file12, file13, file14, …………. ………………..……………….. ………………..………………..………………..………………..
file6, file9, file100,……. File server
need file20 need file34click click
click
clickclick
click
clic
k
6
Dynamic HTML
ClientServer
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"
…..
</form>
IE
answers.txt file server
generic-grader.pl
Form x …….? answers.txtanswers.txt
result.html100 out of 100 are correct..
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
8
Applet: An applet is a little applicationwho 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
9
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>
10
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
11
Java 2 supported Web browsers1. Netscape 72. I.E. with Java Plug-in
install Java 2 Running time environment. (J2RE)j2re-1_4_0-win.exe
or go tohttp://www.java.com/en/download/windows_automatic.jsp
for automated Java Plug-in installation
under window command mode:appletviewer Asg3.html
1.
2.
3.
12
Classes: A class is a concept of something
Vehiclecolor, wheels, seat, engine……..… .(Attributes) can run, turn, stop, carry things ……(Methods)
Truckbig 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
13
Class ObjectsVehicle
SUV
011-JAV
instantiation
Honda Pilot
instantiation
000-AAA
Object
Number
IntegerDouble
I J
Integer I,J;I = new Integer(3);J = new Integer(9);
int i,j;i = Integer.parseInt(“1”);j = I.parseInt(“1”);
Drivethis
not these
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
15
Typical applet componentsimport 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
16
Some Terminologies
Drawing: putting anything on thescreen 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.
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.
18
Graphics classimport java.awt.Graphics; // import class Graphicsimport 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