public class DrawingPanel extends JPanel
{
class Punkt
{
int x, y;
}
private Image image;
private Graphics2D g2d;
public DrawingPanel(int b,int h)
{
setPreferredSize( new Dimension(b, h) );
}
public void DiagZeichnen(int x, int y)
{
draw(x,y,Color.BLACK,5);
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
if (image == null)
{
image = createImage(getWidth(), getHeight());
g2d = (Graphics2D)image.getGraphics();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setColor(Color.white);
g2d.fillRect(0, 0, getWidth(), getHeight());
g2d.setColor(Color.black);
}
Rectangle r = g.getClipBounds();
g.drawImage(image, r.x, r.y, r.width+r.x, r.height+r.y,
r.x, r.y, r.width+r.x, r.height+r.y, null);
}
private void draw(int x, int y, Color Farbe, int Size)
{
g2d.setColor(Color.red); <<<<< hier kommt laut eclipse der null pointer fehler
g2d.fillOval(x, y, Size, Size);
repaint(x, y, Size, Size);
}
}