반응형

eXtream에서 보여주지 않는것 즉... cache table에 대한 정보를 보여주기 위해만든 것으로

가상 HOST의 정보를 표기한다.

myTable.java

Queue가 구현되어 있으나 사용하지는 않는다.

//---------------------------------------------------------------------------------

/*
 * Author: TheOne
 * Created: 2004년 5월 8일 토요일 오후 8:41:20
 * Modified: 2004년 5월 8일 토요일 오후 8:41:20
 */

import! java.awt.*;
import! javax.swing.*;
import! javax.swing.table.*;
import! java.util.Vector;
import! java.util.LinkedList;

public class myTable extends JFrame {

  JScrollPane pane1 = new JScrollPane();
  String data[][] = new String[0][6];
  String col[] = {"State","Queue","Attemp","Time-out","Protocol Addr.","Hardware Addr."};
  DefaultTableModel model = new DefaultTableModel(data,col){
    public boolean isCellEditable(int row, int col) {
      return false;
    }
  };

  LinkedList que = new LinkedList();

  JTable table = new JTable(model);
  JLabel jLabel1 = new JLabel();
  JLabel jLabel2 = new JLabel();
  JLabel jLabel3 = new JLabel();
  JLabel jLabel4 = new JLabel();
  JTextField tf_ip = new JTextField();
  JTextField tf_mac = new JTextField();
  JButton bu_update = new JButton();

  myTable() {
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }

  private void jbInit() throws Exception {
    this.getContentPane().setBackground(Color.white);
    this.setResizable(false);
    this.setState(Frame.NORMAL);
    this.setTitle("Cache Table");
    this.getContentPane().setLayout(null);
    table.getColumnModel().getColumn(0).setPreferredWidth(38);
    table.getColumnModel().getColumn(1).setPreferredWidth(42);
    table.getColumnModel().getColumn(2).setPreferredWidth(50);
    table.getColumnModel().getColumn(3).setPreferredWidth(70);
    table.getColumnModel().getColumn(4).setPreferredWidth(100);
    table.getColumnModel().getColumn(5).setPreferredWidth(100);
    table.setSelectionMode(0);
    table.getTableHeader().setReorderingAllowed(false);
    table.getTableHeader().setBackground(new Color(235,211,200));
    pane1.setBounds(new Rectangle(16, 140, 375, 226));
    jLabel1.setBackground(new Color(212, 218, 217));
    jLabel1.setFont(new java.awt.Font("SansSerif", 0, 12));
    jLabel1.setOpaque(true);
    jLabel1.setText("Computer 정보 : ");
    jLabel1.setBounds(new Rectangle(7, 9, 92, 23));
    jLabel2.setFont(new java.awt.Font("SansSerif", 0, 12));
    jLabel2.setOpaque(false);
    jLabel2.setText("● IP Address : ");
    jLabel2.setBounds(new Rectangle(17, 40, 88, 22));
    jLabel3.setBounds(new Rectangle(17, 67, 99, 22));
    jLabel3.setText("● MAC Address : ");
    jLabel3.setFont(new java.awt.Font("SansSerif", 0, 12));
    jLabel4.setFont(new java.awt.Font("SansSerif", 0, 12));
    jLabel4.setText("● Cache Table 정보  ");
    jLabel4.setBounds(new Rectangle(15, 115, 122, 22));
    tf_ip.setFont(new java.awt.Font("SansSerif", 0, 12));
    tf_ip.setEditable(false);
    tf_ip.setText("");
    tf_ip.setBounds(new Rectangle(120, 40, 163, 22));
    tf_mac.setFont(new java.awt.Font("SansSerif", 0, 12));
    tf_mac.setEditable(false);
    tf_mac.setText("");
    tf_mac.setBounds(new Rectangle(120, 67, 163, 22));
    bu_update.setBackground(new Color(212, 208, 255));
    bu_update.setBounds(new Rectangle(290, 115, 100, 23));
    bu_update.setText("Update");
    this.getContentPane().add(pane1, null);
    this.getContentPane().add(jLabel2, null);
    this.getContentPane().add(jLabel3, null);
    this.getContentPane().add(jLabel1, null);
    this.getContentPane().add(jLabel4, null);
    this.getContentPane().add(tf_ip, null);
    this.getContentPane().add(tf_mac, null);
    this.getContentPane().add(bu_update, null);
    pane1.getViewport().add(table, null);
    this.setSize(new Dimension(421, 410));
    //this.setVisible(true);
  }

  // 자기 자신의 ip를 설정한다.
  public void set_IP(String ip) {
    tf_ip.setText(ip);
  }
  // 자기 자신의 mac을 설정한다.
  public void set_Mac(String mac) {
    tf_mac.setText(mac);
  }
  // 자기 자신의 ip를 반환한다.
  public String get_IP() {
    return tf_ip.getText();
  }
  // 자기 자신의 mac을 반환한다.
  public String get_mac() {
    return tf_mac.getText();
  }
 // table의 정보를 업데이트 하는 메소드(parameter을 4개 받을때)
  public void updateRow(String st, String at, String pi, String hi) {
    try {
    for(int k=0;k<table.getRowCount();k++) {
      if(pi.equals(model.getValueAt(k,4))) {
        model.setValueAt(st,k,0);
        model.setValueAt(at,k,2);
        model.setValueAt(hi,k,5);
      }
    }
  }catch(Exception ex) {
    System.out.println("ex : " + ex);
    }
  }
 // table의 정보를 업데이트 하는 메소드(parameter값을 2개 받을때)
  public void updateRow(String ip, String mac) {
    for(int i=0;i<table.getRowCount();i++) {
      if(ip.equals(model.getValueAt(i,4).toString())) {
        model.setValueAt(ip, i, 4);
        model.setValueAt(mac,i,5);
      }
    }
  }
  // table에 새로운 값을 저장하는 메소드
  public void addRow(String st, String qu, String at, String ti, String pi, String hi) {
    removeRow(pi); // 중복된 값을 제거 하기 위해서
    String temp[] = {st, qu, at, ti, pi, hi};
   model.addRow(temp);
  }
  // Table에 저장된 값을 삭제하는 메소드
  public void removeRow(String ip) {
    for(int i=0;i<model.getRowCount();i++) {
      if(ip.equals(model.getValueAt(i,4))) {
        model.removeRow(i);
      }
    }
  }
  // Pending인지 Resolved인지 값을 넘겨줌
  public String get_State(String ip) {
    String item = null;
    for(int i=0;i<model.getRowCount();i++) {
      if(ip.equals(model.getValueAt(i,4))) {
        item = model.getValueAt(i,0).toString();
      }
    }

    return item;
  }

  // ip값이 있는지 없는지 체크하는것
  public boolean isIpRow(String ip) {
    boolean tf = true;
    for(int i=0;i<model.getRowCount();i++) {
      if(ip.equals(model.getValueAt(i,4))) {
        tf = false;
      }
    }
    return tf;
  }
  // 큐에 item을 저장하는 메소드
  public void push_que(String item) {
    que.addFirst(new String(item));
  }

  // 큐에서 item을 빼는 메소드
  public String pop_que() {
    String temp = (String)que.getLast();
    return temp;
  }
}

반응형
Posted by onlyTheOne
,