Results 1 to 8 of 8
- 05-01-2008, 07:40 PM #1
Member
- Join Date
- Nov 2007
- Posts
- 35
- Rep Power
- 0
Applet programs do not work in my JCreator
Hi I fixed the path of Run Applet option in JDK Tools.
C:\Program Files\Java\jdk1.5.0_03\bin\appletviewer.exe
but when I compile my program it does not work I get this message on the screen.
Exception in thread "main" java.lang.NoSuchMethodError: main
why is that happening other main programs are working with no problem it just working with applets bring this message up.
the code is right, it doesn't have a problem I guess.:rolleyes:Java Code:import java.awt.*; import java.awt.geom.*; import javax.swing.*; public class WelcomeApplet extends JApplet { public void init(){} public void paint(Graphics g) { super.paint(g); int xPoints[] = {-10,0,10}; int yPoints[] = {0,-50,0}; Graphics2D g2d = (Graphics2D) g; GeneralPath triangle = new GeneralPath(); triangle.moveTo(xPoints[0],yPoints[0]); for (int k = 1; k<xPoints.length;k++) triangle.lineTo(xPoints[k], yPoints[k]); triangle.closePath(); g2d.translate(200,200); g2d.setColor(Color.gray); g2d.fill(triangle); g2d.rotate(Math.PI/4.0); g2d.fill(triangle); g2d.rotate(Math.PI/4.0); } }
- 05-01-2008, 08:06 PM #2
The error message means that the jvm (java virtual machine) cannot find a main method in the WelcomeApplet class. To run an applet from/at the prompt you need to add an applet tag in a comment to the source file, eg,
and you run it at the prompt withJava Code:// <applet code="WelcomeApplet" width="400" height="400"></applet> import java.awt.*; ...
Java Code:currentDirectory>appletviewer WelcomeApplet.java
- 05-01-2008, 11:34 PM #3
Member
- Join Date
- Nov 2007
- Posts
- 35
- Rep Power
- 0
I see :) thanks hardwired .. It is still not working I got an error in prompt too.
I wrote: appletviewer WelcomeApplet.java
the error message is " 'appletviewer' is not recognized as an internal or external command , operable program or batch file.
I wrote this line in my program
//<applet code="WelcomeApplet" width="400" height="400"></applet>
above the import statements.Last edited by java_fun2007; 05-02-2008 at 12:03 AM.
- 05-02-2008, 02:32 AM #4
Sounds like your computer cannot find your sdk/jdk path.
It should probably be
"C:\Program Files\Java\jdk1.5.0_03\bin"
to give access to everything: javac, java and appletviewer.
Try
to see if you get your jre version.Java Code:currentDirectory>java -version
- 05-02-2008, 03:19 PM #5
Member
- Join Date
- Nov 2007
- Posts
- 35
- Rep Power
- 0
this is what I got when I typed
java version "1.6.0_05"Java Code:java -version
java <TM> SE Runtime Environment<build 1.6.0_05-b13>
java Hotspot <TM> Client VM <build 10.0-b19, mixed mode, sharing>
they are different right? it should be 1.5.0_03Last edited by java_fun2007; 05-02-2008 at 03:23 PM.
- 05-02-2008, 06:24 PM #6
You are using the latest version, 1.6.0_05, okay.
I don't know anything about JCreator or how it sets its path variable but that seems to be the issue.
- 05-03-2008, 10:18 AM #7
Member
- Join Date
- Nov 2007
- Posts
- 35
- Rep Power
- 0
Maybe the problem is with my computer, because I can't see applets on websites either. My IE always stuck when I visit those websites. However, I downloaded java and installed it several times.
- 04-18-2009, 11:41 AM #8
Member
- Join Date
- Apr 2009
- Posts
- 2
- Rep Power
- 0
Instead of that try this
/*
<applet code="WelcomeApplet" height=400 width=400>
</applet>
*/
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
public class WelcomeApplet extends JApplet
{
public void init(){}
public void paint(Graphics g)
{
super.paint(g);
int xPoints[] = {-10,0,10};
int yPoints[] = {0,-50,0};
Graphics2D g2d = (Graphics2D) g;
GeneralPath triangle = new GeneralPath();
triangle.moveTo(xPoints[0],yPoints[0]);
for (int k = 1; k<xPoints.length;k++)
triangle.lineTo(xPoints[k], yPoints[k]);
triangle.closePath();
g2d.translate(200,200);
g2d.setColor(Color.gray);
g2d.fill(triangle);
g2d.rotate(Math.PI/4.0);
g2d.fill(triangle);
g2d.rotate(Math.PI/4.0);
}
}
And save this as WelcomeApplet.html file.
Now run this. It will definitely work. Believe it
Similar Threads
-
Applet with JCreator
By baltimore in forum Java AppletsReplies: 2Last Post: 04-18-2009, 12:40 PM -
Will this applet ever work?
By willemjav in forum Java AppletsReplies: 4Last Post: 04-20-2008, 05:40 PM -
I need a simple programs
By mikau in forum New To JavaReplies: 2Last Post: 02-11-2008, 03:37 AM -
why doesn't this short applet work?
By kim85 in forum New To JavaReplies: 1Last Post: 01-20-2008, 08:43 PM -
Problem while executing programs
By bks504 in forum New To JavaReplies: 10Last Post: 08-02-2007, 01:32 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks