A telnet program needs to be able to connect to arbitrary hosts on the Internet. The applet security manager prevents used by Netscape and the Applet Viewer prevents that.
A word processing program needs to read files from and save files to the local hard drive. The applet security manager prevents used by Netscape and the Applet Viewer prevents that.
The trick is to use size().height and size(0.width directly in the call to drawString.
//Print out the applet's size
import java.applet.Applet;
import java.awt.Graphics;
public class getSizeApplet extends Applet {
public void paint(Graphics g) {
g.drawString("This applet is " + size().height +
" pixels high by " + size().width + " pixels wide.",
15, size().height/2);
}
}
import java.applet.Applet;
import java.awt.Graphics;
public class letterFillApplet extends Applet {
String theLetter;
public void init() {
String s = getParameter("Letter");
theLetter = s.substring(0, 1);
}
public void paint(Graphics g) {
for (int i = 0; i < size().width; i += 15) {
for (int j = 0; j < size().height; j += 15) {
g.drawString(theLetter, i, j);
}
}
}
}
import java.applet.Applet;
import java.awt.Graphics;
public class PoetryApplet extends Applet {
String[] poem;
int numlines;
public void init() {
int i;
String nextline;
try {
String s = getParameter("numlines");
if (s == null) numlines = 101;
else numlines = Integer.parseInt(s);
}
catch (NumberFormatException e) {
numlines = 101;
}
poem = new String[numlines];
for (i = 1; i <= numlines; i++) {
nextline = getParameter("Line" + i);
if (nextline == null) break;
poem[i] = nextline;
}
numlines = i-1;
}
public void paint(Graphics g) {
int y = 15;
for (int i=1; i <= numlines; i++) {
g.drawString(poem[i], 5, y);
y += 15;
}
}
}
import java.applet.Applet;
import java.awt.Graphics;
import java.util.Vector;
import java.util.Enumeration;
public class PoetryApplet extends Applet {
Vector poem;
public void init() {
int i = 1;
String nextline;
poem = new Vector();
while ((nextline = getParameter("Line" + i++)) != null) {
poem.addElement(nextline);
}
}
public void paint(Graphics g) {
int y = 15;
Enumeration e = poem.elements();
while (e.hasMoreElements()) {
g.drawString((String) e.nextElement(), 5, y);
y += 15;
}
}
}