?? readmac.java
字號:
package work;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import javax.swing.*;
public class ReadMAC {
String line="";
String mac="";
JFrame jf = new JFrame("獲取本機MAC地址");
JButton jb1 = new JButton("獲取");
JButton jb2 = new JButton("清除");
JLabel jt = new JLabel("");
public ReadMAC(){
//界面及事情
jf.setLayout(new GridLayout(2,1));
jf.setBounds(100, 100, 400,150);
jf.setBackground(Color.GRAY);
jf.setResizable(false);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.add(jb1);
jf.add(jb2);
jf.add(jt);
jf.setVisible(true);
jb1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
get();
jt.setText("本機MAC地址:"+mac);
}
});
jb2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
get();
jt.setText("");
}
});
}
//獲取本機MAC地址的方法
void get(){
try{
Process process = Runtime.getRuntime().exec("cmd /c ipconfig /all");//獲取一個運行的進程
BufferedReader buff= new BufferedReader(new InputStreamReader(process.getInputStream()));
while ( (line = buff.readLine())!= null ){
if(line.indexOf("Physical Address. . . . . . . . . :") != -1){
if(line.indexOf(":") != -1){
mac = line.substring(44);
}
}
}
}
catch(Exception e){
System.out.println(e.getMessage());
System.out.println(e.equals(e));
}
}
public static void main(String args[]){
new ReadMAC();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -