connection and protocol
import java.awt.*;
import java.io.*;
import java.awt.event.*;
import java.net.*;
import java.util.*;
public class Client extends Frame implements ActionListener
{
PrintStream ps = null;
PrintWriter pw = null;
BufferedReader bf=null;
Socket s = null;
Button emailButton = new Button("Find Email");//Button for finding email
Button nameButton = new Button("Find Name");//Button for finding staff name
Button numberButton = new Button("Number");//Button for number of members of staff
Button quitButton = new Button("Quit");//Button for quitting
TextField inputData = new TextField(); //For communicating arguments
TextField results = new TextField();//Results text field
Label inputDataLabel = new Label("Input data");
Label resultsLabel = new Label("Results");
public Client() {
super("Presentation");
setLayout(new GridLayout(4,2));
add(emailButton);
add(nameButton);
add(numberButton);
add(quitButton);
add(inputDataLabel);
add(inputData);
add(resultsLabel);
add(results);
//Register listeners
numberButton.addActionListener(this);
nameButton.addActionListener(this);
emailButton.addActionListener(this);
quitButton.addActionListener(this);
initConnection();
}
public void actionPerformed(ActionEvent ae)
{
String name = inputData.getText();
try
{
pw.println(inputData.getText());
String reply = bf.readLine();
results.setText(reply);
}
catch(Exception e)
{System.out.println("Problem establishing a connection 1");}
{
try
{
s = new Socket("127.0.0.1", 1200);
InputStream is = s.getInputStream();
BufferedReader bf = new BufferedReader(new InputStreamReader(is));
}
catch(java.io.IOException e)
{System.out.println("Problem establishing a connection");}
}
public static void main(String[] args)
{
Client cf = new Client();
cf.setSize(300,200); //300 pixels by 200 pixels
cf.setVisible(true);
}
}
Any help on the code above would be appreciated.
Firstly, I want to confirm that I have established a connection with the server I have created ,what is the simplest way of doing this?
Secondly, this particular piece of code aims to use a protocol to complete a range of tasks. I'm not familiar with ActionListener but want to create code that initiates one of four methods depending on the button selected. Again any guidance would be appreciated.

