Applet notes Honors05 #1 Some good web references http://www

advertisement
Untitled Document
9/23/05 11:00 AM
Applet notes
Honors05 #1
Some good web references
http://www.realapplets.com/tutorial/index.html a simple online tutorial
http://www.echoecho.com/index.html has a number of nice tutorials, including one on html
Applets are an alternate form of Java "program" that are meant to be transported over the world wide web and run at a (generally) remote site using
a web browser.
The transport is done via an html page. Here is one. It will display something called TestApplet3. It's in a text file called AppletRunner.htm.
Notice that it's bytecode, and not source code that is transported over the web. Java-aware browsers have built-in interpreters for running your
applet.
computer graphics is upside-down. (0,0) is at the NW corner - not the SW corner.
Here's the cycle: first you write your applet; then you embed it in a web page. then you open it in a browser.
<html>
<head>
<title>
Master Applet Web Page
</title>
<body>
And now.. the applet
<hr>
<applet code = "TestApplet3.class"
width = "200"
height = "200">
</applet>
<hr>
</body>
</html>
Here is TestApplet3.java
file://localhost/Users/moll/CS121/honors05/honors1.htm
Page 1 of 2
Untitled Document
9/23/05 11:00 AM
Some variants:
import javax.swing.*;
import java.awt.*;
public class TestApplet extends JApplet{
public void paint(Graphics g){
g.drawRect(10,50,300,60);
g.drawString("1", 150,90); }
}
import javax.swing.*;
import java.awt.*;
public class TestApplet extends JApplet{
public void paint(Graphics g){
g.drawOval(10,50,300,60); //and an oval instead of a rectangle
g.drawString("1", 150,90); }
}
First assignment:
here are 4 rectangles
#1 300x 100 (width x height); #2 100 x 200; #3 200 x 100; #4 100 x 100
Write an applet that makes a 300x300 rectangle, and inside the rectangle places 1-4 so that they fit exactly and so that they are numbered
numerically. Put your name at the top of the applet
file://localhost/Users/moll/CS121/honors05/honors1.htm
Page 2 of 2
Download