I am drawing onto a JPanel using getGraphics and the drawLine and fillOval commands but it is very temperamental when running the program. However, when I debug it it draws every time.
draw.drawPoints(drawing.getGraphics(), xCoord, yCoord);
Calls:
public void drawPoints (Graphics g, int x, int y){
g.setColor(Color.red);
g.fillOval(x, y, 5, 5);
}
edit: It wont always draw. Most of the time is stays blank.
You should not draw stuff on the
JPanelby getting aGraphicsobject fromdrawing.getGraphics().Instead, you should override the
paintComponent(Graphics g)method and do your painting there.A simple example to get you started: