Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

class InstantiationException

 
bujji adapa
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Iam trying to load the applet into the html page.I get the class instantiation exception.Why?
Here is my applet.class file.
import java.awt.*;
import java.applet.*;
public class testapplet extends Canvas implements java.io.Serializable
{
Dimension size;
protected int wd, ht, halfwd, halfht;
protected int sc;
public testapplet(int initialWidth, int initialHeight, int scale)
{
wd = initialWidth;
ht = initialHeight;
halfwd = Math.round(wd/2);
halfht = Math.round(ht/2);
sc = scale;
size = new Dimension(wd,ht);
}

public Dimension getPreferredSize()
{
return getMinimumSize();
}
public Dimension getMinimumSize()
{
return size;
}
protected void drawAxes(Graphics g)
{
int x;
//sc=12;
g.setColor(Color.black);
g.drawLine(0, halfht, wd, halfht);
g.drawLine(halfwd, 0, halfwd, ht);
for (x = sc ; x < wd ; x += sc)
g.drawLine(x, halfht-3, x, halfht+3);
for (x = sc ; x < ht ; x += sc)
g.drawLine(halfwd-3, x, halfwd+3, x);
}
//protected abstract void drawFigure(Graphics g);
public void paint(Graphics g)
{
drawAxes(g);
//drawFigure(g);
}
}

Regards
rekha.
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bujji,
Only Applets can be loaded into HTML page. What does that mean? Well, for starters your applet.class had better extend an Applet. In your case you are extending a Canvas. You are trying to load a Canvas into an HTML page.
You MUST have a class that looks like the following:
public class testapplet extends Applet
Then inside your applet init method you could add a canvas and go on your merry way:

Regards,
Manfred.
 
bujji adapa
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
 
bujji adapa
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried extending Applet instead of canvas and added canvas inside the init() instead.
But still iam getting the same error.
Can anyone know the solution?
Please let me know.
regards
rajani.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic