Hi! How do I convert this applet into a standalone application? I've tried putting it into a Frame but I get Nullpointerexception from the init() method.
import java.applet.Applet;
import java.applet.AppletContext;
import java.awt.*;
import java.awt.event.*;
import java.io.PrintStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Vector;
publicclass TheApplet extends Applet
implements Runnable, MouseListener
{
publicvoid init()
{
addMouseListener(this);
displayStatus = false;
iBufferWidth = getBounds().width;
iBufferHeight = getBounds().height;
iBuffer = createImage(iBufferWidth, iBufferHeight);
gBuffer = iBuffer.getGraphics();
charsStart_ticks = 4;
charsSpeed_ticks = 1;
charsFade_ticks = 32;
pulseStart_ticks = 0;
pulseSpeed_ticks = 1;
pulseFade_ticks = 8;
bkdColor = new Color(100, 255, 255);
charColor = new Color(255,200,255);
pulseColor = new Color(255,255,160);
calculateFadeValues();
gBuffer.setFont(Font.decode("SansSerif-bolditalic-20"));
metrics = gBuffer.getFontMetrics();
lines = parseTextParameter();
parsePaddingParameter();
lineHeight = metrics.getAscent();
liney = (iBufferHeight / 2 + lineHeight / 2) - (metrics.getLeading() + metrics.getDescent()) / 2;
pulsey = iBufferHeight / 2 + lineHeight / 2;
pulseMagnitude = metrics.getAscent();
ticker = null;
ticks = 0;
runningTime = 0;
currentLine = 0;
initLine();
}
publicvoid start()
{
ticker = new Thread(this);
tickerActive = true;
ticker.start();
}
publicvoid update(Graphics g)
{
paint(g);
}
publicvoid paint(Graphics g)
{
g.drawImage(iBuffer, 0, 0, this);
}
publicvoid stop()
{
tickerActive = false;
}
publicvoid run()
{
while(tickerActive)
{
if(ticks >= runningTime)
{
ticks = 0;
currentLine++;
currentLine %= lines.length;
initLine();
}
renderFrame();
repaint();
ticks++;
try
{
Thread.sleep(50);
}
catch(InterruptedException _ex) { }
}
}
publicvoid calculateFadeValues()
{
charFadeColors = new Color[charsFade_ticks];
pulseFadeColors = new Color[pulseFade_ticks];
for(int k1 = 0; k1 < charsFade_ticks; k1++)
{
int i = (bkdColor.getRed() * k1 + charColor.getRed() * (charsFade_ticks - k1)) / charsFade_ticks;
int k = (bkdColor.getGreen() * k1 + charColor.getGreen() * (charsFade_ticks - k1)) / charsFade_ticks;
int i1 = (bkdColor.getBlue() * k1 + charColor.getBlue() * (charsFade_ticks - k1)) / charsFade_ticks;
charFadeColors[k1] = new Color(i, k, i1);
}
for(int l1 = 0; l1 < pulseFade_ticks; l1++)
{
int j = (bkdColor.getRed() * l1 + pulseColor.getRed() * (pulseFade_ticks - l1)) / pulseFade_ticks;
int l = (bkdColor.getGreen() * l1 + pulseColor.getGreen() * (pulseFade_ticks - l1)) / pulseFade_ticks;
int j1 = (bkdColor.getBlue() * l1 + pulseColor.getBlue() * (pulseFade_ticks - l1)) / pulseFade_ticks;
pulseFadeColors[l1] = new Color(j, l, j1);
}
}
publicvoid renderFrame()
{
gBuffer.setColor(bkdColor);
gBuffer.fillRect(0, 0, iBufferWidth, iBufferHeight);
int i = (ticks - pulseStart_ticks - (pulseFade_ticks - pulseSpeed_ticks)) / pulseSpeed_ticks;
int j = (ticks - pulseStart_ticks) / pulseSpeed_ticks;
i = i >= 0 ? i : 0;
j = j < chars.length ? j : chars.length - 1;
for(int i1 = i; i1 <= j; i1++)
{
gBuffer.setColor(pulseFadeColors[ticks - pulseStart_ticks - i1 * pulseSpeed_ticks]);
int l = chars[i1].equals(" ") ? pulsey - pulseMagnitude / 2 : pulsey - pulseMagnitude * (i1 % 2);
gBuffer.drawLine(charOffsets[i1], pulsey - pulseMagnitude / 2, charOffsets[i1] + charWidths[i1] / 2, l);
gBuffer.drawLine(charOffsets[i1] + charWidths[i1] / 2, l, charOffsets[i1] + charWidths[i1], pulsey - pulseMagnitude / 2);
}
i = (ticks - charsStart_ticks - (charsFade_ticks - charsSpeed_ticks)) / charsSpeed_ticks;
j = (ticks - charsStart_ticks) / charsSpeed_ticks;
i = i >= 0 ? i : 0;
j = j < chars.length ? j : chars.length - 1;
for(int j1 = i; j1 <= j; j1++)
{
int k = ticks - charsStart_ticks - j1 * charsSpeed_ticks;
k = k < 0 ? 0 : k;
gBuffer.setColor(charFadeColors[k]);
gBuffer.drawString(chars[j1], charOffsets[j1], liney);
}
}
publicvoid initLine()
{
charOffsets = newint[lines[currentLine].length()];
chars = new String[lines[currentLine].length()];
charWidths = newint[lines[currentLine].length()];
int i = iBufferWidth / 2 - metrics.stringWidth(lines[currentLine]) / 2;
for(int j = 0; j < lines[currentLine].length(); j++)
{
charOffsets[j] = i + metrics.stringWidth(lines[currentLine].substring(0, j));
chars[j] = lines[currentLine].substring(j, j + 1);
charWidths[j] = metrics.stringWidth(chars[j]);
}
int k = (lines[currentLine].length() - 1) * charsSpeed_ticks + charsFade_ticks + charsStart_ticks;
int l = (lines[currentLine].length() - 1) * pulseSpeed_ticks + pulseFade_ticks + pulseStart_ticks;
runningTime = k <= l ? l : k;
}
public Color parseColorParameter(String s, Color color)
{
String s1 = getParameter(s);
if(s1 == null)
return color;
try
{
return Color.decode(s1);
}
catch(NumberFormatException _ex)
{
return decodeColorName(s1, color);
}
}
publicint parseIntParameter(String s, int i)
{
String s1 = getParameter(s);
if(s1 == null)
return i;
try
{
return Integer.parseInt(s1);
}
catch(NumberFormatException _ex)
{
return i;
}
}
public Color decodeColorName(String s, Color color)
{
for(int i = 0; i < HTMLColorNames.length; i++)
if(s.equalsIgnoreCase(HTMLColorNames[i]))
returnnew Color(HTMLColorCodes[i]);
return color;
}
public String[] parseTextParameter()
{
String s = "text";
Vector vector = new Vector();
int i = 0;
int j;
do
{
j = s.indexOf("\\n", i);
j = j != -1 ? j : s.length();
String s1 = s.substring(i, j).trim();
if(!s1.equals(""))
vector.addElement(s1);
i = j + 2;
} while(j < s.length());
String as[] = new String[vector.size()];
for(int k = 0; k < as.length; k++)
as[k] = (String)vector.elementAt(k);
return as;
}
publicvoid parsePaddingParameter()
{
String s = getParameter("padding");
int i = 0;
boolean flag = false;
if(s == null)
i = 10;
elseif(s.equalsIgnoreCase("extents"))
flag = true;
elsetry
{
i = Integer.parseInt(s);
}
catch(NumberFormatException _ex)
{
i = 10;
}
int l = metrics.stringWidth(" ");
for(int i1 = 0; i1 < lines.length; i1++)
{
int j = metrics.stringWidth(lines[i1]);
int k = l * i * 2;
if(j < iBufferWidth)
{
if(flag || k + j > iBufferWidth)
i = (iBufferWidth - j) / l / 2;
lines[i1] = insertPadding(i) + lines[i1] + insertPadding(i);
}
}
}
public String insertPadding(int i)
{
String s = "";
for(int j = 0; j < i; j++)
s = s + " ";
return s;
}
public TheApplet()
{
}
String lines[];
int iBufferWidth;
int iBufferHeight;
FontMetrics metrics;
Image iBuffer;
Graphics gBuffer;
Thread ticker;
boolean tickerActive;
int currentLine;
int ticks;
int runningTime;
int liney;
int lineHeight;
int charWidths[];
int charOffsets[];
String chars[];
int pulseMagnitude;
int pulsey;
Color charFadeColors[];
Color pulseFadeColors[];
Color bkdColor;
Color charColor;
Color pulseColor;
int charsStart_ticks;
int charsSpeed_ticks;
int charsFade_ticks;
int pulseStart_ticks;
int pulseSpeed_ticks;
int pulseFade_ticks;
boolean displayStatus;
staticfinal String HTMLColorNames[] = {
"aqua", "black", "blue", "fuschia", "gray", "green", "lime", "maroon", "navy", "olive",
"purple", "red", "silver", "teal", "white", "yellow"
};
staticfinalint HTMLColorCodes[] = {
65535, 0, 255, 0xff00ff, 0xbebebe, 32768, 65280, 0x800000, 128, 0x808000,
0x800080, 0xff0000, 0xc0c0c0, 32896, 0xffffff, 0xffff00
};
}