小编mar*_*l56的帖子

多线程程序中的java.lang.NullPointerException

这是代码:

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)

java windows multithreading awt

1
推荐指数
1
解决办法
372
查看次数

标签 统计

awt ×1

java ×1

multithreading ×1

windows ×1