Article View: borland.public.jbuilder.java.swing
Article #8707JTextField - Unable to throw IOException
From: Len Chiacchia
Date: Sun, 23 Jul 2000 00:00
Date: Sun, 23 Jul 2000 00:00
35 lines
1564 bytes
1564 bytes
I am trying to use a JTextField for the user to enter an IP address.
The user will click the JButton which then will run a routine that
will get the Internet Host Name. It can't get it to work. I get an
error that 'unreported exception: java.net.UnknownHostException; must
be caught or declared to be thrown.' Here is the applicable code
segments. Can anyone tell me what I missed???? Len
import java.io.*;
import java.net.*;
.
.
JTextField jTextField1 = new JTextField();
JTextField jTextField3 = new JTextField();
JButton jButton1 = new JButton();
.
.
jButton1.addActionListener(new java.awt.event.ActionListener() {.
.
.
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
.
.
jPanel3.add(jTextField1, new XYConstraints(176, 14, 117, -1));
jPanel3.add(jTextField3, new XYConstraints(176, 52, 201, -1));
.
.
public void jButton1_actionPerformed(ActionEvent e) {
String myIP = jTextField1.getText();
InetAddress inet = InetAddress.getByName(myIP);
jTextField3.setText(inet.getHostAddress());
}
Technical Details
Message-ID:
<397b69e8.14384932@nntp.ix.netcom.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,5868b15b38c39c4,start X-Google-Attributes: gid111d45,public From: lchiacch@ix.netcom.com (Len Chiacchia) Subject: JTextField - Unable to throw IOException Date: 2000/07/23 Message-ID: <397b69e8.14384932@nntp.ix.netcom.com> X-Deja-AN: 649898926 Organization: LCN Associates X-Server-Date: 23 Jul 2000 22:11:50 GMT Newsgroups: borland.public.jbuilder.java.swing