i just started learning swings. And thought of trying out a simple program, but i can't run it.
import java.awt.*;
import javax.swing.*;
class MyDrawPanel extends JPanel
{
public void paintComponent(Graphics g)
{
g.setColor(Color.orange);
g.fillRect(20,50,100,100);
}
}
I am getting the following error:
Exception in thread "main" java.lang.NoSuchMethodError: main
My Question: Do we need to have a main method in every class we want to run? Can't JVM run any class which doesnt have a main method. Here i don't require a main class i think, cuz this paintComponent method should be called by the system, right?
P.S: I am using plain vanilla cmd to compile and run.