I'm completely new to java. I'm trying to write a simple java program that takes the input for coordinates and height,width for a rectangle and draws it. But i'm getting NullPointerException error. Here is my code:
import javax.swing.JFrame;
import java.util.Scanner;
import java.awt.*;
public class shape extends JFrame{
public int x,y,width, height;
public void setxyhw(int f, int g, int h, int i){
this.x = f;
this.y = g;
this.width =h;
this.height = i;
}
public shape(){
setTitle("frame1");
setSize(960,960);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void paint(Graphics g){
g.drawRect(x,y,height,width);
}
public static void main(String[] args) {
int a,b,c,d ;
Scanner in = new Scanner(System.in);
System.out.println("Input Co-ordinates and widh & height for rectangle");
a= in.nextInt();
b=in.nextInt();
c=in.nextInt();
d=in.nextInt();
shape s=new shape();
s.setxyhw(a,b,c,d);
s.paint(null);
}
}