角色入场:
public void paint(Graphics g){
g.clearRect(0, 0, 1600, 900);
Image image = new ImageIcon("D:\\综合案例\\10\\src\\tu.png").getImage();
//获取图片资源
g.drawImage(image, PositionA - 50, 100, RecWidth, RecHeight,this);//绘制图像
Image image2 = new ImageIcon("D:\\综合案例\\10\\src\\gui.png").getImage();
//获取图片资源
g.drawImage(image2, PositionB - 50, 300, RecWidth, RecHeight,this);//绘制图像
}
完整代码:
/**
* 创建赛道
* 角色入场
*/
package com.huizhi;
import javax.swing.*;
import java.awt.*;
public class TwoQRun extends JFrame {
static int RecWidth=50,RecHeight=50;
static int PositionA=50,PositionB=50,distanceAll=1600;
TwoQRun(){
setTitle("多线程:龟兔争霸");
setBackground(Color.WHITE);
setSize(1600, 500);
setLocation(0, 200);
setResizable(false);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void paint(Graphics g){
g.clearRect(0, 0, 1600, 900);
// g.setColor(Color.RED);
//g.fillRect(PositionA - 50, 100, RecWidth, RecHeight);
Image image = new ImageIcon("D:\\贵阳出差\\7-多线程和并发\\综合案例\\10\\src\\tu.png").getImage();
//获取图片资源
g.drawImage(image, PositionA - 50, 100, RecWidth, RecHeight,this);//绘制图像
// g.setColor(Color.BLUE);
// g.fillRect(PositionB - 50, 300, RecWidth, RecHeight);
Image image2 = new ImageIcon("D:\\贵阳出差\\7-多线程和并发\\综合案例\\10\\src\\gui.png").getImage();
//获取图片资源
g.drawImage(image2, PositionB - 50, 300, RecWidth, RecHeight,this);//绘制图像
}
public static void main(String[] args) {
ThreadA threadA=new ThreadA();
ThreaB threaB=new ThreaB();
ThreadC threadC=new ThreadC();
threaB.start();
threadA.start();
threadC.start();
}
}
class ThreadA extends Thread{
public void run(){
}
}
class ThreaB extends Thread{
public void run(){
}
}
class ThreadC extends Thread{
TwoQRun twoQRun=new TwoQRun();
public void run(){
}
}