Java Reference
In-Depth Information
hostPanel.add(hostInput);
add(hostPanel,BorderLayout.NORTH);
report = new JTextArea(10,25);
add(report,BorderLayout.CENTER);
buttonPanel = new JPanel();
seekButton = new JButton("Seek server ports ");
seekButton.addActionListener(this);
buttonPanel.add(seekButton);
exitButton = new JButton("Exit");
exitButton.addActionListener(this);
buttonPanel.add(exitButton);
add(buttonPanel,BorderLayout.SOUTH);
}
public void actionPerformed(ActionEvent event)
{
if (event.getSource() == exitButton)
System.exit(0);
//Must have been the 'seek' button that was
//pressed, so clear the output area of any
//previous output…
report.setText("");
//Retrieve the URL from the input text fi eld…
String host = hostInput.getText();
try
{
//Convert the URL string into an INetAddress
//object…
InetAddress theAddress =
InetAddress.getByName(host);
report.append("IP address: "
+ theAddress + "\n");
for (int i = 0; i < 25; i++)
{
try
{
//Attempt to establish a socket on
//port i…
socket = new Socket(host, i);
//If no IOException thrown, there must
//be a service running on the port…
Search WWH ::




Custom Search