• 大小: 4KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-11
  • 语言: Java
  • 标签: java  多线程  

资源简介

操作系统多线程的作业,模拟多个电梯的调度机制。使用jdk11开发环境。

资源截图

代码片段和文件信息

import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JButton;
import javax.swing.Jframe;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.border.MatteBorder;
import javax.swing.plaf.basic.BasicArrowButton;



public class Listframe extends Jframe implements Runnable
{

private static int floorNum = 20; //楼层数
private static int elevatorNum = 5; //电梯数
private SubThread[] subThread;

//region UI设计___________________________________________
Container cp;
JPanel floorPanel;
JButton[] floorButton; 
BasicArrowButton[] upButton; 
BasicArrowButton[] downButton; 
JButton dispUp dispDown dispFloor;
JMenuBar menuBar;
JMenu menu;
JMenuItem chooses[] = {
//new JMenuItem(“电梯数(N)“) 
//new JMenuItem(“楼层数(N)“)
new JMenuItem(“退出(X)“)};

Color pressDownColor = Color.RED;
Color unPressDownColor = Color.GRAY;


int[] upState; 
int[] downState; 
//#endregion______________________________________________


public Listframe()
{
cp = this.getContentPane();
cp.setLayout(new GridLayout(1 elevatorNum + 1));

        //region floorPanel_________________________________________________
        floorPanel = new JPanel(); 
floorPanel.setLayout(new GridLayout(floorNum + 1 3));
floorPanel.setBorder(new MatteBorder(2 4 2 2 Color.yellow));
floorButton = new JButton[floorNum];
upButton = new BasicArrowButton[floorNum];
downButton = new BasicArrowButton[floorNum];

dispFloor = new JButton(“楼层“);
dispFloor.setEnabled(false);
dispUp = new JButton(“上“);
dispUp.setEnabled(false);
dispDown = new JButton(“下“);
dispDown.setEnabled(false);

floorPanel.add(dispFloor);
floorPanel.add(dispUp);
floorPanel.add(dispDown);

MouseListener Listener = new ButtonAction(); 
for (int i = floorButton.length - 1; i >= 0; i--)
{
floorButton[i] = new JButton(String.valueOf(i + 1));
floorButton[i].setFont(new Font(“Serif“ Font.BOLD 13));
floorButton[i].setEnabled(false);

upButton[i] = new BasicArrowButton(BasicArrowButton.NORTH);
upButton[i].addMouseListener(Listener);
upButton[i].setBackground(unPressDownColor);

downButton[i] = new BasicArrowButton(BasicArrowButton.SOUTH);
downButton[i].addMouseListener(Listener);
downButton[i].setBackground(unPressDownColor);

floorPanel.add(floorButton[i]);
floorPanel.add(upButton[i]);
floorPanel.add(downButton[i]);
}
cp.add(floorPanel);
        //endregion___________________________________________________________


        //region menuBar______________________________________________________
menuBa

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       6246  2019-05-06 23:01  Listframe.java

     文件        842  2019-05-06 21:56  ListMain.java

     文件       6842  2019-05-06 23:01  SubThread.java

----------- ---------  ---------- -----  ----

                13930                    3


评论

共有 条评论