[英]How to make image stay after resizing?
我是Java的新手,我试图弄清楚如何在调整窗口大小后确保图像保持在屏幕上。 我尝试过在发布之前寻找答案,但似乎找不到我想要的东西。
最好的方法是什么,我应该怎么做?
这是我认为的“重要”代码:
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);
}
}
要保留图像,请执行以下操作:
getGraphics()
获得的Graphics对象。 这些对象的寿命很短,并且有导致图像消失或NullPointerExceptions的风险。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.