Reputation: 1
I'm new to Java, and I'm trying to figure out how to make sure my image stays on the screen after resizing the window. I've tried looking for the answer before posting, but I can't seem to find what I'm looking for.
What is the best way to do this would be and how I should do it?
Here is what I deem the "important" code:
public void mouseDragged(MouseEvent DrawingEvent) {
Graphics g = getGraphics();
g.drawLine(DrawPoint.x, DrawPoint.y, DrawingEvent.getX(), DrawingEvent.getY());
DrawPoint = new Point(DrawingEvent.getX(), DrawingEvent.getY());
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
}
}
Upvotes: 0
Views: 77
Reputation: 285430
To get the image to stay:
getGraphics()
on a Swing component. These objects are short-lived and risk causing disappearing images or NullPointerExceptions.Upvotes: 2