CIS 757 INTERNET PROGRAMMING PROF. AUCIELLO
Topics: Applets -- Java Programming running inside Web Browser.
HTML to run Applets.
"Round up the usual players" Using
av.exe (AppletViewer) wa.java (source code)
wa.html (contains applet) wa.class ('compilation of wa.java,
NETSCAPE 3.0 to 4.5 embedded in wa.html)
av = allows viewing of a Java Applet, as does NETSCAPE, of course.
Procedure: Compile program 'gena.java' (below)
Verify that 'gena.class' was created.
Create 'gena.htm' (below)
Insert 'gena.class' into it.
Test using Netscape to load and run 'gena.htm'
Output:
[should see 2 lines of text in different colors and fonts.]
Here is the gena.java source code:
/* WEEK 8 PROF. AUCIELLO
(gena.java)
use gena.html to execute
print results. put in notebook.
Topics:
. Printing a literal string.
(using drawstring)
. 'public'
. x (hor) and y (ver) coord for drawString
. Fonts
Hello World, the first Java application
------------------------------------------- */
// HelloWorld as an Applet
import corejava.*; // req. for applet
import java.awt.Graphics; // req. for app & prog
import java.awt.*;
// import java.awt.color;
public class gena extends java.applet.Applet // req for app
{ public void paint(Graphics g) // req for app
{ Font f = new Font("Sans Serif", Font.BOLD, 14); // define Font
// Font is an object. Need to define the 'properties' of Font,
// (BOLD, Sans Serif, 14, etc).
// Font f defines Font.
g.setFont(f); // setFont is part of the graphics 'library'
// setFont is now 'linked' with the program.
setBackground(Color.blue);
// g.setColor(Color.red);
g.setColor(new Color(0,128,128));
// g.setColor(Color.red);
// g.drawString(x,1,100);
g.drawString("Hello World (color & motion!) @ hor 1, ver 150 ",1,150);
g.setColor(Color.yellow);
repaint();
g.drawString("Genesis Applet -- by drawString @ hor 1, ver 200 ",1,200);
}
}
// gena uses drawString to display text, demos fonts and color!
........................
Here is gena.htm (note it uses gena.class)
[APPLET CODE="gena.class" WIDTH=400 HEIGHT=300 IGNORE=""]
[/APPLET]
100 Points - change color, message, fonts, print out.
|