• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Applet ???? help

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Brilliant

Thanks Prashanth Lingala
 
Kay Kumar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
reply
    Bookmark Topic Watch Topic
  • New Topic