package xiaohu;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.util.StringTokenizer;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
public class FCFS extends JFrame implements ActionListener
{
Vector workVector;
int status[]={0,0,0,0,0};
String workname[]={"作业名","提交时刻","要求运行时间","运行时刻","完成时刻","周转时间","带权周转时间"};
String worktable[][]=new String[5][7];
JTable workjtable;
JScrollPane messageScrollPane;
JToolBar toolBar = new JToolBar();
JButton InputButton;
JButton FCFSButton;
JButton exitButton;
JTextField show;
JTextArea source;
public FCFS()
{
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
workVector=new Vector();
InputButton=new JButton("添加作业");
FCFSButton = new JButton("FCFS算法");
exitButton = new JButton("退出");
FCFSButton.setToolTipText("FCFS算法");
toolBar.add(InputButton);
toolBar.add(FCFSButton);
toolBar.add(exitButton);
contentPane.add(toolBar, BorderLayout.NORTH);
InputButton.addActionListener(this);
FCFSButton.addActionListener(this);
exitButton.addActionListener(this);;
source=new JTextArea(5,30);
contentPane.add(source, BorderLayout.CENTER);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(300,300);
this.setLocation(100,300);
this.setResizable(false);
this.setTitle("FCFS算法");
this.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
Object obj = e.getSource();
if (obj ==InputButton)
{
String stringnum;
Work work=new Work();
stringnum=JOptionPane.showInputDialog(this,"作业名、提交时刻、要求运行时间").trim();
StringTokenizer st0 = new StringTokenizer(stringnum);
System.out.println(stringnum);
if(st0.hasMoreTokens())
{
work.workname=(String)st0.nextToken();
source.append("作业: "+work.workname);
}
if(st0.hasMoreTokens())
{
work.refertime=Double.valueOf(st0.nextToken()).doubleValue();
source.append("提交时间为: "+work.refertime);
}
if(st0.hasMoreTokens())
{
work.needtime=Double.valueOf(st0.nextToken()).doubleValue();
source.append("要求运行时间为: "+work.needtime);
}
source.append("\n");
workVector.add(work);
}
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.util.StringTokenizer;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
public class FCFS extends JFrame implements ActionListener
{
Vector workVector;
int status[]={0,0,0,0,0};
String workname[]={"作业名","提交时刻","要求运行时间","运行时刻","完成时刻","周转时间","带权周转时间"};
String worktable[][]=new String[5][7];
JTable workjtable;
JScrollPane messageScrollPane;
JToolBar toolBar = new JToolBar();
JButton InputButton;
JButton FCFSButton;
JButton exitButton;
JTextField show;
JTextArea source;
public FCFS()
{
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
workVector=new Vector();
InputButton=new JButton("添加作业");
FCFSButton = new JButton("FCFS算法");
exitButton = new JButton("退出");
FCFSButton.setToolTipText("FCFS算法");
toolBar.add(InputButton);
toolBar.add(FCFSButton);
toolBar.add(exitButton);
contentPane.add(toolBar, BorderLayout.NORTH);
InputButton.addActionListener(this);
FCFSButton.addActionListener(this);
exitButton.addActionListener(this);;
source=new JTextArea(5,30);
contentPane.add(source, BorderLayout.CENTER);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(300,300);
this.setLocation(100,300);
this.setResizable(false);
this.setTitle("FCFS算法");
this.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
Object obj = e.getSource();
if (obj ==InputButton)
{
String stringnum;
Work work=new Work();
stringnum=JOptionPane.showInputDialog(this,"作业名、提交时刻、要求运行时间").trim();
StringTokenizer st0 = new StringTokenizer(stringnum);
System.out.println(stringnum);
if(st0.hasMoreTokens())
{
work.workname=(String)st0.nextToken();
source.append("作业: "+work.workname);
}
if(st0.hasMoreTokens())
{
work.refertime=Double.valueOf(st0.nextToken()).doubleValue();
source.append("提交时间为: "+work.refertime);
}
if(st0.hasMoreTokens())
{
work.needtime=Double.valueOf(st0.nextToken()).doubleValue();
source.append("要求运行时间为: "+work.needtime);
}
source.append("\n");
workVector.add(work);
}