Download presentation
Presentation is loading. Please wait.
Published byMelvyn Howard Modified over 9 years ago
1
IT11 Agenda for Feb 10 1. Golden Rule Reminder. 2. PowerPoint demonstration on the structure of Java Applet programs. Source Files HTML Files Class Files 3. Quick demo on using Project Builder. 4. Unit 2 Exercises (on page 13). Due 10 minutes after the beginning of the next class.
2
Three Files To Consider When Creating & Running Java Applets Java Applets source files have extension (end in) “.java” Example of a Java source file: HelloWorld.java Java Applet executable files have extension “.class” Example of a Java executable file: HelloWorld.class Applets need an applet viewer or browser to run. To place an Applet on a web page use the Applet HTML Tag.
3
Example of a Java Applet Source Files { public void paint (Graphics screen) { Java instructions for painting will go here } public void init() { Java instructions for setting up the applet will go here. } public class program_name extends Applet } import java.awt.*; import java.applet.*;
4
public void init() { } The instructions in this method get executed before any other instructions in your program. For the time being we will not be placing any instructions inside this method. The init method
5
The paint method public void paint (Graphics screen) { Your java paint instructions will go here. } The paint method is executed every time your window needs to be re-drawn. Can you think of a situation where the paint method would need to be executed?
6
HTML Files Use the Applet Tag to insert your Applet into your web-page. When working from home make sure you place your class file in the same folder as your HTML page. Below is an example of an HTML file that contains an Applet that is 300 pixels wide and 200 pixels in height.
7
Pitfall Alert! The name of your source file must exactly match the name of your program. For example if you call your Java Project HelloWorld, Project Builder will automatically call your Java source file HelloWorld.java. That means your source file must look like this: import java.awt.*; import java.applet.*; public class HelloWorld extends Applet { … } public class helloworld extends Applet { … } A syntax error will result if you replace the line above with something like:
8
Quiz #1 on Friday
9
Things To Do 1. Read Unit 2 carefully & then answer the Unit Exercises (on page 13). Don’t forget to fully answer question #3 at the very bottom of page 13 before handing it in. 2. Read chapter 3 carefully (silent reading). 3. If you finish all of 1 & 2 try Section 3.1 Mastery Questions on page 18.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.