I'm trying to do a canvas object... is homework.. but I want to make a object
Canvas obj=new Canvas();
but i can't draw..
package canvasobjeto;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.image.BufferedImage;
/**
*
* @author Robin
*/
public class CanvasObjeto {
JFrame Frame=new JFrame();
public CanvasObjeto() {
Frame.setTitle("CanvasObjeto");
Frame.setName("CanvasObjeto");
Frame.setSize(300, 300);
Frame.setResizable(false);
Frame.setUndecorated(false);
Frame.setLayout(null);
Frame.setLocationRelativeTo(null);
Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Frame.getContentPane().setBackground(Color.WHITE);
Formato();
Frame.setVisible(true);
}
private void Formato() {
Canvas lien=new Canvas();
Graphics g= lien.getGraphics();
g.drawLine(0, 0, 20, 20);
lien.setBounds(0, 0, 200, 200);
lien.setBackground(Color.red);
lien.repaint();
Frame.add(lien);
}
public static void main(String[] args) {
CanvasObjeto Ventana=new CanvasObjeto();
}
}
this is the error... i don't know why says that if i making the obj..
Exception in thread "main" java.lang.NullPointerException at canvasobjeto.CanvasObjeto.Formato(CanvasObjeto.java:43)