• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applets not working

 
bhagya modukuri
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
ur site acutally hepled a lot for my preparation in java.i was working on applets and awt and i just couldn't get the results.the program does not compile,
my program is
import java.awt.*;
import java.applet.*;
public class Graphics extends Applet
{
public void paint(Graphics g)
{
Dimension r=size();
g.setColor(Color.red);
g.drawLine(0,0,r.width,r.height);
}
}
when i compile i get method setColor and drawLine not found in the class.
i downloaded jdk1.1.8 and also set the class path.frames are working but graphics are not working.
please tell me what is the problem.i think it might me with the software.
 
Stephanie Grasson
Ranch Hand
Posts: 347
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bhagya,
The compile error you are getting is because Java is looking for the methods setColor() and drawLine() in your Graphics class instead of in java.awt.Graphics. If you make the change to the code shown below, it will compile.

In the future, it will be easier for you if you use names for your classes that are not also used by Java. For example, instead of naming your applet class Graphics, call it LineApplet.
Hope this helps.
Stephanie
[This message has been edited by Stephanie Grasson (edited November 01, 2000).]
[This message has been edited by Stephanie Grasson (edited November 01, 2000).]
 
bhagya modukuri
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
thanks for ur help it is working.this same problem raised when i was working in another program also,there i didn't use any class names but now the code is working fine when did the modification
u suggested.i don't think that i have to write java.awt.Graphics
everytime i write my paint method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic