📄 graphicreseau.java
字号:
package fr.umlv.projet.fenetre.net;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JPanel;
/**
* This class is to display the state of the network transmit by graphic.
* @author HUANG Wei & MA Xiao Jun
*
*/
public class GraphicReseau extends JPanel{
private int debut = 0;
private int distance = 3;
private int w = 0;
private int h = 0;
private int Pic = 100;
private int lineYellow = 60;
private Color color;
private List<Integer> list = new ArrayList<Integer>();
protected@Override void paintComponent(Graphics graphic){
Graphics2D g = (Graphics2D)graphic;
super.paintComponent(g);
this.setBackground(Color.BLACK);
this.w = this.getWidth() - 1;
this.h = this.getHeight() - 1;
int x = w - debut;
while(x >= lineYellow){
g.setColor(new Color(0,100,60));
g.drawLine(x,0,x,h);
x = x - 10;
}
int y = h;
while(y >= 0){
g.drawLine(lineYellow,y,w,y);
y = y - 25;
}
g.setColor(color);
if(list != null){
int index = list.size() - 1;
while(index >= 1){
if(w <= lineYellow)
break;
int f1 = list.get(index)*h/Pic;
int f2 = list.get(index-1)*h/Pic;
g.drawLine(w,
h - f1,
w - distance,
h - f2);
w = w - distance;
index --;
}
}
g.setColor(Color.YELLOW);
g.drawLine(lineYellow,0,lineYellow,h);
g.drawString(Pic+" kb/s",lineYellow-(Pic+" kb/s").length()*7,10);
if(Pic%2!=0)
g.drawString((float)Pic/2+" kb/s",lineYellow-((float)Pic/2+" kb/s").length()*7,h/2);
else
g.drawString(Pic/2+" kb/s",lineYellow-(Pic/2+" kb/s").length()*7,h/2);
g.drawString("0 kb/s",lineYellow-("0 kb/s").length()*7,h);
}
/**
* refresh the state of transmit.
* @param debut to define the abscissa of begining to draw de cell.
* @param data value of the real time state of transmit(in or out).
* @param color we use two different color to draw line(in or out).
*/
public void refresh(int debut,int data,Color color){
this.debut = debut;
this.list.add(data);
this.color = color;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -