import java.awt.Graphics;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.management.loading.PrivateClassLoader;
public class TankClient extends Frame {
public static void main(String[] args) {
TankClient tankClient = new TankClient();
tankClient.lanchFrame();
}
public void paint(Graphics graphics) {
int x = 50, y = 50;
Color color = graphics.getColor();
graphics.setColor(Color.RED);
graphics.fillOval(x, y, 30, 30);
graphics.setColor(color);
y += 5;
}
public void lanchFrame() {
this.setTitle("TankWar");
this.setLocation(300, 100);
this.setSize(800, 600);
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
this.setResizable(false);
this.setBackground(Color.GREEN);
this.setVisible(true);
new Thread(new PaintThread()).start();
}
private class PaintThread implements Runnable {
@Override
public void run() {
while (true) {
repaint();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.management.loading.PrivateClassLoader;
public class TankClient extends Frame {
public static void main(String[] args) {
TankClient tankClient = new TankClient();
tankClient.lanchFrame();
}
public void paint(Graphics graphics) {
int x = 50, y = 50;
Color color = graphics.getColor();
graphics.setColor(Color.RED);
graphics.fillOval(x, y, 30, 30);
graphics.setColor(color);
y += 5;
}
public void lanchFrame() {
this.setTitle("TankWar");
this.setLocation(300, 100);
this.setSize(800, 600);
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
this.setResizable(false);
this.setBackground(Color.GREEN);
this.setVisible(true);
new Thread(new PaintThread()).start();
}
private class PaintThread implements Runnable {
@Override
public void run() {
while (true) {
repaint();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}