Hi guys,

In my program i have to draw rectangles, but i need to pause before drawing it depending on the the number it has been assigned. I have created a timing class, which pauses the timer according to the integer. I have used tested the timing class and it works, however, it is not working in my main program, i cant figure out why. I have included the code below, can any of u figure out what the problem is?

Thanks!!

public class timing{  //this is the timing class
public long stop(int a){
if(a==1){
return 150;
}
if(a==2){
return 250;
}
if(a==3){
return 350;
}
if(a==4){
return 450;
}
if(a==5){
return 550;
}
else
return 0;
}
}



import CSLib.*;
import java.awt.*;


public class trying{
public static void main (String [] args){


DrawingBox d = new DrawingBox();
java.util.Random r = new java.util.Random();
int A[] = new int[5];
int x = 30;
colors c = new colors();
timing t = new timing();


for (int i = 0; i <A.length; i++) {
int j = r.nextInt(5)+1;
A=j;
d.setColor(c.decide(A));
d.fillRect(x, 30, 30, 30);
x = (x + 80);
Timer.pause(t.stop(A)); // the timing class works here
}
}
}



public void move() {  //this is part of another program
timing u = new timing();


for (int k = 0; k < f; k++) {
for (int i = 0; i < f - 1 - k; i++) {
d.clearRect(A, B, 30, 30);
if (f > 1) {
if (F < C) {
C[0] = F;
F = 0;
d.clearRect(D, E, 30, 30);
Timer.pause(250);
d.setColor(c.decide(C[0]));
d.fillRect(A[0], B[0], 30, 30);
Timer.pause(u.stop(C[0])); // does not work here in this program
}

Edited 3 Years Ago by Nick Evan: Fixed formatting

hey i_me_roo ... sorry to say .... your code is not indented properly ... that makes it very difficult to read.

Hi,

yeah im sorry about that, its because i cut and pasted it onto here. The main problem is that the timing class which i have created does not work in the program i want to use it in.

public class priority{
OutputBox out = new OutputBox();
DrawingBox d = new DrawingBox("Priority queuing bank system");
java.util.Random r = new java.util.Random();
colors c = new colors();
timing u = new timing();

Here is the beginning of the code where i have declared the timing class, however, when i compile it, it says 'cannot resolve symbol:class timing in class priority'. But the timing class does work because i have used it in other programs. I dont know why it will not work here, if u can figure it out, please let me know.

Thanks

sorry about that, here is the code again, this is only part of the code. When i use the timing class here there is an error, even though i havent used it, only declared it.

public class priority{
  OutputBox out = new OutputBox();
  DrawingBox d = new DrawingBox("Priority queuing bank system");
  java.util.Random r = new java.util.Random();
  colors c = new colors();
  timing u = new timing();
public class timing{ //this is the timing class
  public long stop(int a){
    if(a==1){ 
      return 150;
    }
    if(a==2){ 
      return 250;
    }
    if(a==3){ 
      return 350;
    }
    if(a==4){
      return 450;
    }
    if(a==5){
      return 550;
    }
    return 0;
  }//end function
}//end class

I had to do a lot of reading over it ... I think it'll run fine now ... test it n tell me does it work now ?

Thanks a lot for ur time and effort nanosani, however, it is still not working.

What error do you see? Please copy and paste the error here. And give a listing of the files you see in that directory (also copy and paste).

Thanks a lot for ur time and effort nanosani, however, it is still not working.

public void move() {  //this is part of another program
timing u = new timing();

for (int k = 0; k < f; k++) {
  for (int i = 0; i < f - 1 - k; i++) {
    d.clearRect(A[i], B[i], 30, 30);
    if (f > 1) {              
      if (F[i + 1] < C[i + 1]) {    
        C[0] = F[i + 1];            
        F[i + 1] = 0;               
        d.clearRect(D[i + 1], E[i + 1], 30, 30);
        Timer.pause(250);
        d.setColor(c.decide(C[0])); 
        d.fillRect(A[0], B[0], 30, 30);
        Timer.pause(u.stop(C[0])); // does not work here in this program 
      }

what is C[0],F[i+1] .... an integer or a long or something

try if you save C[0] in a long and then pass it as a parameter.

long d = C[0];
Timer.pause(u.stop(d));

Edited 3 Years Ago by pyTony: fixed formating

This article has been dead for over six months. Start a new discussion instead.