Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Applet ???? help

 
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
 
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...
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!