public static string GetLocalIpAddress()
{
string hostName = Dns.GetHostName();
IPHostEntry ip = Dns.GetHostEntry(hostName);
string IpAddress = Convert.ToString(ip.AddressList[2]);
return IpAddress.ToString();
}
Run Code Online (Sandbox Code Playgroud)
这有时会显示索引超出范围的异常应该是什么问题.提前致谢
public class Scal {
JFrame mainframe;
JPanel controlsPanel;
JPanel inputPanel;
JPanel opPanel;
JTextField inputbox;
String input1 = "";
public Scal(){
prepareCAL();
}
public static void main(String[] args) {
Scal cal = new Scal();
cal.showcontrols();
}
private void prepareCAL() {
mainframe = new JFrame();
mainframe.setSize(400, 400);
mainframe.setBackground(Color.GRAY);
inputPanel = new JPanel();
controlsPanel = new JPanel();
controlsPanel.setSize(new Dimension(200, 250));
opPanel = new JPanel();
opPanel.setSize(200, 250);
// opPanel.setMaximumSize(new Dimension(200, 250));
mainframe.add(inputPanel, BorderLayout.NORTH);
mainframe.add(controlsPanel, BorderLayout.CENTER);
mainframe.add(opPanel, BorderLayout.EAST);
mainframe.setVisible(true);
}
private void showcontrols() {
inputbox …Run Code Online (Sandbox Code Playgroud)