Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) 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.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!