![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jul 2005
Posts: 1
Rep Power: 0
![]() |
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)";
}
} |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: MA, US
Posts: 204
Rep Power: 4
![]() |
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"/>
__________________
"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. |
|
|
|
|
|
#3 |
|
Programming Guru
![]() ![]() ![]() |
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." |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Jul 2005
Posts: 1
Rep Power: 0
![]() |
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|