Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applet ???? help

 
Kay Kumar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there, again.

I am trying to execute the following



/*
* This program creates an applet
* which displays text.
*/

import java.applet.*;
import java.awt.*;


public class MyFirstApplet extends Applet
{
public void paint (Graphics graphic)
{
graphic.drawString("Boo u twat", 5,5);
graphic.drawRect(3,3, 100, 20);
}//paint method
}//class

However, i am getting the following message

Exception in thread "main" java.lang.NoSuchMethodError: main

Why is this and how can i fix this???

Begginer here, so understand

Thanks
 
Prashanth Lingala
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
first compile your file....

In your applet there is no main()...
further

type the following code

<applet code="MyFirstApplet.class" width = 300 height = 50>
</applet>

and save as MyFirstApplet.html

place in the same directory as your class file...

now Double Click MyFirstApplet.html

you will get your result...
 
Kay Kumar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brilliant

Thanks Prashanth Lingala
 
Kay Kumar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wait, before you go.

I have done as you said and it does work, but..

the display is stuck in the top left corner and no matter what i change in my code (MyFirstApplet.java) it dosn't effect html display.


i.e. The rectangle and text is always in the top left corner.
 
Prashanth Lingala
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember the CoOrdinates begin at the top left corner

0,0 -------X Coordinates------89,0
|
|
|
y Coordinate
|
|
0,10

replace your drawRect code with the following:


Try playing with coordinates...you will get the idea...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic