I'm extending JPanel to make a custom drawing panel, but am getting a NullPointerException and can't work out why. I've removed code until it's pretty bare, but the error is still occuring.
package testdraw;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import javax.swing.JPanel;
public class DrawPanel extends JPanel {
public DrawPanel() {
this.Draw();
}
public void Draw(){
Graphics g = this.getGraphics();
Graphics2D g2d = (Graphics2D) g;
RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
rh.put(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_SPEED);
g2d.setRenderingHints(rh);
}
}
I'm getting the error:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
from the line where I call the setRenderingHints
method. Any help appreciated.