对于健身运动器,我需要在JPanel内连续修改文本和图像。
drawImage()
和drawString()
工作正常,但他们“愚蠢”。我每次都要重新粉刷一切。
伪代码如下:
public class CScreen extends JPanel {
public CScreen()
{
repaint();
}
public void paint(Graphics g)
{
BufferedImage img=...some image...;
int ximg= ...variable location...;
int yimg= ...variable location...;
g.drawImage(img,ximg,yimg,...);
Graphics2D g2 = (Graphics2D) g;
g2.setFont(...);
g2.setColor(...);
String txt = ...some text...;
int xtxt= ...variable location...;
int ytxt= ...variable location...;
g2.drawString(txt,xtxt,ytxt,...);
}
}
有没有办法处理这些文字和图像,好像它们是对象,而不是像素?
请帮助,非常感谢。