📄 90f9ea9d0014001c1d2fc692924e35ff
字号:
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class TankClient extends Frame {
int x=30,y=30;
Image offScreenImage=null;
public void launchFrame()
{
this.setLocation(100,100);
this.setTitle("Tank 大战");
this.setSize(800,600);
this.setBackground(Color.GREEN);//设置背景颜色
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
);
this.setResizable(false);
new Thread(new TankThread()).start();
this.setVisible(true);
}
public void update(Graphics g)
{
if(offScreenImage==null)
{
offScreenImage=this.createImage(800,600);
Graphics goffScreen=offScreenImage.getGraphics();
paint(goffScreen);
g.drawImage(offScreenImage,0,0,null);
}
}
public void paint(Graphics g)
{
Color c=g.getColor();
g.setColor(Color.RED);
g.fillOval(x,y,50,50);
y+=5;
}
private class TankThread implements Runnable
{
public void run() {
while(true)
{
repaint();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public static void main(String[] args) {
TankClient tc=new TankClient();
tc.launchFrame();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -