Applets ICS 111 Introduction to Computer Science II

  • Slides: 15
Download presentation
Applets • ICS 111: Introduction to Computer Science II – William Albritton • Information

Applets • ICS 111: Introduction to Computer Science II – William Albritton • Information and Computer Sciences Department at the University of Hawai‘i at Mānoa • "While theoretically and technically television may be feasible, commercially and financially it is an impossibility. " – Lee De. Forest, inventor 6/19/2021 © 2007 William Albritton 1

Applet Example • Applet text file (source code) – See Hello. World. java •

Applet Example • Applet text file (source code) – See Hello. World. java • Displays several greetings • HTML text file – See hello. html (Click “View”, then “Page source”) • In order to view the applet, files hello. html & Hello. World. class file are posted on the web • However, Hello. World. java file (the source code) DOES NOT need to be posted on web in order to view applet • DO NOT post your. java file on the web, as others can copy your code & both will earn a 0 or F! 6/19/2021 © 2007 William Albritton 2

GUI • Graphical User Interface – Special computer program that provides the means for

GUI • Graphical User Interface – Special computer program that provides the means for users to interact with other computer programs by means of graphical images such as buttons, menus, etc. • Easy to write programs in Java that use GUIs 6/19/2021 © 2007 William Albritton 3

Web Pages • • Usually use HTML text files Hyper. Text Markup Language 1.

Web Pages • • Usually use HTML text files Hyper. Text Markup Language 1. Regular text 2. Tags – special notation that controls the appearance of the text a. b. c. d. 6/19/2021 Starts with < Special tag word (not case sensitive) Sometimes more information (depends on tag) Ends with > © 2007 William Albritton 4

Java Applet • Two types of Java programs 1. Applications • Until now, all

Java Applet • Two types of Java programs 1. Applications • Until now, all our programs have been applications • Execute (run) with a Java interpreter • To start the program, must have method main() 2. Applets • Linked to an HTML page & sent across the Internet • Execute (run) with a Web browser • To start the program, must have method paint() 6/19/2021 © 2007 William Albritton 5

Java API • Application Programming Interface (API) – Contains predefined classes and methods of

Java API • Application Programming Interface (API) – Contains predefined classes and methods of Java • Including the Abstract Window Toolkit (AWT) with classes used to create applets – Not actually part of the Java language – Can access Java API documentation on the Internet • Contains a description of the classes and methods that you can use in the program • See Java API link on ICS 111 class web page 6/19/2021 © 2007 William Albritton 6

Displaying Applets on Web • Follow these steps 1. Use j. GRASP to edit

Displaying Applets on Web • Follow these steps 1. Use j. GRASP to edit My. Applet. java file • Creates file My. Applet. java 2. Compile the file • Creates file My. Applet. class 3. Create HTML web page & insert tag • <APPLET CODE="My. Applet. class" WIDTH=300 HEIGHT = 400> </APPLET> 4. Post HTML on your UHUNIX web account 6/19/2021 © 2007 William Albritton 7

Displaying Applets on Web • A few tips 1. The directory (folder) must have

Displaying Applets on Web • A few tips 1. The directory (folder) must have permission 755 and the files permission 644 in order to be viewed on the Internet 2. You may need to refresh the web page (or even open a new browser) in order to display changes in the applet 3. Don’t post your *. java file on the web – The whole world will have access to it, so anyone can copy it! 4. Your only need to post your *. class file on the web 6/19/2021 © 2007 William Albritton 8

File Permissions • File permission mode – xyz represents three digits • representing the

File Permissions • File permission mode – xyz represents three digits • representing the owner, group, and other (public) users respectively – Each in the range 0 -7 • representing read, write, and execute respectively in binary/octal format • To see, right click on file or directory & select “properties” 6/19/2021 © 2007 William Albritton 9

File Permissions • For file permissions – Three octal digits = owner, group, other

File Permissions • For file permissions – Three octal digits = owner, group, other (public) – Each octal digit = three binary digits – Three binary digits = read, write, execute • (“on” or “off” = 1 or 0) • 644 = 110 100 = owner can read & write; group can read; others can read 6/19/2021 © 2007 William Albritton 10

File Permissions • Common permission modes are – 755 for web page directories •

File Permissions • Common permission modes are – 755 for web page directories • only you can read, write, or execute the directory, but all others can only read or execute the directory – 644 for web pages • you can read or write the file, but all others can only read the file – 700 for directories that should not be displayed • only you can read, write, and execute – 600 for files that should not be displayed • only you can read and write the file 6/19/2021 © 2007 William Albritton 11

Class Exercise 1 • Write an Applet that displays a goodbye message in as

Class Exercise 1 • Write an Applet that displays a goodbye message in as many different languages as the members of your group speaks – Also write the HTML file for your applet 6/19/2021 © 2007 William Albritton 12

Applet Example • Applet text file (source code) – See Yukidaruma. java • Displays

Applet Example • Applet text file (source code) – See Yukidaruma. java • Displays a Japanese snowperson • HTML text file – See snow. html (Click “View”, then “Page source”) • The html file has a link to the Yukidaruma. class file, so that the applet is displayed on the web • Yukidaruma. java file DOES NOT need to be posted on the web in order to view the applet 6/19/2021 © 2007 William Albritton 13

Class Exercise 2 • Take the following steps to create an Applet 1. Discuss

Class Exercise 2 • Take the following steps to create an Applet 1. Discuss with your group what kind of simple drawing y’all want to make – Just use a few shapes 2. Draw it on paper first – So you can figure out coordinates & size of the shapes 3. Then write the code for the Applet 6/19/2021 © 2007 William Albritton 14

Applet Issues • ICS lab issues – In order to get the applet to

Applet Issues • ICS lab issues – In order to get the applet to run, you have to save the file. java on the desktop (not in your account), and then compile & run it • Mac & PC issues – Mac still uses Java 5. 0, while PC may have either Java 5. 0 or 6. 0 • • 6/19/2021 Applets compiled in Java 5. 0 can be viewed on computers with Java 5. 0 or 6. 0 However, Applets compiled in Java 6. 0 can be viewed on computers with Java 6. 0, but CANNOT be viewed with Java 5. 0 © 2007 William Albritton 15