⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 statuspanel.java

📁 操作系统课程设计之内存分配模拟,采用首次适应算法实现(JAVA版)
💻 JAVA
字号:
/**
 * StatusPanel类
 * 构建内存空间分配图
 * @author linpeitian
 */

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

public class StatusPanel extends JPanel{

	private int[] block = new int[128];
	MAllocator mallocator = null;
	
	public StatusPanel(){	}
	
	public StatusPanel(MAllocator mallocator){
		this.mallocator = mallocator;
	}
	
	/**
	 * 内存分配显示条,绘图函数
	 */
	public void paintComponent(Graphics g){
		super.paintComponent(g);
		block = mallocator.getBlock();
		g.drawRect(0, 0, 440, 20);
		g.setColor(new Color(0, 0, 255));
		g.fillRect(0, 0, 440, 20);
		int count = 0;
		for(int i = 0 ; i < 128; i++){
			if(block[i] == 1){
				count++;
			}else{
				if(count == 0) continue;
				int x1 = (int)(440*(i - count)/128);
				int x2 = (int)(count * 440 / 128);
				g.drawRect(x1, 0, x2, 20);
				g.setColor(new Color(0, 255, 0));
				g.fillRect(x1, 0, x2, 20);
				count = 0;
			}
		}
		if(count != 0){
			int x1 = (int)(440*(128 - count)/128);
			int x2 = (int)(count * 440 / 128);
			g.drawRect(x1, 0, x2, 20);
			g.setColor(new Color(0, 255, 0));
			g.fillRect(x1, 0, x2, 20);
			count = 0;
		}
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -