【汇智学堂】JAVA多线程实现的小游戏-弹球-2

显示球板
在这里插入图片描述
Ui类

/**\
 * 定义界面
 * 显示球板
 */
package com.huizhi;

import javax.swing.*;
import java.awt.*;

public class Ui extends JFrame {

    static int PositionA=50,RecWidth=50,RecHeight=20;

    public Ui(){
            setTitle("弹球游戏");
            setBackground(Color.WHITE);
            setSize(900, 600);
            setLocation(300, 50);
            setResizable(false);
            setVisible(true);
            setDefaultCloseOperation(EXIT_ON_CLOSE);
        }

    public void paint(Graphics g) {
        g.clearRect(300,50,900,600);
        g.setColor(Color.red);
        g.fillRect(PositionA - 50, 450, RecWidth, RecHeight);
    }
    }

其他类

package com.huizhi;

public class ThreadPaddles  extends Thread{
}
package com.huizhi;

public class ThreadControle extends Thread {

    Ui ui=new Ui();
    public void run(){

        while(true){
            ui.repaint();
        }
    }
}
package com.huizhi;

public class ThreadBall extends Thread {
}
package com.huizhi;

public class Main {

    public static void main(String[] args) {
   // write your code here

        ThreadBall threadBall=new ThreadBall();
        ThreadPaddles threadPaddles=new ThreadPaddles();
        ThreadControle threadControle=new ThreadControle();

        threadBall.start();
        threadPaddles.start();
        threadControle.start();

        try {
            threadBall.join();
            threadPaddles.join();
            threadControle.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
发布了268 篇原创文章 · 获赞 47 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/weixin_39593940/article/details/103612767
今日推荐