{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

22-07apr12appls

22-07apr12appls - C S 1 0 0 J 1 2 A p r il 2 0 0 7 A p p...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: C S 1 0 0 J 1 2 A p r il 2 0 0 7 A p p lic a tio n s a n d A p p le ts E x e c u tin g J a v a p r o g r a m s o u ts id e t h e D r J a v a I n te r a c tio n s p a n e . R e a d C h a p te r 1 6 o f th e t e x t E v e r y J a v a p r o g r a m is e ith e r a n a p p lic a tio n o r a n a p p le t. W e a ls o lo o k a t h tm l, s in c e w e n e e d it to u s e a p p le ts . p u b lic c la s s C { I n e v e r le t m y s c h o o lin g in te rfe re w ith m y e d u c a tio n . M a rk T w a in … p u b lic s ta tic v o id m a in (S trin g a rg s ) { T o s ta rt th e a p p lic a tio n , m e th o d m a in is c a lle d . … L e a rn in g m a k e s a m a n fi t c o m p a n y fo r h im s e lf. A non } T h e p r i m a r y p u r p o s e o f a l i b e r a l e d u c a t i o n i s t o m a k e o n e 's m i n d a p l e a s a n t p l a c e i n w h i c h t o s p e n d o n e 's t i m e . S y d n e y J . H a rris (1 9 1 7 -1 9 8 6 ) A m e ric a n jo u rn a lis t. A J a v a a p p lic a tio n n e e d s a c la s s w ith a m e th o d m a in th a t is defined like this. … } T h e p a ra m e te r, a n a rra y o f S trin g s , c a n b e u s e d to p a s s in fo rm a tio n in to th e p ro g ram . 1 2 p u b lic c la s s C L A S { ja r fi le (J a v a A r c h iv e fi le ) … (lik e ta r fi le (T a p e A rc h iv e fi le )) p ublic static void main(String args) { … } C o n ta in s (a m o n g o th e r th in g s ) … ( 1 ) .c la s s fi le s (2) a “manifest”, which says which class has method main } > cd M a n ife s t: C a u s e s m e th o d c a ll > d ir A lis t o f p a s s e n g e r s o r a n in v o ic e o f c a r g o fo r a v e h ic le ( a s a s h ip o r p la n e ) . CLAS.main(null); (lis t o f fi le s ) to b e e x e c u te d > ja v a C L A S Terminal window (can type “ java CLAS” in DrJava Interactions pane) 3 4 S ta n d a lo n e J a v a p r o g r a m s C r e a tin g a ja r fi le 1 . N a v ig a te to th e d ir e c to r y th a t c o n ta in s th e .c la s s fi le s . S u p p o s e im a g e s .j a r c o n t a in s a J a v a a p p lic a t io n 2 . C r e a te a te x t fi le x .m f th a t c o n ta in s o n e lin e ( w ith a lin e - f e e d ) : I t h a s a c la s s w ith a s ta tic p r o c e d u r e m a in , a n d its m a n ife s t n a m e s th e c la s s . M a in -c la s s : < n a m e o f c la s s > 3 . In th e d ire c to ry , ty p e : • E x e c u te it b y d o u b le c lic k in g its ic o n in a d ire c to ry . j ar -cmf x .m f a p p .ja r * .c la s s • E x e c u te it b y ty p in g j a v a - j a r im a g e s .j a r C r e a te in a te rm in a l w in d o w (o r D O S , o r c o m m a n d -lin e w in d o w ) M a n ife s t F ile 5 nam e of m a n ife s t fi le n a m e o f fi le to crea te ex p a n d s to n a m e a ll th e .c la s s fi le s 6 1 I n s p e c tin g ja r fi le s ja r -tf A p p le t: a ja v a p r o g r a m th a t c a n b e c a lle d fr o m a w e b p a g e (in y o u r b r o w s e r ) i m a g e s .ja r p u b lic c la s s C { L is t th e c o n te n ts o f ja r fi le im a g e s .ja r public s tatic v oid main(String args) {…} } ty p e (lis t) F ile nam e of ja r fi le a p p lic a tio n im p o r t j a v a x. s w in g .* ; p u b lic c la s s A e x te n d s J A p p le t{ p u b lic v o id in it() { … } public void start() { …} p u b lic v o id s to p () { … } p u b lic v o id d e s tro y () { … } } a p p le t F o u r in h e r ite d p r o c e d u r e s : c a lle d to in itia liz e c a lle d to s ta rt p ro c e s s in g c a lle d to s to p p ro c e s s in g c a lle d to d e s tro y re s o u rc e s (ju s t b e fo re k illin g th e a p p le t) 7 8 An html (H y perText M a rkup L a nguage) file An html (H y perText M a rkup L a nguage) file < h tm l> < h e a d > < title > J u s t a title < /title > < /h e a d > <body> < p a lig n = " c e n te r" > < B > D e m o L in k s a n d Im a g e s < /i> < /p > < p > T h is is < a h r e f = " h ttp ://w w w .c s .c o r n e ll.e d u /c o u r s e s /c s 1 0 0 j/2 0 0 6 s p /" > a lin k < /a > < /p > < p > T h is < a h r e f = " h ttp ://w w w .c s .c o r n e ll.e d u /c o u r s e s /c s 1 0 0 j/2 0 0 6 s p /" ta rg e t= " _ b la n k " > lin k < /a > < h tm l> s ta rt a n h tm l p a g e o p e n s a n e w w in d o w < /p > < h e a d > s ta rt th e “ h e a d in g ” < p > B e lo w is a n im a g e < /p > < title > t h e title fo r th e p a g e < p > < im g s r c = " H ilb e r t_ c u r v e .p n g ” width="544” h e ig h t= " 3 5 2 " > < /p > < /b o d y > < /h tm l> <body> s ta rt th e b o d y , c o n te n t, o f th e p a g e <p> b e g in a p a ra g ra p h ta g s <a> b e g in a lin k < im g > b e g in a n im a g e 9 < h tm l> <head> <title>F acultyApplet</title> < /h e a d > <body> < p a lig n = " c e n te r" > < B > T h is < /B > is a n < i> A p p le t!< /i> < /p > < b r> < b r> ta g s < h tm l> s ta rt a n h tm l p a g e <head> s ta rt th e “ h e a d in g ” < title > t h e title fo r th e p a g e <body> s ta rt th e b o d y , c o n te n t, o f th e p a g e <p> b e g in a p a ra g ra p h <b> b e g in b o ld fa c e < p > < a p p le t a rc h iv e = " A p p le tC la s s e s . ja r ” < i> b e g in ita lic s c ode="FacultyApplet. class” < a p p le t> s ta rt a J a v a a p p le t w id th = 8 0 0 h e ig h t= 5 5 0 > < /a p p le t> <br> l in e b re a k (n o e n d ta g ) < /p > < /b o d y > < /h tm l> 10 2 ...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online