I have created an applet that will display a blinking blue circle with a pull down menu that allows the user to select the speed of the blinker. This applet compiles and works fine in an appletviewer. However, when I post it to a web page, I get an error in the status bar that states:
error: java.lang.NOsuchMethodError: java/awt/Choice: method add(Ljava/lang/String;)V not found
Here is the code:
import java.awt.*;
import java.awt.event.*;
public class blinkingGraphic extends java.applet.Applet implements Runnable
{
Thread runner = null;
Color newColor;
int speed = 1000;
Choice blinkerControl = new Choice();
Label blinkerControlLabel = new Label("Blinker Control ", Label.RIGHT);
public void init()
{
blinkerControl.add("Slow");
blinkerControl.add("Medium");
blinkerControl.add("Fast");
blinkerControl.add("HyperSpeed");
add(blinkerControlLabel);
add(blinkerControl);
blinkerControl.addItemListener(new SelectItem());
}
class SelectItem implements ItemListener {
public void itemStateChanged(ItemEvent ie) {
if (ie.getStateChange() == ItemEvent.SELECTED) {
String name = (String) ie.getItem();
if (name == "Slow") speed = 1000;
if (name == "Medium") speed = 750;
if (name == "Fast") speed = 500;
if (name == "HyperSpeed")speed = 250;
}
}
}
public void run()
{
Color chg = getBackground();
changeColor(Color.blue);
while (true)
{
try {Thread.sleep(speed);} catch (InterruptedException e){}
changeColor(chg);
try {Thread.sleep(speed);} catch (InterruptedException e){}
changeColor(Color.blue);
}
}
public void update(Graphics g)
{
g.setColor(newColor);
g.fillOval(80,40,100,100);
}
public void changeColor(Color chg_color)
{
newColor = chg_color;
repaint();
}
public void start()
{
if (runner == null)
{
runner = new Thread(this);
runner.start();
}
}
public void stop()
{
runner = null;
}
}
Any help in getting this running of the Web would be appreciated. Thanks
Tina
Re: Applet won't display on Web page, but works fine in Appletviewer
9-13-98
Unfortunately, you've run into a problem a lot of Java developers have difficulty in overcoming.
In your case though, the fix could be simple. Try modifiying your "c:\config.sys" (or whereever it is) to include a line that says something like
set classpath = c:\myIDE\bin1;c:\myIDE\bin2
mine says:
set classpath= d:\games2\cafe\java\bin;d:\games2\cafe\java\lib;d:\games2
(all on one line though...)
If that doesn't work .. you may have to get an updated browser or get plug0in that update the java capabilities of your browser. If this is necessary, then remember that people may not be willing to do that to invoke your applet and your applet will not be usable for these people
Mike
Re: Re: Applet won't display on Web page, but works fine in Appletviewer
just as a side note ... I've got an applet that works fine in AppletViewer, works great in Netscape 4.05 and 4.06 .. but craps out in Microsoft Internet Explorer 4.01. But, secure the knowledge that one of Microsoft's marketing strategies is to "pollute Java and other cross-platform languages," I think "to hell with it .. use Nestscape to view my site --- MSIE not allowed here" :-)~
Mike (again)