Java各种网络代码
源代码在线查看: infopanel.java
package ipconfig; import java.awt.*; import javax.swing.*; import java.io.*; import java.net.*; import java.awt. event.*; import javax.swing.border.*; /** * Title: 获取网站信息 * Description: 该实例从Internet网络中获取一个服务器的IP地址、机器名称、子网掩码、DNS配置等信息。 * Copyright: Copyright (c) 2002 * Company: 北京师范大学计算机系 * @author 梁志伟 * @version 1.0 */ public class InfoPanel extends JPanel { GridLayout gridLayout1 = new GridLayout(5,2,1,1); JLabel displayLabel = new JLabel(); JLabel namelabel = new JLabel(); JLabel name = new JLabel(); JLabel ipLabel = new JLabel(); JLabel ip = new JLabel(); JLabel display = new JLabel(); JLabel host = new JLabel(); JLabel hostLabel = new JLabel(); JLabel full = new JLabel(); JLabel fullLabel = new JLabel(); Info cfg; public InfoPanel(Info cfg) { this.cfg =cfg; try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } private void jbInit() throws Exception { Border border=new BevelBorder(BevelBorder.RAISED); String names=cfg.getName() ; border=new TitledBorder(border,names); setBorder(border); displayLabel.setText("DisplayName:"); this.setLayout(gridLayout1); namelabel.setText("Name:"); name.setForeground(Color.red); name.setText(cfg.getName() ); ipLabel.setText("Address:"); ip.setForeground(Color.red); ip.setText(cfg.getAddress() ); display.setForeground(Color.red); display.setText(cfg.getDisplayName()); host.setForeground(Color.red); host.setText(cfg.getHostName()); hostLabel.setText("HosName:"); full.setForeground(Color.red); full.setText(cfg.getFullName() ); fullLabel.setText("FullName:"); this.add(displayLabel, null); this.add(display, null); this.add(namelabel, null); this.add(name, null); this.add(ipLabel, null); this.add(ip, null); this.add(hostLabel, null); this.add(host, null); this.add(fullLabel, null); this.add(full, null); } }