Programming help (applets in crimson editor)

  • Thread starter fletchersally
  • Start date
  • Tags
    Programming
In summary, the author is trying to run a code example that uses Java macros, but is getting an error.
  • #1
fletchersally
2
0
Completely new to this and having some trouble with the following code...

I'm trying to run this code in Crimson editor:
Code:
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:
Physics news on Phys.org
  • #2
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++.
 
  • #3
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".

java.lang.NoSuchMethodError: main
The error message is telling you that you don't have a main function. You need to have a main.
 
  • #4
D H said:
The error message is telling you that you don't have a main function. You need to have a main.

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.
 
  • #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!
 

1. What is an applet?

An applet is a small application or program that is designed to run within a larger software application or on a web browser. They are often used to add interactivity or visual elements to websites.

2. How do I add an applet to my website?

To add an applet to your website, you will need to first create the applet using a programming language such as Java or HTML. Then, you can use HTML code to embed the applet into your webpage.

3. What is Crimson Editor?

Crimson Editor is a text editor specifically designed for programming. It offers features such as syntax highlighting, code completion, and multiple language support to make programming tasks easier and more efficient.

4. Can I use applets in Crimson Editor?

Yes, you can use applets in Crimson Editor. You can write and edit the code for your applet in the editor, and then test and run the applet using a web browser.

5. What are some common issues when working with applets in Crimson Editor?

Some common issues when working with applets in Crimson Editor include syntax errors in the code, compatibility issues with different web browsers, and difficulty troubleshooting errors. It is important to carefully check your code and use a compatible web browser to ensure your applet runs smoothly.

Similar threads

  • Programming and Computer Science
Replies
4
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Programming and Computer Science
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Programming and Computer Science
Replies
19
Views
977
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
4K
Replies
3
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
3K
Back
Top