1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Programming help (applets in crimson editor)

  1. Apr 12, 2014 #1
    Completely new to this and having some trouble with the following code...

    I'm trying to run this code in Crimson editor:
    Code (Text):
     
    import java.awt.*;
    import javax.swing.JApplet;

    public class Snowman extends JApplet {
        public void paint (Graphics g) {
            final int MID = 150;
            final int TOP = 50;
            setBackground(Color.CYAN);
            g.setColor(Color.BLUE);
            g.fillRect(0, 175, 300, 50);
            g.setColor(Color.YELLOW);
            g.fillOval(-40, -40, 80, 80);
            g.setColor(Color.WHITE);
            g.fillOval(MID-20, TOP, 40, 40);
            g.fillOval(MID-35, TOP+35, 70, 50);
            g.fillOval(MID-50, TOP+80, 100, 60);
            g.setColor(Color.BLACK);
            g.fillOval(MID-10, TOP+10, 5, 5);
            g.fillOval(MID+5, TOP+10, 5, 5);
            g.drawArc(MID-10, TOP+20, 20, 10, 190, 160);
            g.drawLine(MID-25, TOP+60, MID-50, TOP+40);
            g.drawLine(MID+25, TOP+60, MID+55, TOP+60);
            g.drawLine(MID-20, TOP+5, MID+20, TOP+5);
            g.fillRect(MID-15, TOP-20, 30, 25);
        }  
    }
     
    but keep getting this error:


    ---------- Capture Output ----------
    > "C:\Program Files (x86)\Java\bin\java.exe" Snowman
    java.lang.NoSuchMethodError: main
    Exception in thread "main"
    > Terminated with exit code 1.

    and I have no idea why!!!!

    Any help is greatly appreciated!
    Thanks in advance.
     
    Last edited by a moderator: Apr 12, 2014
  2. jcsd
  3. Apr 12, 2014 #2

    Borek

    User Avatar

    Staff: Mentor

    Latest stable release is already 6 years old, it is rather miracle it works at all. After fighting problems (unrelated to java macros) I switched to Notepad++.
     
  4. Apr 12, 2014 #3

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

    fletchersally: Notice how I edited your post. Your code now looks like code. Use the code tags for code. You can either type them in manually or you can select a bunch of text and click on the code icon, the icon formed by a white box with its upper right corner torn off and with a # symbol inside.

    Your code is also indented. There are number of different indentation schemes. Arguing which one is "right" starts religious wars amongst programmers. However, almost all programmers will agree that flush left is not "right".

    The error message is telling you that you don't have a main function. You need to have a main.
     
  5. Apr 12, 2014 #4

    AlephZero

    User Avatar
    Science Advisor
    Homework Helper

    You don't need a main() function in an applet. Your code looks OK (but I haven't tested it!)

    What the error message really means is that you are trying to run your code as a stand-alone program, not as an applet.

    Some Java development systems have a "run as applet" option that simulates the way an applet is meant to start running from inside a web page. (I don't know if the Crimson editor can do that, or how to do it). Otherwise, you will have to create a simple web page that displays the applet, and open the page in your web browser.
     
  6. Apr 15, 2014 #5
    Thanks for that DH, still learning how to use this website also, and yes AlephZero I don't think Crimson can, so I'm using dos. Thanks!!
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Programming help (applets in crimson editor)
  1. Java applet help (Replies: 4)

  2. Programming Help (Replies: 4)

Loading...