Results 1 to 7 of 7
  1. #1
    pinkdreammsss is offline Member
    Join Date
    Apr 2009
    Posts
    84
    Rep Power
    0

    Question Applet Main Thread Error

    Hey guyz , ive got below program :

    Java Code:
    import java.awt.Graphics;
    import java.awt.Image;
    public class BJ1 extends java.applet.Applet
    {
    	
    	Image mypic;
    	public void init()
    	{
    		  mypic = getImage(getCodeBase(), "C01.jpg");
    	}
    	
    	public void paint(Graphics screen)
    	{
    		int	iWidth =71 ;//71 int iWidth =mypic.getWidth(this);
    		int iHeight=96;  //96 int iHeight=mypic.getHeight(this);
    
    
    		int xPos = 10;
    		screen.drawImage(mypic, xPos,10, this);
    	}
    }
    However , as i try to run , i got below error :

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

    what does that mean n how can i solve this problem ?
    tnx :)

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,893
    Rep Power
    25

    Default

    How are you trying to execute your applet? The error message says you were trying to use the java command. Applets are executed in a browser by coding an <APPLET tag in some html and having the browser read the html page and then the class file.

    If you want to execute a class with the java program you need to have a main(String[] args) method in it.

  3. #3
    pinkdreammsss is offline Member
    Join Date
    Apr 2009
    Posts
    84
    Rep Power
    0

    Default

    how can i implement the main thread into my program so it can run on Java ?

  4. #4
    pinkdreammsss is offline Member
    Join Date
    Apr 2009
    Posts
    84
    Rep Power
    0

    Default

    Anybody can help ?

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,893
    Rep Power
    25

    Default

    Do you want it to run as an applet or as an application?
    An applet runs from an html page.
    To make a desktop application out of your code requires a major rewrite.

  6. #6
    pinkdreammsss is offline Member
    Join Date
    Apr 2009
    Posts
    84
    Rep Power
    0

    Default

    i need to run it as desktop applet , could u help me to run it ?! tnx

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,893
    Rep Power
    25

    Default

    i need to run it as desktop applet
    Do you want an applet or an application?
    For an applet, write an html page with the applet tag.

    To make a desktop application out of your code requires a major rewrite.
    First it needs a GUI. Extend JFrame instead of applet
    Add a constructor to fill the frame with the components you want (see below).
    Move the code from the init method to the constructor
    Add a main(String[] args) method that calls the constructor.

    Move/change the paint method to be the paintComponent method in a JPanel.
    Add that panel to the frame.

Similar Threads

  1. Replies: 2
    Last Post: 11-06-2011, 05:40 PM
  2. Replies: 5
    Last Post: 06-22-2010, 04:51 PM
  3. Replies: 8
    Last Post: 02-23-2010, 01:22 PM
  4. Replies: 1
    Last Post: 08-07-2007, 08:10 AM
  5. Replies: 1
    Last Post: 07-25-2007, 11:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •