0

I'm creating a program that will create a series of rectangles. When I run the program, I get the error that "Rectangle1 class wasn't found in Problem_3_1 Project. I am using NetBeans 8.1. Here is my code.

import javax.swing.JApplet;
import java.awt.*;

public class Rectangle1 extends JApplet {
    public void paint(Graphics page) {              
        page.drawRect(10, 10, 10, 10);
    }  
}

Error:

Main method not found in class Rectangle1, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application C:\Users\z2054321\AppData\Local\NetBeans\Cache\8.1\executor-‌​snippets\run.xml:53: Java returned: 1 BUILD FAILED (total time: 0 seconds)

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
ZachW
  • 11
  • 1
  • Please post the full and complete error message, not an abbreviated version. – Hovercraft Full Of Eels Feb 03 '17 at 18:08
  • And where's your init method? Side recommendation: don't draw in top-level windows such as JFrames or JApplets. Rather, go through the Swing painting tutorial, which you can find here: [Lesson: Performing Custom Painting](http://docs.oracle.com/javase/tutorial/uiswing/painting/index.html), and then draw in a JPanel's paintComponent method which is then displayed in your applet. – Hovercraft Full Of Eels Feb 03 '17 at 18:10
  • @Hovercraft Full of Eels Error: Main method not found in class Rectangle1, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application C:\Users\z2054321\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1 BUILD FAILED (total time: 0 seconds) – ZachW Feb 03 '17 at 18:14
  • Post that information **in the question** as it is much too important to bury in comments. You're trying to run this code as if it were a standard program, and it's not. It's an applet, and you have to run it as an applet. That's your problem. NetBeans help files should tell you how to do this. Closed as a duplicate. – Hovercraft Full Of Eels Feb 03 '17 at 18:16
  • [Other similar questions](https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=site:stackoverflow.com+java+main+method+not+found+applet+netbeans) – Hovercraft Full Of Eels Feb 03 '17 at 18:17
  • @HovercraftFullOfEels Understood, thank you. – ZachW Feb 03 '17 at 18:18
  • The next discussion should be on why you never want to create applets as they are never used much any more, except in academic situations where the instructor doesn't really know any better. – Hovercraft Full Of Eels Feb 03 '17 at 18:20

0 Answers0