Reputation:
So basically, I've mentioned the HTML code in the java file, But um the applet wont execute for some reason, Help me
import java.awt.*;
import java.applet.*;
/*
<applet code = "demo.java" width=400 height=200>
<param name="txt" value ="Hey">
</applet>
*/
class demo extends Applet {
public void paint(Graphics g)
{
String string = getParameter("txt");
g.drawString(string, 29, 40);
start();
}
}
Upvotes: 0
Views: 735
Reputation: 168825
<applet code = "demo.java" width=400 height=200>
<param name="txt" value ="Hey">
</applet>
That code
parameter is incorrect. It should be the fully qualified class name. Or..
<applet code = "demo" width=400 height=200>
<param name="txt" value ="Hey">
</applet>
To compile & launch it in applet viewer from the command line, do something like:
prompt> javac demo.java
prompt> appletviewer demo.java // (see Note)
Note: Yes I do mean the .java
extension. AppletViewer can launch an applet from that comment embedded in the source code. See the Applet info. page (at To compile and launch:) for another example.
String txt
that is declared as a class attribute and initialized in the init()
method, like this txt = getParameter("txt");
. the paint(Graphics)
method might be called many times.paint(..)
method is overridden, it should immediately call super.paint(..)
(for the BG color, if nothing else).Upvotes: 1
Reputation: 1874
you should give the class name not java file name.Go through applet tutorials for good understanding.
Try this,
import java.awt.*;
import java.applet.*;
public class demo extends Applet {
public void run(){
repaint();
}
public void paint(Graphics g)
{
String string = getParameter("txt");
g.drawString(string, 29, 40);
}
}
/*
<html>
<applet code = "demo.java" width=400 height=200>
<param name="txt" value ="Hey">
</applet>
</html>
*/
Upvotes: 0