Java Reference
In-Depth Information
public GetRemoteTime()
{
hostInput = new JTextField(20);
add(hostInput, BorderLayout.NORTH);
display = new JTextArea(10,15);
//Following two lines ensure that word-wrapping
//occurs within the JTextArea…
display.setWrapStyleWord(true);
display.setLineWrap(true);
add(new JScrollPane(display),
BorderLayout.CENTER);
buttonPanel = new JPanel();
timeButton = new JButton("Get date and time ");
timeButton.addActionListener(this);
buttonPanel.add(timeButton);
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);
String theTime;
//Accept host name from the user…
String host = hostInput.getText();
fi nal int DAYTIME_PORT = 13;
try
{
//Create a Socket object to connect to the
//specifi ed host on the relevant port…
socket = new Socket(host, DAYTIME_PORT);
//Create an input stream for the above Socket
//and add string-reading functionality…
Scanner input =
new Scanner(socket.getInputStream());
//Accept the host's response via the
Search WWH ::




Custom Search