📄 rooterframe1.java
字号:
package rooter;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import javax.swing.border.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class RooterFrame1 extends JFrame {
///////////////////////////////////////////////////
private final int MAX_VERTS = 20;
private final int INFINITY = 1000000;
private Vertex vertexList[]; // list of vertices
private int adjMat[][]; // adjacency matrix
private int nVerts; // current number of vertices
private int nTree; // number of verts in tree
private DistPar sPath[]; // array for shortest-path data
private int currentVert; // current vertex
private int startToCurrent; // distance to currentVert
////////////////////////////////////////////////////
JPanel contentPane;
XYLayout xYLayout1 = new XYLayout();
JPanel jPanel1 = new JPanel();
TitledBorder titledBorder1;
JLabel jLabel1 = new JLabel();
JButton router0 = new JButton();
JButton router1 = new JButton();
JButton router2 = new JButton();
JButton router3 = new JButton();
JButton router4 = new JButton();
TitledBorder titledBorder2;
TitledBorder titledBorder3;
JPanel jPanel4 = new JPanel();
TitledBorder titledBorder4;
JLabel jLabel2 = new JLabel();
XYLayout xYLayout3 = new XYLayout();
JTextField sendJTextField = new JTextField();
JLabel jLabel3 = new JLabel();
JButton send = new JButton();
JScrollPane jScrollPane1 = new JScrollPane();
JTextArea sendMes = new JTextArea();
JButton jButton2 = new JButton();
JScrollPane jScrollPane2 = new JScrollPane();
JTextArea jTextArea1 = new JTextArea();
JScrollPane jScrollPane3 = new JScrollPane();
JScrollPane jScrollPane4 = new JScrollPane();
JLabel jLabel5 = new JLabel();
JTextArea jTextArea2 = new JTextArea();
JTextArea jTextArea3 = new JTextArea();
JButton linkButton = new JButton();
FlowLayout flowLayout1 = new FlowLayout();
//Construct the frame
public RooterFrame1() {
//////////////////////////////////////////////////////////
vertexList = new Vertex[MAX_VERTS];
// adjacency matrix
adjMat = new int[MAX_VERTS][MAX_VERTS];
nVerts = 0;
nTree = 0;
for (int j = 0; j < MAX_VERTS; j++) // set adjacency
for (int k = 0; k < MAX_VERTS; k++) // matrix
adjMat[j][k] = INFINITY; // to infinity
sPath = new DistPar[MAX_VERTS]; // shortest paths
//////////////////////////////////////////////////////////
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
jLabel2.setFont(new java.awt.Font("Dialog", 1, 11));
jLabel2.setForeground(Color.blue);
jLabel2.setText("发送给");
titledBorder1 = new TitledBorder("模拟路由器");
titledBorder2 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white,new Color(178, 178, 178)),"链路状态信息");
titledBorder3 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white,new Color(178, 178, 178)),"路由表");
titledBorder4 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white,new Color(148, 145, 140)),"路由信息");
contentPane.setLayout(xYLayout1);
this.getContentPane().setBackground(UIManager.getColor(
"InternalFrame.inactiveTitleBackground"));
this.setJMenuBar(null);
this.setSize(new Dimension(550,480));
this.setTitle("链路状态路由");
this.setVisible(true);
contentPane.setForeground(Color.black);
jPanel1.setBackground(SystemColor.inactiveCaption);
jPanel1.setBorder(titledBorder1);
jPanel1.setLayout(flowLayout1);
jLabel1.setBackground(Color.pink);
jLabel1.setFont(new java.awt.Font("Dialog", 0, 15));
jLabel1.setForeground(Color.blue);
jLabel1.setBorder(BorderFactory.createRaisedBevelBorder());
jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
jLabel1.setHorizontalTextPosition(SwingConstants.CENTER);
jLabel1.setText("链路状态路由实验模拟");
jLabel1.setVerticalAlignment(SwingConstants.CENTER);
jLabel1.setVerticalTextPosition(SwingConstants.CENTER);
router0.setText("Router0");
router0.addActionListener(new RooterFrame1_router0_actionAdapter(this));
router1.setText("Router1");
router1.addActionListener(new RooterFrame1_router1_actionAdapter(this));
router2.setSelectedIcon(null);
router2.setText("Router2");
router2.addActionListener(new RooterFrame1_router2_actionAdapter(this));
router3.setText("Router3");
router3.addActionListener(new RooterFrame1_router3_actionAdapter(this));
router4.setText("Router4");
router4.addActionListener(new RooterFrame1_router4_actionAdapter(this));
jPanel4.setBorder(titledBorder4);
jPanel4.setLayout(xYLayout3);
sendJTextField.setText("");
jLabel3.setFont(new java.awt.Font("Dialog", 1, 11));
jLabel3.setForeground(Color.blue);
jLabel3.setText("号路由器");
send.setFont(new java.awt.Font("Dialog", 1, 13));
send.setForeground(Color.blue);
send.setActionCommand("发送信息");
send.setText("发送信息");
send.addActionListener(new RooterFrame1_send_actionAdapter(this));
sendMes.setText("");
jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
jButton2.setFont(new java.awt.Font("Dialog", 1, 13));
jButton2.setForeground(Color.blue);
jButton2.setText("处理路由信息");
jTextArea1.setToolTipText("");
jTextArea1.setText("");
jLabel5.setFont(new java.awt.Font("Dialog", 1, 13));
jLabel5.setForeground(Color.blue);
jLabel5.setIconTextGap(4);
jLabel5.setText("路由表");
jTextArea2.setText("");
jScrollPane3.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
jScrollPane3.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
jScrollPane2.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
jScrollPane2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
jTextArea3.setText("");
jScrollPane4.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
jScrollPane4.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
linkButton.setFont(new java.awt.Font("Dialog", 1, 13));
linkButton.setForeground(Color.blue);
linkButton.setText("链路信息");
contentPane.add(linkButton, new XYConstraints(22, 83, 107, -1));
jPanel4.add(jLabel2, new XYConstraints(6, 0, 41, 27));
jPanel4.add(sendJTextField, new XYConstraints(48, 1, 28, 26));
jPanel4.add(jLabel3, new XYConstraints(85, 1, 50, 28));
jPanel4.add(send, new XYConstraints(132, 1, 92, 28));
jPanel4.add(jButton2, new XYConstraints(339, 3, 119, 27));
contentPane.add(jLabel1, new XYConstraints(64, 1, 394, 30));
contentPane.add(jLabel5, new XYConstraints(277, 84, 61, 26));
jScrollPane2.getViewport().add(jTextArea1, null);
jScrollPane3.getViewport().add(jTextArea2, null);
contentPane.add(jPanel4, new XYConstraints(20, 235, 503, 202));
contentPane.add(jScrollPane4, new XYConstraints(277, 113, 245, 124));
jScrollPane4.getViewport().add(jTextArea3, null);
contentPane.add(jScrollPane3, new XYConstraints(20, 112, 240, 125));
jPanel4.add(jScrollPane1, new XYConstraints( -6, 35, 240, 135));
jScrollPane1.getViewport().add(sendMes, null);
jPanel4.add(jScrollPane2, new XYConstraints(251, 36, 245, 133));
jPanel1.add(router0, null);
jPanel1.add(router1, null);
jPanel1.add(router2, null);
jPanel1.add(router3, null);
jPanel1.add(router4, null);
//jPanel1.add(router1,null);
contentPane.add(jPanel1, new XYConstraints(20, 33, 502, 49));
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
public void router0_actionPerformed(ActionEvent e) {
jTextArea2.setText("");
jTextArea2.append("线路\t" + "延迟\n");
jTextArea2.append("0->1\t" + 5 + "\n");
jTextArea2.append("0->3\t" + 8 + "\n");
//------------------------------------------------------
jTextArea3.setText("");
jTextArea3.append("目的\t下一站\t时间\n");
add();
path(0);
//--------------------------------------------------------------
for(int j=0; j<nVerts; j++) // display contents of sPath[]
{
jTextArea3.append(String.valueOf(vertexList[j].label) + "\t");
char parent = vertexList[ sPath[j].parentVert].label;
jTextArea3.append(String.valueOf(parent)+"\t");
if(sPath[j].distance == INFINITY)
jTextArea3.append("inf\t\n");
else
jTextArea3.append(String.valueOf(sPath[j].distance)+"\n");
}
//--------------------------------------------------------------
cleartree();
}
//-------------------------------------------------------------
public void router1_actionPerformed(ActionEvent e) {
jTextArea2.setText("");
jTextArea2.append("线路\t" + "延迟\n");
jTextArea2.append("1->2\t" + "6\n");
jTextArea2.append("1->3\t" + "9\n");
jTextArea2.append("1->4\t" + "5\n");
//----------------------------------------------------------
jTextArea3.setText("");
jTextArea3.append("目的\t下一站\t时间\n");
add();
path(1);
//--------------------------------------------------------------
for(int j=0; j<nVerts; j++) // display contents of sPath[]
{
jTextArea3.append(String.valueOf(vertexList[j].label) + "\t");
char parent = vertexList[ sPath[j].parentVert ].label;
jTextArea3.append(String.valueOf(parent)+"\t");
if(sPath[j].distance == INFINITY)
jTextArea3.append("inf\t\n");
else
jTextArea3.append(String.valueOf(sPath[j].distance)+"\n");
}
//--------------------------------------------------------------
cleartree();
}
public void router2_actionPerformed(ActionEvent e) {
jTextArea2.setText("");
jTextArea2.append("线路\t" + "延迟\n");
jTextArea2.append("2->4\t" + "4\n");
jTextArea2.append("2->3\t" + "2\n");
jTextArea3.setText("");
jTextArea3.append("目的\t下一站\t时间\n");
add();
path(2);
//--------------------------------------------------------------
for (int j = 0; j < nVerts; j++) { // display contents of sPath[]
jTextArea3.append(String.valueOf(vertexList[j].label) + "\t");
char parent = vertexList[sPath[j].parentVert].label;
jTextArea3.append(String.valueOf(parent) + "\t");
if (sPath[j].distance == INFINITY)
jTextArea3.append("inf\t\n");
else
jTextArea3.append(String.valueOf(sPath[j].distance) + "\n");
}
//--------------------------------------------------------------
cleartree();
}
public void router3_actionPerformed(ActionEvent e) {
jTextArea2.setText("");
jTextArea2.append("线路\t" + "延迟\n");
jTextArea2.append("3->0\t" + "8\n");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -