显示球板
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();
}
}
}