📄 statuspanel.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 + -