Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I get this Error when running th JFrame. I need to have Job_ID P_TIME W_TIME Tot

ID: 3549221 • Letter: I

Question

I get this Error when running th JFrame. I need to have  Job_ID P_TIME W_TIME


Total Waiting Time:

Average Waiting Time:



Run when I cllck on the Run button. Right now it just runs without the JFrame.

This is the JFrame I am trying to create:



package sjf;


import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;


import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;



public static void main(String[] args {

EventQueue.invokeLater(new Runnable() {

public void run()

{

EventFrame frame = new EventFrame ();

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setVisible(true);

}





public @SuppressWarnings("serial")

class JFrameDemo1 extends JFrame ActionListner()

          public JFrameDemo1()



@SuppressWarnings("unused")

private JPanel buttonPanel;

@SuppressWarnings("unused")

private JButton runbutton;



// public  class  extends  JFrameDemo1 ActionListner();

// public JFrameDemo1()

{

setTitle ("Shortest Job First");

setSize(WIDTH, HEIGHT);

buttonPanel = new JPanel();

runbutton = new JButton("Run");

}

private static void createAndShowGUI()  {

        JFrame frame1 = new JFrame("JAVA");

        frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JButton button = new JButton(" Run Shortest Job First");

        

         @SuppressWarnings("unused")

final int WIDTH = 400;

         @SuppressWarnings("unused")

final int HEIGHT = 250;

        

        

        //Add action listener to button

        button.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e)

            {

             Object Source = e.getSource();

             if (source == runbutton)

            

             {

            

             }

            

                //Execute when button is pressed

            

             System.out.println("P_ID P_TIME W_TIME");

                System.out.println("Total Waiting Time");

                System.out.println("Average Waitng Time");

            }

        });      

        frame1.getContentPane().add(button);

        frame1.pack();

        frame1.setVisible(true);

    }



public static void main(String[] args) {

    javax.swing.SwingUtilities.invokeLater(new Runnable() {

        public void run() {

            createAndShowGUI();

        }

    });

}

Explanation / Answer

package sjf;



import java.awt.Event;

import java.awt.EventQueue;

import java.awt.event.ActionEvent;


import java.awt.event.ActionListener;



import javax.swing.JButton;


import javax.swing.JFrame;


import javax.swing.JPanel;






public @SuppressWarnings("serial")


public class JFrameDemo1 extends JFrame implements ActionListener

{




java.awt.EventQueue invokeLater(new Runnable() {


public void run()


{


JFrame frame = new JFrame ();


frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


frame.setVisible(true);


}

});




@SuppressWarnings("unused")


private JPanel buttonPanel;


@SuppressWarnings("unused")


private static JButton runbutton;




// public class extends JFrameDemo1 ActionListner();


public JFrameDemo1()


{


setTitle ("Shortest Job First");


setSize(WIDTH, HEIGHT);


buttonPanel = new JPanel();


runbutton = new JButton("Run");

createAndShowGUI();


}



private static void createAndShowGUI() {


JFrame frame1 = new JFrame("JAVA");


frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


JButton button = new JButton(" Run Shortest Job First");


@SuppressWarnings("unused")


final int WIDTH = 400;


@SuppressWarnings("unused")


final int HEIGHT = 250;


//Add action listener to button


button.addActionListener(new ActionListener() {


public void actionPerformed(ActionEvent e)


{


Object Source = e.getSource();


if (Source == runbutton)


{

System.out.println("P_ID P_TIME W_TIME");


System.out.println("Total Waiting Time");


System.out.println("Average Waitng Time");


}


//Execute when button is pressed



}


});


frame1.getContentPane().add(button);


frame1.pack();


frame1.setVisible(true);


}





@Override

public void actionPerformed(ActionEvent arg0) {

// TODO Auto-generated method stub

}

}


/*package sjf;


import java.util.Scanner;




class sjf {

public static void main(String args[])

{

int process[] = new int[10];

int ptime[] = new int[10];

int wtime[] = new int[10];

int temp, n, total=0;

float avg=0;

@SuppressWarnings("resource")

Scanner get = new Scanner(System.in);

System.out.println("Enter Number of Jobs: ");

n = get.nextInt();

for(int i=0;i<n;i++)

{

System.out.println("Enter Job "+(i+1)+" ID: ");

process[i] = get.nextInt();

System.out.println("Enter Job "+(i+1)+" Burst Time: ");

ptime[i] = get.nextInt();

}

for(int i=0;i<n-1;i++)

{

for(int j=i+1;j<n;j++) { if(ptime[i]>ptime[j])

{

temp = ptime[i];

ptime[i] = ptime[j];

ptime[j] = temp;

temp = process[i];

process[i] = process[j];

process[j] = temp;

}

}

}

wtime[0] = 0;

for(int i=1;i<n;i++)

{

wtime[i] = wtime[i-1]+ptime[i-1];

total = total + wtime[i];

}

avg = (float)total/n;

System.out.println("P_ID P_TIME W_TIME");

for(int i=0;i<n;i++)

{

System.out.println(process[i]+" "+ptime[i]+" "+wtime[i]);

}

System.out.println("Total Waiting Time: "+total);

System.out.println("Average Waiting Time: "+avg);

}

}

*/