package 动;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.border.BevelBorder;
public class Panel extends JPanel implements Runnable{
static int u=0;
static int d=0;
static int l=0;
static int r=1;
static int Carmove1=0;
static int Carmove2=46;
static int Carmove3=0;
static int Carmove401=56;
static int Carmove402=41;
static int Personmove4=140;
static int flag1=0;
static int flag2=0;
static int flag3=1;
static int flag4=0;
static int flag40=1;
static int lab_space=12000;
final int CAR1_SPEED=10;
final int CAR2_SPEED=16;
final int CAR3_SPEED=16;
final int CAR4_SPEED=12;
final int PERSON4_SPEED=4;
ChangeCar3 car3=new ChangeCar3();
Thread t3=new Thread(car3);
ChangeCar402 car5=new ChangeCar402();
Thread t5=new Thread(car5);
Ready a=new Ready();
Thread at=new Thread(a);
final ImageIcon imageIcon = new ImageIcon("road.jpg");
Image img = imageIcon.getImage();
final ImageIcon imageIcon1 = new ImageIcon("1.png");
Image img1 = imageIcon1.getImage();
final ImageIcon imageIcon2 = new ImageIcon("2.jpg");
Image img2 = imageIcon2.getImage();
final ImageIcon imageIcon3 = new ImageIcon("3.jpg");
Image img3 = imageIcon3.getImage();
final ImageIcon imageIcon4 = new ImageIcon("4.jpg");
Image img4 = imageIcon4.getImage();
final ImageIcon imageIcon501 = new ImageIcon("501.png");
Image img501 = imageIcon501.getImage();
final ImageIcon imageIcon502 = new ImageIcon("502.jpg");
Image img502 = imageIcon502.getImage();
final ImageIcon imageIcona = new ImageIcon("a.jpg");
Image imga = imageIcona.getImage();
final ImageIcon imageIconb = new ImageIcon("b.jpg");
Image imgb = imageIconb.getImage();
final ImageIcon imageIconc = new ImageIcon("c.jpg");
Image imgc = imageIconc.getImage();
final ImageIcon imageIcond = new ImageIcon("d.jpg");
Image imgd = imageIcond.getImage();
final ImageIcon imageIcone = new ImageIcon("e.jpg");
Image imge = imageIcone.getImage();
final ImageIcon imageIconf = new ImageIcon("f.jpg");
Image imgf = imageIconf.getImage();
public Panel() {
this.setOpaque(false);
this.setLayout(null);
this.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
this.setBackground(Color.WHITE);
new Thread(this).start();
}
public class Ready implements Runnable{
public void run(){
ChangeLab lab=new ChangeLab();
ChangeCar1 car1=new ChangeCar1();
ChangeCar2 car2=new ChangeCar2();
Thread t=new Thread(lab);
Thread t1=new Thread(car1);
Thread t2=new Thread(car2);
t.start();
t1.start();
t2.start();
ChangePerson4 person1=new ChangePerson4();
Thread t3=new Thread(person1);
t3.start();
ChangeCar401 car4=new ChangeCar401();
Thread t4=new Thread(car4);
t4.start();
}
}
public void DrawCar1(Graphics g){
g.setColor(Color.BLACK);
g.drawImage(img1,Carmove1*CAR1_SPEED,443,60,43,null);
}
public void DrawCar2(Graphics g){
g.setColor(Color.BLACK);
g.drawImage(img2,Carmove2*CAR2_SPEED,313,60,43,null);
}
public void DrawCar3(Graphics g){
g.setColor(Color.BLACK);
g.drawImage(img3,320,Carmove3*CAR3_SPEED,45,36,null);
}
public void DrawCar401(Graphics g){
g.setColor(Color.BLACK);
g.drawImage(img501,492,Carmove401*CAR4_SPEED,45,36,null);
}
public void DrawCar402(Graphics g){
g.setColor(Color.BLACK);
g.drawImage(img502,Carmove402*CAR4_SPEED,450,45,36,null);
}
public void Drawperson(Graphics g){
g.setColor(Color.BLACK);
g.drawImage(img4,Personmove4*PERSON4_SPEED,210,50,36,null);
}
public void paint(Graphics g) {
g.drawImage(imageIcon.getImage(), 0, 0,this);
g.drawImage(imge, 35, 0,200,150,this);
g.drawImage(imgf, 555, 0,200,150,this);
for(int i=0;i<3;i++){
g.drawImage(imga, -20+i*90, 160,100,100,this);
g.drawImage(imgb, -20+i*90, 550,100,100,this);
}
for(int j=0;j<2;j++){
g.drawImage(imgc, 555+j*120, 150,100,100,this);
g.drawImage(imgd, 555+j*120, 550,100,100,this);
}
DrawCar1(g);
DrawCar2(g);
if(flag1==1) DrawCar3(g);
Drawperson(g);
DrawCar401(g);
DrawLab(g);
if(flag2==1) DrawCar402(g);
String s="当前红绿灯切换间隔为"+lab_space+"ms";
g.setColor(Color.RED);
g.drawString(s, 0, 20);
//DrawCar2(g);
}
public void run(){
while (true) {
try {
repaint();
if(lab_space<=1500) lab_space=1500;
if(lab_space>=24000) lab_space=24000;
Thread.sleep(50);
//System.out.println("I am repaint run");
}
catch (InterruptedException e) {
// TODO Auto-generated catch block
}
}
}
public void DrawLab(Graphics g){
paintArcUp(g, 330, 260);
paintArcDown(g, 470, 510);
paintArcLeft(g, 280, 450);
paintArcRight(g, 510, 330);
}
public void paintArcUp(Graphics g,int x,int y){
Color c;
if(u==1) c=Color.green;
else c=Color.red;
g.setColor(Color.GRAY);
g.fillRect(x-40, y, 110, 30);
g.setColor(c);
g.fillArc(x, y, 30, 30, 0, 360);
g.fillArc(x+40, y, 30, 30, 0, 360);
if(c==Color.RED){
g.setColor(Color.GREEN);
g.fillArc(x-40, y, 30, 30, 0, 360);
}
else{
g.setColor(Color.RED);
g.fillArc(x-40, y, 30, 30, 0, 360);
}
paintLeft(g, x+40, y);
paintRight(g, x-40, y);
paintDown(g, x, y);
}
public void paintArcDown(Graphics g,int x,int y){
Color c;
if(d==1) c=Color.green;
else c=Color.red;
g.setColor(Color.GRAY);
g.fillRect(x-40, y, 110, 30);
g.setColor(c);
g.fillArc(x, y, 30, 30, 0, 360);
g.fillArc(x-40, y, 30, 30, 0, 360);
if(c==Color.RED){
g.setColor(Color.GREEN);
g.fillArc(x+40, y, 30, 30, 0, 360);
}
else{
g.setColor(Color.RED);
g.fillArc(x+40, y, 30, 30, 0, 360);
}
paintLeft(g, x+40, y);
paintRight(g, x-40, y);
paintUp(g, x, y);
}
public void paintArcLeft(Graphics g,int x,int y){
Color c;
if(l==1) c=Color.green;
else c=Color.red;
g.setColor(Color.GRAY);
g.fillRect(x, y-40, 30, 110);
g.setColor(c);
g.fillArc(x, y, 30, 30, 0, 360);
g.fillArc(x, y-40, 30, 30, 0, 360);
if(c==Color.RED){
g.setColor(Color.GREEN);
g.fillArc(x, y+40, 30, 30, 0, 360);
}
else{
g.setColor(Color.RED);
g.fillArc(x, y+40, 30, 30, 0, 360);
}
paintUp(g, x, y-40);
paintDown(g, x, y+40);
paintLeft(g, x, y);
}
public void paintArcRight(Graphics g,int x,int y){
Color c;
if(r==1) c=Color.green;
else c=Color.red;
g.setColor(Color.GRAY);
g.fillRect(x, y-40, 30, 110);
g.setColor(c);
g.fillArc(x, y, 30, 30, 0, 360);
g.fillArc(x, y+40, 30, 30, 0, 360);
if(c==Color.RED){
g.setColor(Color.GREEN);
g.fillArc(x, y-40, 30, 30, 0, 360);
}
else{
g.setColor(Color.RED);
g.