File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Applet ???? help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Applet ???? help" Watch "Applet ???? help" New topic
Author

Applet ???? help

Kay Kumar
Greenhorn

Joined: Feb 28, 2005
Posts: 11
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

Joined: Nov 13, 2004
Posts: 66
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...


Have A Nice Day !!!
Kay Kumar
Greenhorn

Joined: Feb 28, 2005
Posts: 11
Brilliant

Thanks Prashanth Lingala
Kay Kumar
Greenhorn

Joined: Feb 28, 2005
Posts: 11
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

Joined: Nov 13, 2004
Posts: 66
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...
 
 
subject: Applet ???? help