package myPackage;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Line2D;
import java.util.LinkedList;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
public class SecondPanel extends JPanel {
private static final long serialVersionUID = 8241054192211241466L;
SecondPanel(MainDialog mainDialog) {
this.setBounds(0, 0, mainDialog.getWidth(), mainDialog.getHeight());
this.setLayout(new FlowLayout());
}
private void initUnchangedPaint(Graphics g) {
Graphics2D bg = (Graphics2D) g;
bg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);// 设置平滑
bg.setStroke(new BasicStroke(2.0f));
Line2D.Double leftLine = new Line2D.Double(
(double) (1 * this.getWidth() / 10),
(double) (1 * this.getHeight() / 10),
(double) (1 * this.getWidth() / 10),
(double) (9 * this.getHeight() / 10));
bg.draw(leftLine);
Line2D.Double downLine = new Line2D.Double(
(double) (1 * this.getWidth() / 10),
(double) (9 * this.getHeight() / 10),
(double) (9 * this.getWidth() / 10),
(double) (9 * this.getHeight() / 10));
bg.draw(downLine);
bg.setStroke(new BasicStroke(1.0f));
Line2D.Double rightLine = new Line2D.Double(
(double) (9 * this.getWidth() / 10),
(double) (1 * this.getHeight() / 10),
(double) (9 * this.getWidth() / 10),
(double) (9 * this.getHeight() / 10));
bg.draw(rightLine);
Line2D.Double upLine = new Line2D.Double(
(double) (1 * this.getWidth() / 10),
(double) (1 * this.getHeight() / 10),
(double) (9 * this.getWidth() / 10),
(double) (1 * this.getHeight() / 10));
bg.draw(upLine);
FontMetrics fm = bg.getFontMetrics();
bg.setFont(new Font(null, Font.BOLD, 15));
bg.setColor(Color.blue);
String str1 = "固定分配、局部页面置换算法的比较";
bg.drawString(str1, 1 * this.getWidth() / 2 - fm.stringWidth(str1) / 2,
1 * this.getHeight() / 10 - (fm.getAscent() - fm.getDescent())
/ 2);
bg.setColor(Color.black);
String str2 = "分配的页框数目";
bg.drawString(str2, 1 * this.getWidth() / 2 - fm.stringWidth(str2) / 2,
9 * this.getHeight() / 10 + fm.getAscent() + fm.getHeight());
bg.drawImage(new ImageIcon("image//picture.png").getImage(),
9 * this.getWidth() / 10 + 20, 1 * this.getHeight() / 10,
Color.white, null);
}
private void initChangedPaint(Graphics g) {
Graphics2D bg = (Graphics2D) g;
bg.setStroke(new BasicStroke(0.5f, BasicStroke.CAP_BUTT,
BasicStroke.JOIN_ROUND, 0.5f, new float[] { 5, 10, }, 0f));
Line2D.Double dashHorLine = new Line2D.Double(
(double) (1 * this.getWidth() / 10),
(double) (1 * this.getHeight() / 2),
(double) (9 * this.getWidth() / 10),
(double) (1 * this.getHeight() / 2));
bg.draw(dashHorLine);
Line2D.Double dashVerLine = new Line2D.Double(
(double) (1 * this.getWidth() / 2),
(double) (1 * this.getHeight() / 10),
(double) (1 * this.getWidth() / 2),
(double) (9 * this.getHeight() / 10));
bg.draw(dashVerLine);
FontMetrics fm = bg.getFontMetrics();
String str3 = "0";
bg.drawString(str3, 1 * this.getWidth() / 2 - fm.stringWidth(str3) / 2,
9 * this.getHeight() / 10 + fm.getAscent());
bg.drawString(str3, 1 * this.getWidth() / 10 - fm.getAscent(),
1 * this.getHeight() / 2 + fm.stringWidth(str3) / 2);
}
private void addPaint(Graphics g) {
drawLinePaint(g);
drawColPaint(g, 1, 30, 1, 9);
drawRowPaint(g, 5, 100, 1, 9);
}
private void drawLinePaint(Graphics g) {
Graphics2D bg = (Graphics2D) g;
bg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);// 设置平滑
if (MainDialog.opts == null || MainDialog.fifos == null
|| MainDialog.clocks == null || MainDialog.lrus == null
|| MainDialog.Sequence == null)
return;
String lack = "页面失效率";
g.drawString(lack, this.getWidth() / 10, this.getHeight() / 10 - 10);
bg.setFont(new Font(null, Font.BOLD, 10));
for (int i = 1; i < MainDialog.pageFrameNumber - 2; i++) {
int K = (8 * this.getWidth() / 10)
/ (MainDialog.pageFrameNumber - 2);
g.setColor(Color.red);
g.drawLine(1 * this.getWidth() / 10 + (i + 2 - 1) * K,
(int) (this.getHeight() / 10 + (1 - MainDialog.opts[i - 1])
* (8 * this.getHeight() / 10)), 1 * this.getWidth()
/ 10 + (i + 2) * K,
(int) (this.getHeight() / 10 + (1 - MainDialog.opts[i])
* (8 * this.getHeight() / 10)));
g.setColor(Color.BLUE);
g.drawLine(
1 * this.getWidth() / 10 + (i + 2 - 1) * K,
(int) (this.getHeight() / 10 + (1 - MainDialog.clocks[i - 1])
* (8 * this.getHeight() / 10)), 1 * this.getWidth()
/ 10 + (i + 2) * K,
(int) (this.getHeight() / 10 + (1 - MainDialog.clocks[i])
* (8 * this.getHeight() / 10)));
g.setColor(Color.GREEN);
g.drawLine(1 * this.getWidth() / 10 + (i + 2 - 1) * K,
(int) (this.getHeight() / 10 + (1 - MainDialog.lrus[i - 1])
* (8 * this.getHeight() / 10)), 1 * this.getWidth()
/ 10 + (i + 2) * K,
(int) (this.getHeight() / 10 + (1 - MainDialog.lrus[i])
* (8 * this.getHeight() / 10)));
g.setColor(Color.black);
g.drawLine(
1 * this.getWidth() / 10 + (i + 2 - 1) * K,
(int) (this.getHeight() / 10 + (1 - MainDialog.fifos[i - 1])
* (8 * this.getHeight() / 10)), 1 * this.getWidth()
/ 10 + (i + 2) * K,
(int) (this.getHeight() / 10 + (1 - MainDialog.fifos[i])
* (8 * this.getHeight() / 10)));
}
}
private void drawRowPaint(Graphics g, int space, int arrange,
double rowBegin, double rowEnd) {
Graphics2D bg = (Graphics2D) g;
bg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);// 设置平滑
bg.setStroke(new BasicStroke(0.5f));
FontMetrics fm = bg.getFontMetrics();
int sign = 0;
for (double i = 1; i <= 9; i = i + (double) (9 - 1)
/ ((arrange / space))) {
bg.setStroke(new BasicStroke(0.5f));
Line2D.Double longLine = new Line2D.Double((double) (rowBegin
* this.getWidth() / 10),
(double) (i * this.getHeight() / 10),
(double) ((rowBegin - 0.1) * this.getWidth() / 10),
(double) (i * this.getHeight() / 10));
bg.draw(longLine);
bg.drawString(sign + "",
(int) ((rowBegin * this.getWidth()) / 10 - 10 - fm
.getAscent()), (int) ((10 - i) * this.getHeight()
/ 10 + fm.stringWidth(sign + "") / 2));
sign = sign + space;
bg.setStroke(new BasicStroke(0.25f, BasicStroke.CAP_BUTT,
BasicStroke.JOIN_ROUND, 0.5f, new float[] { 5, 10, }, 0f));
Line2D.Double paintDashVorLine = new Line2D.Double(
(double) (rowBegin * this.getWidth() / 10), (double) (i
* this.getHeight() / 10), (double) (rowEnd
* this.getWidth() / 10), (double) (i
* this.getHeight() / 10));
bg.draw(paintDashVorLine);
}
}
private void drawColPaint(Graphics g, int space, int arrange,
double rowBegin, double rowEnd) {
Graphics2D bg = (Graphics2D) g;
bg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);// 设置平滑
bg.setStroke(new BasicStroke(0.5f));
FontMetrics fm = bg.getFontMetrics();
int mark = 0;
int sign = 0;
for (double i = 1.0; i <= 9; i = i + (double) (9 - 1)
/ ((arrange / space) * 4 + 1)) {
if (mark % 4 == 0) {
bg.setStroke(new BasicStroke(0.5f));
Line2D.Double longLine = new Line2D.Double((double) (i
* this.getWidth() / 10), (double) (rowEnd
* this.getHeight() / 10),
(double) (i * this.getWidth() / 10),
(double) ((rowEnd + 0.1) * this.getHeight() / 10));
bg.draw(longLine);
bg.drawString(sign + "", (int) (i * this.getWidt
- 1
- 2
前往页