JAVA编写的IP地址动态切换软件
一共有4个类 MainApplet.java ConfigFile.java ExecCmd.java SystemVars.java
下面是源代码:
1. MainApplet.java类
package com.zhangzhen.cmd;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import javax.swing.DefaultListModel;
import javax.swing.JApplet;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
public class MainApplet extends JApplet
{
private JButton jbtSave = new JButton("Save");
private JButton jbtDelete = new JButton("Delete");
private JButton jbtOK = new JButton("OK");
private JButton jbtAuto = new JButton("Auto");
private JButton jbtExit = new JButton("Exit");
private JLabel jlblIPAddress = new JLabel("IP地址:");
private JTextField jtfIPAddress = new JTextField();
private JLabel jlblSubnetMask = new JLabel("子网掩码: ");
private JTextField jtfSubnetMask = new JTextField();
private JLabel jlblGateway = new JLabel("默认网关:");
private JTextField jtfGateway = new JTextField();
private JLabel jlblDNSfirst = new JLabel("首选DNS服务器:");
private JTextField jtfDNSfirst = new JTextField();
private JLabel jlblDNSremark = new JLabel("备用DNS服务器:");
private JTextField jtfDNSremark = new JTextField();
private JLabel jlblConfigFileName = new JLabel("配置项名称:");
private JTextField jtfConfgFileName = new JTextField();
private JList jlConfigItem = new JList();
DefaultListModel dlmConfigItem = new DefaultListModel();
SystemVars configInfo = new SystemVars();
public void init()
{
super.setSize(1000,500);
setLayout(new BorderLayout());
//添加控制按钮面板
JPanel jpControl = new JPanel();
jpControl.setLayout(new FlowLayout());
// 设置按钮属性
jbtSave.setMnemonic(KeyEvent.VK_S);
jbtDelete.setMnemonic(KeyEvent.VK_DELETE);
jbtOK.setMnemonic(KeyEvent.VK_O);
jbtAuto.setMnemonic(KeyEvent.VK_A);
jbtExit.setMnemonic(KeyEvent.VK_E);
//添加控制按钮
jpControl.add(jbtSave);
jpControl.add(jbtDelete);
jpControl.add(jbtOK);
jpControl.add(jbtAuto);
jpControl.add(jbtExit);
add(jpControl,BorderLayout.SOUTH);
//添加输入配置信息面板
JPanel jpEnterConfigInfo = new JPanel();
jpEnterConfigInfo.setLayout(new GridLayout(6,2,0,40));
jpEnterConfigInfo.add(this.jlblIPAddress);
jpEnterConfigInfo.add(this.jtfIPAddress);
jpEnterConfigInfo.add(this.jlblSubnetMask);
jpEnterConfigInfo.add(this.jtfSubnetMask);
jpEnterConfigInfo.add(this.jlblGateway);
jpEnterConfigInfo.add(this.jtfGateway);
jpEnterConfigInfo.add(this.jlblDNSfirst);
jpEnterConfigInfo.add(this.jtfDNSfirst);
jpEnterConfigInfo.add(this.jlblDNSremark);
jpEnterConfigInfo.add(this.jtfDNSremark);
jpEnterConfigInfo.add(this.jlblConfigFileName);
jpEnterConfigInfo.add(this.jtfConfgFileName);
add(jpEnterConfigInfo,BorderLayout.EAST);
//添加配置项列表框面板
JPanel jpConfigItem = new JPanel();
jpConfigItem.setLayout(new BorderLayout());
//设置列表框属性
jlConfigItem.setSelectionBackground(Color.gray);
jlConfigItem.setSelectionForeground(Color.red);
jlConfigItem.setVisibleRowCount(10);
jlConfigItem.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jlConfigItem.setFixedCellHeight(30);
jlConfigItem.setFixedCellWidth(200);
jlConfigItem.setVisible(true);
//添加配置项列表框
jpConfigItem.add(jlConfigItem,BorderLayout.CENTER);
add(new JScrollPane(jlConfigItem),BorderLayout.WEST);
File configPath = new File("D:\IP_CONFIG");
configPath.mkdir();
this.jbtSave.addActionListener(new ActionListener()
{
补充:软件开发 , Java ,