-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bus.java
159 lines (147 loc) · 2.68 KB
/
Bus.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package project;
import java.applet.*;
import java.awt.*;
public class Bus extends Applet implements Runnable{
String previous;
String op;
Graphics g;
Thread t;
int flag=0;
int x1=650;
int y1;
int y2;
Color reg=new Color(137, 186, 250);
Color temp=new Color(102, 255, 102);
Color green=new Color(102, 222, 116);
Color pink=new Color(80, 212, 205);
Color red1=new Color(252, 93, 96);
Color red=new Color(255, 11, 23);
Color gray=new Color(142, 142, 142);
public Bus(Graphics h,String s,int x,int y,String o)
{
op=o;
g=h;
previous=s;
y1=x;
y2=y;
t=new Thread(this);
t.start();
}
public void run()
{
if(previous.equals("pc"))
toIr();
else if(previous.equals("cu"))
toR0();
else if(previous.equals("r0") && op.equals("MOVE"))
toR1Move();
else if(previous.equals("r0") && (op.equals("ADD") || op.equals("SUB") || op.equals("MUL") || op.equals("DIV")))
toY();
else if(previous.equals("z"))
toR1();
}
public void toIr()
{
flag=1;
try{
for(int i=y1;i<y2;i+=5)
{
y1+=5;
repaint();
Thread.sleep(100);
}
flag=0;
new Ir(g,op);
flag=0;
t=null;
repaint();
previous="";
}
catch(InterruptedException e){}
}
public void toY()
{
flag=1;
try{
for(int i=y1;i>y2;i-=5)
{
y1-=5;
repaint();
Thread.sleep(100);
}
flag=0;
//previous="cu";
new Y(g,"r0",op);
t=null;
repaint();
}
catch(InterruptedException e){}
}
public void toR0()
{
flag=1;
try{
for(int i=y1;i<y2;i+=5)
{
y1+=5;
repaint();
Thread.sleep(100);
}
flag=0;
previous="cu";
new Register(g,"cu",op);
t=null;
repaint();
}
catch(InterruptedException e){}
}
public void toR1()
{
flag=1;
try{
for(int i=y1;i>y2;i-=5)
{
y1-=5;
repaint();
Thread.sleep(100);
}
}catch(InterruptedException e){}
flag=0;
new R1(g,"z",op);
}
public void toR1Move()
{
flag=1;
try{
for(int i=y1;i<y2;i+=5)
{
y1+=5;
repaint();
Thread.sleep(100);
}
}catch(InterruptedException e){}
flag=0;
new R1(g,"z",op);
}
public void Paint(Graphics g)
{
if(flag==1)
{
g.setColor(gray);
g.fillRect(650, 40, 10, 600);
g.fillRect(575, 232, 75, 7); //MDR->bus
g.setColor(Color.GREEN);
g.fillOval(x1, y1, 8,8 );
}
else if(flag==0)
{
g.setColor(gray);
g.fillRect(650, 40, 10, 600);
g.fillRect(575, 232, 75, 7); //MDR->bus
}
}
public void repaint()
{
Paint(g);
}
}