[3508] in java-interest
java-interest-digest V1 #262
daemon@ATHENA.MIT.EDU (Patrick Taylor)
Tue Nov 14 23:21:35 1995
Date: Tue, 14 Nov 1995 20:50:53 -0500
From: Patrick Taylor <patrick.taylor@template.com>
To: java-interest@java.sun.com
In-Reply-To: <199511141137.DAA23232@java.sun.com>
> From: juanda@edx1.educ.monash.edu.au (Juanda Ismail)
> Date: Tue, 14 Nov 1995 18:27:28 +1100
> Subject: Copyright Issues
>
> Not a technical query, here folks, but one of legallity.
>
> I'm using the "Nervous Text" applet where I've customised the wording of the
> text so that it reads the title of my home page. Just wondering if this is ok.
> If not, I'll remove the page from the web.
I can't see this being a problem, but I don't know. However, here's a
an improved version of NervousText called CrazyText that I put together.
Feel free to use it.
// CrazyText.java
// Patrick Taylor (taylor@us.net)
// Works with JDK 1.0 beta1.
/* Based on NervousText.java demo in the JDK 1.0 beta1 release,
by Daniel Wyszynski.
The differences:
- NervousText isn't smart about its use of a proportional font. It spaces
all of the characters evenly. To demonstrate, try giving it a string
like "lllllllllllllllllllmmmmmmmmmmmmmmmmmmmm". The m's get scrunched
together, the l's are too far apart. CrazyText fixes this.
- CrazyText is very customizable.
- CrazyText paints with a random color on each update.
- By default, CrazyText doesn't clear the background on each update, which
produces a nice effect since the color changes.
- CrazyText resizes the applet to fit the text. Unfortunately, this has
no effect in Netscape 2.0 beta2, but does work in appletviewer. You
can click on the applet to see its desired size on the status line.
*/
import java.awt.Graphics;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Event;
import java.awt.Color;
public class CrazyText extends java.applet.Applet implements Runnable {
// parameters
String text = "Java"; // string to be displayed
int delay = 100; // # of milliseconds between updates
int delta = 5; // "craziness" factor: max pixel offset
boolean clear = false; // should background be cleared on update
String fontName = "TimesRoman";
int fontSize = 36;
boolean fontBold = true;
boolean fontItalic = false;
// implementation
char chars[]; // individual chars in 'text'
int positions[]; // base horizontal position for each char
FontMetrics fm;
Thread thread = null;
int newWidth, newHeight;
public void init() {
String param;
param = getParameter("text");
if (param != null) { text = param; }
param = getParameter("delay");
if (param != null) { delay = Integer.parseInt(param); }
param = getParameter("delta");
if (param != null) { delta = Integer.parseInt(param); }
param = getParameter("clear");
if (param != null) { clear = param.equals("true"); }
param = getParameter("fontName");
if (param != null) { fontName = param; }
param = getParameter("fontSize");
if (param != null) { fontSize = Integer.parseInt(param); }
param = getParameter("fontBold");
if (param != null) { fontBold = param.equals("true"); }
param = getParameter("fontItalic");
if (param != null) { fontItalic = param.equals("true"); }
int fontStyle = (fontBold ? Font.BOLD : 0) +
(fontItalic ? Font.ITALIC : 0);
setFont(new Font(fontName, fontStyle, fontSize));
fm = getFontMetrics(getFont());
chars = new char[text.length()];
text.getChars(0, text.length(), chars, 0);
positions = new int[text.length()];
for (int i = 0; i < text.length(); i++) {
positions[i] = fm.charsWidth(chars, 0, i);
}
newWidth = delta * 2 + fm.stringWidth(text);
newHeight = delta * 2 + getFont().getSize();
// this works in appletviewer, but has no effect in Netscape 2.0 beta2
resize(newWidth, newHeight);
}
public void start() {
if (thread == null) {
thread = new Thread(this);
thread.start();
}
}
public void stop() {
thread = null;
}
public void run() {
while (thread != null) {
try { Thread.sleep(delay); } catch (InterruptedException e) {}
repaint();
}
}
public void paint(Graphics g) {
g.setColor(new Color((float)Math.random(),
(float)Math.random(),
(float)Math.random()));
for (int i = 0; i < text.length(); i++) {
int x = (int)(Math.random() * delta * 2) + positions[i];
int y = (int)(Math.random() * delta * 2) + fm.getAscent() - 1;
g.drawChars(chars, i, 1, x, y);
}
}
public void update(Graphics g) {
if (clear) {
super.update(g);
} else {
paint(g);
}
}
public boolean mouseDown(Event evt, int x, int y) {
showStatus( "I'd like my size to be " + newWidth + "x" + newHeight);
return true;
}
}
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com