will someone help me pls with my case study, i need it very urgent
this is my code for shortest remaining time first or the preemptive sjf.
i need to know how to make gantt chart.

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class SRTF extends Applet implements ActionListener {

 Label srtf = new Label("Shortest Remaining Time First");
 Label job = new Label("Jobs");
 Label at = new Label("Arrival Time");
 Label bt = new Label("    Burst Time");
 Label ttav = new Label("Average Turnaround Time:");
 Label wtav = new Label("Average Waiting Time:");

 Button tt = new Button("Compute for Turnaround Time");
 Button wt = new Button("Compute for Waiting Time");
 Button gc = new Button("Show Gantt Chart");
 Button close = new Button("Close");

 TextField j1 = new TextField("Job 1",10);
 TextField j2 = new TextField("Job 2",10);
 TextField j3 = new TextField("Job 3",10);
 TextField j4 = new TextField("Job 4",10);
 TextField j5 = new TextField("Job 5",10);

 TextField at1 = new TextField("",10);
 TextField at2 = new TextField("",10);
 TextField at3 = new TextField("",10);
 TextField at4 = new TextField("",10);
 TextField at5 = new TextField("",10);

 TextField bt1 = new TextField("",10);
 TextField bt2 = new TextField("",10);
 TextField bt3 = new TextField("",10);
 TextField bt4 = new TextField("",10);
 TextField bt5 = new TextField("",10);

 TextField ttave = new TextField();
 TextField wtave = new TextField();

 Frame fr = new Frame("Turnaround Time");
 Frame fr1 = new Frame("Waiting Time");
 Frame gcf = new Frame("Gantt Chart");

 Panel p1 = new Panel();
 Panel p2 = new Panel();
 Panel p3 = new Panel();
 Panel p4 = new Panel();
 Panel p5 = new Panel();
 Panel p6 = new Panel();
 Panel p7 = new Panel();
 Panel p8 = new Panel();
 Panel p9 = new Panel();

 GridLayout GL = new GridLayout(1,3);
 GridLayout GL2 = new GridLayout(1,2);


public void init() {

 add(p1);
 p1.add(srtf);

 add(p2);
 p2.setLayout(GL);
 p2.add(job);
 p2.add(at);
 p2.add(bt);

 add(p3);
 p3.add(j1);
 j1.setEditable(false);
 p3.add(at1);
 p3.add(bt1);
 p3.setLayout(GL);

 add(p4);
 p4.add(j2);
 j2.setEditable(false);
 p4.add(at2);
 p4.add(bt2);
 p4.setLayout(GL);

 add(p5);
 p5.add(j3);
 j3.setEditable(false);
 p5.add(at3);
 p5.add(bt3);
 p5.setLayout(GL);

 add(p6);
 p6.add(j4);
 j4.setEditable(false);
 p6.add(at4);
 p6.add(bt4);
 p6.setLayout(GL);

 add(p7);
 p7.add(j5);
 j5.setEditable(false);
 p7.add(at5);
 p7.add(bt5);
 p7.setLayout(GL);

 add(p8);
 p8.add(tt);tt.addActionListener(this);
 p8.add(wt);wt.addActionListener(this);
 p8.setLayout(GL2);

 add(p9);
 p9.add(gc);gc.addActionListener(this);

}


public void actionPerformed(ActionEvent x) {
 if(x.getSource()==tt)
 {fr.show();
  fr.setSize(300,300);
  fr.add(ttav, BorderLayout.NORTH);
  fr.add(ttave);
  fr.add(close, BorderLayout.SOUTH);
  close.addActionListener(this);

  int att, att2, att3, att4, att5;
  int sum;
  int aw;
  String tot;

  try {
  att = Integer.parseInt(at1.getText());
  att2 = Integer.parseInt(at2.getText());
  att3 = Integer.parseInt(at3.getText());
  att4 = Integer.parseInt(at4.getText());
  att5 = Integer.parseInt(at5.getText());

  sum = att+att2+att3+att4+att5;
  aw = sum/5;
  tot = String.valueOf(aw);

  ttave.setText(tot);

  }catch(Exception a)
  {//JOptionPane.showMessageDialog(null, "TAE", "MALI", JOptionPane.ERROR_MESSAGE);
  }

  }

 if(x.getSource()==close)
  {fr.hide();
   fr.dispose();
   }



 if(x.getSource()==wt)
 {fr1.show();
  fr1.setSize(300,300);
  fr1.add(wtav, BorderLayout.NORTH);
  fr1.add(wtave);
  fr1.add(close, BorderLayout.SOUTH);
  close.addActionListener(this);
     }

 if(x.getSource()==close)
   {fr1.hide();
    fr1.dispose();
   }

 if(x.getSource()==gc)
 {gcf.show();
  gcf.setSize(600,200);
  gcf.add(close, BorderLayout.SOUTH);
  close.addActionListener(this);
     }

 if(x.getSource()==close)
  {gcf.hide();
   gcf.dispose();
   }

    }
}

Do you have a data structure with all the jobs and their times:
shortest start, shortest finish, longest start, longest finish? (I don't know the English terminology)

I don't see where you save those values. Have an array for example with the jobs and their times. Then create a new Frame that takes as argument those values and draw some graphs.

When I was making my own GANTT chart, I used rectangulars with a fixed width and the length was the duration.

Draw the 1st job at position (X,Y)=(0,0) with width and length=duration.
Then as the loop progresses, draw the ith rectangular(job) at position below the previous rectangular (previous position: X + width) and to the right moved by the previous's length (previous position: Y + length)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.