我正在用户屏幕上绘制一个字符串,我想移动该字符串,但它不会改变位置,这是我的代码
public static int x = 200,y = 200;
public static Window draw() {
Window w = new Window(null) {
@Override
public void paint(Graphics g) {
super.paint(g);
System.out.println("repainting");
final Font font = getFont().deriveFont(48f);
g.setfont(font);
g.setColor(Color.WHITE);
final String message = "Hello";
FontMetrics metrics = g.getFontMetrics();
g.drawString(message,x,y);
}
@Override
public void update(Graphics g) {
paint(g);
}
};
w.setalwaysOnTop(true);
w.setbounds(w.getGraphicsConfiguration().getBounds());
w.setBackground(new Color(0,true));
w.setVisible(true);
return w;
}
public static void main(String[] args) throws AWTException {
Window window = draw();
x = 500;
y = 500;
window.repaint();
window.invalidate();
}
}
它似乎并没有改变文本位置,它打印出repainting
,因此调用了point方法,并且我已经在paint方法中打印了x,y
,它似乎也被更新了,因此图形存在问题,不想绘制新的字符串。