- Java code
import java.awt.*;import java.awt.event.*;public class TankClient extends Frame { Image fim = null; int framex =30; int framey = 50; public void paint(Graphics g) { Color c = g.getColor(); g.setColor(Color.RED); g.fillOval(framex, framey, 30, 30); g.setColor(c); framex+=5; framey+=5; } public void update(Graphics g) {//System.out.println("调用了update"); if(fim == null){ fim = this.createImage(800, 600); } Graphics fimgs = fim.getGraphics(); Color c = fimgs.getColor(); fimgs.setColor(Color.GREEN); fimgs.fillRect(0, 0, 800, 600); paint(fimgs); g.drawImage(fim, 0, 0, null); } public TankClient(String s){ super(s); } public void launchFrame(){ this.setBounds(250, 200, 800, 600); this.setResizable(false); this.setBackground(Color.green); this.setVisible(true); this.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e) { e.getWindow().setVisible(false); System.exit(0); } public void windowClosed(WindowEvent e) { } }); new Thread(new FrameRepaint()).start(); } public class FrameRepaint implements Runnable{ public void run() { while(true){ repaint(); try { Thread.sleep(50); } catch (InterruptedException e) { e.printStackTrace(); } } } } public static void main(String [] args){ TankClient tc = new TankClient("坦克世界"); tc.launchFrame(); } }
------解决方案--------------------
if(g instanceof Graphics2D){
g = (Grahpics2D) g;
g.setRenderingHint(RenderingHints.KEY_ANTILASING,RenderingHints.VALUE_ANTIALIAS_ON);
}