📄 b078b2de3186001c1081e06c574e7d11
字号:
import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;
public class Drawpicture extends Frame
{
public void paint(Graphics g)
{
int i=0;
Graphics2D g2=(Graphics2D)g;
Font f1=new Font("包",Font.BOLD,15); //设置字体为粗型
Font f2=new Font("数",Font.BOLD,15);
Font f3=new Font("/",Font.BOLD,15);
Font f4=new Font("个",Font.BOLD,15);
Font f5=new Font("时间/分",Font.BOLD,15);
Line2D.Double Line1=new Line2D.Double(40.0,40.0,40.0,300.0); //y直线
Line2D.Double Line2=new Line2D.Double(40.0,300.0,400.0,300.0); //x直线
Line2D.Double Line3=new Line2D.Double(40.0,40.0,37.0,43.0);
Line2D.Double Line4=new Line2D.Double(40.0,40.0,43.0,43.0); //y轴的箭头
Line2D.Double Line5=new Line2D.Double(397.0,297.0,400.0,300.0);
Line2D.Double Line6=new Line2D.Double(397.0,303.0,400.0,300.0); //y轴的箭头
g2.setPaint(Color.BLACK ); //设置颜色
g2.draw(Line1);
g2.draw(Line2);
g2.draw(Line3);
g2.draw(Line4);
g2.draw(Line5);
g2.draw(Line6);
g2.setFont(f1);
g2.drawString("包", 20, 55);
g2.setFont(f2);
g2.drawString("数", 20, 70);
g2.setFont(f3);
g2.drawString(" /", 20, 85);
g2.setFont(f4);
g2.drawString("个", 20, 100); //纵坐标单位
g2.setFont(f5);
g2.drawString("时间/分", 325,322); //横坐标单位
int j=295;
do
{ Font f6=new Font("TimesRoman",Font.BOLD,8);
g2.setFont(f6);
g2.drawString(Integer.toString((300-j)*100), 20, j);
// Line2D.Double Line7=new Line2D.Double(40.0,j,390.0,j);
g2.setPaint(Color.BLUE);
//g2.draw(Line7);
//g2.drawString(Integer.toString((300-j)*100), 30, j);
j-=5;
}while(j>=45); //画坐标的背景线颜色为蓝色
while(i<catchbao.perpack_i)
{ g2.setPaint(Color.BLACK); //以下画数据包的流量变化图(矩阵)
Rectangle2D.Double rec=new Rectangle2D.Double(40+i*7,300-catchbao.perpack[i],6,catchbao.perpack[i]);
g2.draw(rec);
g2.drawString(Integer.toString((i+1)*2), 40+i*7, 315);
g2.setStroke(new BasicStroke(2)); //设置线宽
i++;
}
}
public Drawpicture() //构造函数
{
this.addWindowListener
(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
Drawpicture.this.windowClosed();
}
}
);
this.setTitle("流量直观图");
this.setVisible(true); //设置窗口可见
this.pack();
}
protected void windowClosed() {
System.exit(0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -