Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 11th, 2005, 10:46 AM   #1
1stMan
Newbie
 
Join Date: Jul 2005
Posts: 1
Rep Power: 0 1stMan is on a distinguished road
Trying to run a java program

Hi,

I am trying to run a program in Java but it is not working. It compiles fine, but when i run it, it gives the error message:

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

Does anybody know what the problem is?

Thanks in advance.



Below is the code:

/*Mandel.java - Java Mandelbrot by MN Karthik. 
Any questions, comments, suggestions? You can contact me at mnkarthik@yahoo.com.
*/
import java.awt.Graphics;
import java.awt.Color;

public class Mandel extends java.applet.Applet {

    public void paint(Graphics g) {
  int sx=320;           //Screenwidth
  int sy=240;           //Screenheight
  double xmin=-2;       //smallest real value (x-axis)
  double xmax=1.25;     //largest real value (x-axis)
  double ymin=-1.25;    //smallest imaginary value (y-axis)
  double ymax=1.25;     //largest imaginary value (y-axis)
  double maxiter=512;       //Max number of iterations

  double old_x;         //temporary variable to store x-value
  double fx,fy;        
  int m;                //variable to store number of iterations

  double dx=(xmax-xmin)/sx; //how much to add for each x-pixel?
  double dy=(ymax-ymin)/sy; //how much to add for each y-pixel?

  int px;               //Variable storing current x-pixel
  int py=0;             //Variable storing current y-pixel
  double x;             //Variable storing current x-value
  double y=ymin;        //Variable storing current y-value

 g.setColor(Color.black);
 g.drawString("Rendering Mandelbrot..... please wait", 72, 220);
  while (py<sy) {
	 px=0;
	 x=xmin;
	 py++;
	 while (px<sx) {
		px++;

		fx=0;           
		fy=0;
		m=0;            
		do {
		  old_x=fx;      
		  fx=fx*fx-fy*fy+x;   
		  fy=2*old_x*fy+y;  
		  m++;                
		} while (((fx*fx+fy*fy)<4) && (m<maxiter)); 
	    if (m%2==0) g.setColor(Color.white);
	    if (m%3==0) g.setColor(Color.green);
	    if (m%4==0) g.setColor(Color.blue);
	    if (m%5==0) g.setColor(Color.red);
	    if (m%6==0) g.setColor(Color.yellow);
	    if (m%7==0) g.setColor(Color.cyan);
	    if (m%8==0) g.setColor(Color.magenta);
	    if (m%9==0) g.setColor(Color.orange);
	    if (m%10==0) g.setColor(Color.pink);
	    if (m%11==0) g.setColor(Color.gray);
	    if (m%12==0) g.setColor(Color.red);
	    if (m%13==0) g.setColor(Color.black);	g.drawLine(px-3,py-3,px+10,py+10);	 //the +10 adds a nice effect while rendering :)
	 x+=dx;
	 }
  y+=dy;
  }
  g.setColor(Color.black);
  g.drawString("Java Mandelbrot By MN Karthik", 3, 10);
    }
  public String getAppletInfo() {
    return "Java Mandelbrot by MN Karthik (mnkarthik@yahoo.com)";
  }
}
1stMan is offline   Reply With Quote
Old Jul 11th, 2005, 11:13 AM   #2
skuinders
Hobbyist Programmer
 
skuinders's Avatar
 
Join Date: Jun 2005
Location: MA, US
Posts: 204
Rep Power: 4 skuinders is on a distinguished road
that is an applet, you don't run it from the command line. you need to run it in a web browser or applet viewer... make an html file that references the applet like this:
<applet code="Applet.class" width="200" height="200"/>
and open it in your browser.
__________________
"A stupid man's report of what a clever man says can never be accurate, because he unconciously translates what he hears into something he can understand."
- B. Russell

http://web.bryant.edu/~srk2

Last edited by skuinders; Jul 11th, 2005 at 11:25 AM.
skuinders is offline   Reply With Quote
Old Jul 11th, 2005, 11:20 AM   #3
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
beat me to it...

applications that run from the command line, look for the 'Main' function. The applets, look for 'Paint', etc.
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Jul 25th, 2005, 7:30 AM   #4
varun_sud
Newbie
 
Join Date: Jul 2005
Posts: 1
Rep Power: 0 varun_sud is on a distinguished road
If u want to execute a program, the executable code must be inside main() method.
It seems u dont have any main() method.So u cannot execute a java program after compilation
varun_sud is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:56 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC