用Java来获取VMware ESX Server的信息可以通过一个第三方jar包进行方便的 *** 作:
Vijava – Vmware infrastructure(vSphere) java API
代码如下:
import javaawtBorderLayout;import javaawtFlowLayout;
import javaxswingJButton;
import javaxswingJDialog;
import javaxswingJFrame;
import javaxswingJPanel;
import javaxswingborderEmptyBorder;
import javaxswingJLabel;
import javaawtFont;
import javaawtPoint;
import javautilTimer;
import javautilTimerTask;
import javaawtColor;
public class MouseInfo extends JFrame {
private final JPanel contentPanel = new JPanel();
JLabel value_x = null;
JLabel value_y = null;
/
Launch the application
/
public static void main(String[] args) {
try {
MouseInfo info_frame = new MouseInfo();
info_framesetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);
info_framesetVisible(true);
info_framesetAlwaysOnTop(true);
Timer timer = new Timer();
timerschedule(new TimerTask() {
@Override
public void run() {
Point point = javaawtMouseInfogetPointerInfo()getLocation();
// Systemoutprintln("Location:x=" + pointx + ", y=" +
// pointy);
info_framevalue_xsetText("" + pointx);
info_framevalue_ysetText("" + pointy);
}
}, 100, 100);
} catch (Exception e) {
eprintStackTrace();
}
}
/
Create the dialog
/
public MouseInfo() {
setTitle("\u9F20\u6807\u5750\u6807\u83B7\u53D6\u5668");
setBounds(100, 100, 217, 156);
getContentPane()setLayout(new BorderLayout());
contentPanelsetBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane()add(contentPanel, BorderLayoutCENTER);
contentPanelsetLayout(null);
JLabel lblx = new JLabel("\u5750\u6807x:");
lblxsetFont(new Font("宋体", FontPLAIN, 15));
lblxsetBounds(22, 27, 66, 31);
contentPaneladd(lblx);
JLabel lbly = new JLabel("\u5750\u6807y:");
lblysetFont(new Font("宋体", FontPLAIN, 15));
lblysetBounds(22, 68, 66, 31);
contentPaneladd(lbly);
value_x = new JLabel("0");
value_xsetForeground(ColorBLUE);
value_xsetFont(new Font("宋体", FontPLAIN, 20));
value_xsetBounds(82, 27, 66, 31);
contentPaneladd(value_x);
value_y = new JLabel("0");
value_ysetForeground(ColorBLUE);
value_ysetFont(new Font("宋体", FontPLAIN, 20));
value_ysetBounds(82, 68, 66, 31);
contentPaneladd(value_y);
}
}
import javaioBufferedReader;
import javaioIOException;
import javaioInputStream;
import javaioInputStreamReader;
/
@author chenyun
@version $Id: CmdUtiljava, v 01 2015年8月19日 下午3:10:19 chenyun Exp $
/
public class CmdUtil {
/
获取某个Cmd命令的输出,以字符串返回。
@param cmdString CMD命令
@return
@throws IOException
/
public static String getCmdOutput(String cmdString) throws IOException{
// 1、开启子线程运行Cmd命令
Process proc = null;
String[] cmd = { "cmd", "/c", cmdString };
proc = RuntimegetRuntime()exec(cmd);
// 2、获取子线程InputStream
InputStream inputStream = procgetInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "GBK");
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
// 3、从流中读取数据
String line;
StringBuffer output = new StringBuffer();
while ((line = bufferedReaderreadLine()) != null) {
outputappend(line + "\r\n");
}
// 4、返回结果
return outputtoString();
}
/
测试桩
@param args
@throws IOException
/
public static void main(String[] args) throws IOException {
Systemoutprintln(CmdUtilgetCmdOutput("ipconfig"));
}
}
使用JNI调用WIN32 API ,先得到窗口句柄,再得到窗口的RECT
先WindowFromPoint(point);
再GetWindowRect(hwnd, &rect);
返回的rect,就是窗口的left/top/width/height
这个不麻烦、也不复杂,很简单的JNI。
以上就是关于Java怎么获取VMware中Vcenter/ServerInstance下的各种硬件信息全部的内容,包括:Java怎么获取VMware中Vcenter/ServerInstance下的各种硬件信息、java怎样获取鼠标在屏幕的坐标、java如何获取DOS窗口命令输出等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)