这是代码:
import java.applet.Applet;
import java.awt.Color;`
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
@SuppressWarnings("serial")
public class Pong extends Applet implements Runnable, KeyListener{
final int width = 700, height = 500;
public static int score = 0;
Thread thread;
HumanPaddle p1;
Ball b1;
public void init(){
this.resize(width, height);
this.addKeyListener(this);
thread = new Thread(this);
thread.start();
p1 = new HumanPaddle(1);
b1 = new Ball();
}
public void paint(Graphics g){
g.setColor(Color.black);
g.fillRect(0, 0, width, height);
p1.draw(g);
b1.draw(g);
g.setColor(Color.red);
g.drawString("Score: " + Integer.toString(score), width/2 - 20, 10); …Run Code Online (Sandbox Code Playgroud)