📄 frame1.java~5~
字号:
package getip;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import java.net.*;
/**
* <p>Title: no</p>
* <p>Description: This a Java builder program</p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: home</p>
* @author liujun
* @version 1.0
*/
public class Frame1 extends JFrame {
private JPanel contentPane;
private JLabel jLabel1 = new JLabel();
private JTextField jTextField1 = new JTextField();
private JButton jButton1 = new JButton();
private XYLayout xYLayout1 = new XYLayout();
private JLabel jLabel2 = new JLabel();
InetAddress myIPaddress=null;
InetAddress myServer=null;
//Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
//setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
jLabel1.setText("jLabel1");
contentPane.setLayout(xYLayout1);
this.setSize(new Dimension(333, 214));
this.setTitle("Frame Title");
jTextField1.setText("cs.hust.edu.cn");
jButton1.setText("jButton1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
jLabel2.setText("jLabel2");
contentPane.add(jLabel1, new XYConstraints(42, 73, 263, 25));
contentPane.add(jButton1, new XYConstraints(44, 18, 235, -1));
contentPane.add(jTextField1, new XYConstraints(48, 152, 241, -1));
contentPane.add(jLabel2, new XYConstraints(42, 107, 269, 23));
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
void jButton1_actionPerformed(ActionEvent e) {
//取得LOCALHOST的IP地址
try {
myIPaddress=InetAddress.getLocalHost();
}
catch (UnknownHostException e1) {
System.out.println("get Local Host Exception:"+e1);
}
//取得jTextField所指定的服务器IP地址
try {
myServer=InetAddress.getByName(jTextField1.getText());
}
catch (UnknownHostException e2) {
System.out.println("get remote Host Exception:"+e2);
}
//输出得到IP地址结果
jLabel1.setText("您的本地主机IP地址为:"+ myIPaddress.getHostAddress());
jLabel2.setText("您输入的服务器的IP地址:"+ myServer.getHostAddress());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -