Sunday 24 March 2013

Disk Scheduling Simulator with JavaFX



import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.LineTo;
import javafx.scene.shape.MoveTo;
import javafx.scene.shape.Path;
import javafx.stage.Stage;

/**
 *
 * @author Cristina
 */
public class JavaFXApplication1 extends Application {
   
    @Override
    public void start(Stage primaryStage) {
      primaryStage.setTitle("Disk Scheduling Simulator");
      Group root = new Group();
      Scene scene = new Scene(root, 750, 500);
     
      int[] queue = {98, 183, 37, 122, 14, 124, 65, 67};
      int headStart = 53; 
       
      DiskScheduler fcfs = new FCFS(queue, headStart);
     
      int [] result = fcfs.path();
    
      Path path = new Path(); 
   
      MoveTo moveTo = new MoveTo();
      moveTo.setX(headStart);
      moveTo.setY(50);
      path.getElements().add(moveTo); 
     
  for(int i = 0; i < result.length; i++){      
          LineTo lineTo = new LineTo();
          lineTo.setX(4*result[i]);
          lineTo.setY(50 + i*50); 
          path.getElements().add(lineTo);
      }
     
      path.setStrokeWidth(3);
      path.setStroke(Color.BLUE);
      root.getChildren().add(path);  
      primaryStage.setScene(scene);
      primaryStage.show();
    }

Bibliography

[1] http://java-buddy.blogspot.ro/2012/02/javafx-20-exercise-draw-basic-line.html
[2] Avi Silberschatz, Peter Baer Galvin, Greg Gagne: Operating System Concepts with Java

1 comment:

Anonymous said...

You really make it seem so easy with your presentation
but I find this topic to be really something that I think I would never
understand. It seems too complex and very broad for me.
I am looking forward for your next post, I'll try to get the hang of it!



My website ... buy electronic cigarette