HelloMe 0 Junior Poster in Training

Hello everybody...!!!

I got a little but bothering problem.

I create a First in First out algorithm schedule but somehow i have a problem in computing the WT(Waiting Time).

Actually i have a WT but it only considers the current AT(Arrival Time) of the current process and does not include the previews AT of the previews processes.

Take a look please, i commented the problem area.

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

class   fcfs  extends JFrame implements ActionListener
{
   JButton cmdButton[] = new JButton[3];
   JTextField  txtField[],txtField2[];
   JLabel  lblPromt[],lblPromt2,lblPromt3,lblPromt4;
   JPanel  frmPanel,frmPanel2;
   Container con;
   int  k,p;
   String buttonCaption[] = {"APPLY","RESET","EXIT"};
   String labelCaption[] = {"Process","   AT","BT","WT","TAT"};


   public fcfs()
	{
       super("FCFS Scheduling Algorithm");
	   con = getContentPane();

	   k= Integer.parseInt(JOptionPane.showInputDialog("Enter Number Of Process"));

	   lblPromt2 = new JLabel("Process");
	   lblPromt3 = new JLabel("Arrival Time");
	   lblPromt4 = new JLabel("Burst Time");

	   lblPromt = new JLabel[k];
       txtField = new JTextField[k];
	   txtField2 = new JTextField[k];


       for(int i=0;i<k;i++)
		{
		   lblPromt[i] = new JLabel("Process "+(i+1));
		   txtField[i]  = new JTextField(10);
           txtField2[i]  = new JTextField(10);
	   }

	  for(int i=0;i<3;i++)
	{
		  cmdButton[i] = new JButton(buttonCaption[i]);
	  }

	  con.setLayout(new  GridLayout(k+2,3));
	  con.add(lblPromt2);
	  con.add(lblPromt3);
	  con.add(lblPromt4);

	  int l=0;

	  for(int i=0;i<k;i++)
		{
            con.add(lblPromt[l]);
			con.add(txtField[l]);
			con.add(txtField2[l]);
			l++;
	  }
	  l=0;
	  for(int i=0;i<3;i++)
		{
		  con.add(cmdButton[l]);
		  cmdButton[l].addActionListener(this);
		  l++;
        }
	}

	public void actionPerformed(ActionEvent ae)
	{
		
  		int WT[] = new int[k];
		int TAT[] = new int[k];
		float sum=0;
        float avg;
        
		 JPanel main = new JPanel();
		 main.setLayout(new BorderLayout());
		 frmPanel = new JPanel();
		 frmPanel2 = new JPanel();
		 frmPanel.setLayout(new GridLayout(k+1,5));
		 frmPanel2.setLayout(new FlowLayout());

		if(ae.getSource() == cmdButton[2])
        {
			System.exit(0);
	    }
		
		else if(ae.getSource() == cmdButton[0])
        {
		  
		  Integer.parseInt(txtField2[0].getText());

		  		for(int i=0;i<k;i++)
		  		{
		  			if(i==0 || i < 0)
		  			{
		  				WT[i] = 0;
		  			}
		else
		{	
			{

// WT[i] = Integer.parseInt(txtField[i].getText()) - Integer.parseInt(txtField[i].getText()) // here it only uses the current Arrival Time
					 
    WT[i] = 0;
					  
do { WT[i] += ((Integer.parseInt(txtField2[0].getText())) - (Integer.parseInt(txtField[i].getText())));} while ( WT[i]<k);  //ok there is something wrong with the while statement it loops somehow forever
			}
	

                }
				TAT[i] = WT[i]+Integer.parseInt(txtField2[i].getText());
		
				sum = sum+WT[i];


			}
		  		
            for (int i=0;i<5;i++ )
            {
			  frmPanel.add(new JLabel(labelCaption[i]));
            }
			for (int i=0;i<k;i++)
			{
			  frmPanel.add(new JLabel("Process"+(i+1)));
			  frmPanel.add(new JLabel("   "+Integer.parseInt(txtField[i].getText())));
			  frmPanel.add(new JLabel(""+Integer.parseInt(txtField2[i].getText())));
			  frmPanel.add(new JLabel(""+WT[i]));
			  frmPanel.add(new JLabel(""+TAT[i]));
		


			}
			avg = sum/k;
			String avgWaitingTime = "Average Waiting Time is "+ avg;
             frmPanel2.add(new JLabel(avgWaitingTime));
			 main.add(frmPanel,BorderLayout.NORTH);
			 main.add(frmPanel2,BorderLayout.SOUTH);

			 JOptionPane.showMessageDialog(null,main,"Output",JOptionPane.PLAIN_MESSAGE);

        }
		
		else if(ae.getSource() == cmdButton[1])
		{
			setVisible(false);
			fcfs  window = new fcfs();
			window.setSize(400,300);
			window.setLocation(550,300);
			window.setVisible(true);
			window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		}
	}
	
	

	public static void main(String[] args)
	{
            fcfs  window = new fcfs();
			window.setSize(400,300);
			window.setLocation(550,300);
			window.setVisible(true);
			window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
}

Thank you...