You need to understand java
basics before programming in java to avoid waste of your time.
To be "runnable" a class needs a main method which is
static .
You need to add a "panel" in a window("a frame") to display it.
Here is a working code, not tested, but should work without problems.
Code:
import java.awt.*;
import javax.swing.*;
public class MyDrawPanel extends JPanel {
public void paintComponent(Graphics g) {
g.setColor(Color.orange);
g.fillRect(20,50,100,100);
}
// if a main method the code inside the main method will be executed
public static void main(String args[]){
// create a window with a title
JFrame frame = new JFrame("MyApplication");
// if the window is closed, the program should exit
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// add our beautiful panel inside the window
frame.getContentPane.add(new MyDrawPanel());
// prepare the gui and display it
frame.pack();
frame.setLocation(200,200);
frame.setSize(400,400);
frame.setVisible(true);
}
}