Lab assignment 3 - Rock, paper, scissors

This program is run against a server. Here is the server program. If the server is down, start it on the computer you're working on.

In lecture 4 a server program was written which plays "rock, paper, scissors" with its clients. The code is available here. Your task is to write a graphical client program using only Swing components, namely JFrame, JTextField, JLabel, JButton, ImageIcon and Box. The game is widely known, and you can find useful material at Rock, paper, scissors, e.g. three gif images.

Note: the server speaks Swedish, so either change the server code (and run the server locally), or translate the replies from the server inside the client program ("sten"->rock, "sax"->scissors, "påse"->paper).

A simple client

Start off by making a client without the graphics, using the following code to open a connection to the server.
  try                                                          {
     Socket socket=new Socket("",4712)           ;
     BufferedReader in=new BufferedReader(new InputStreamReader(
                           socket.getInputStream()))           ;
     PrintWriter ut=new PrintWriter(socket.getOutputStream())  ;
     ut.println("Charlotta"); ut.flush()                       ;
     System.out.println(in.readLine())                         ;}
If the server is down, try the one at rungner by replacing "" with "". The client should send your name to the server listening on port 4712 and display the answer you receive. Remember to do ut.flush(), or the name won't be sent. Once the client works you can focus completely on the graphical interface.

The Swing components

Your program should be a
public class Client extends JFrame implements ActionListener{
where the left half is your game area and the right half is that of the computer. Use BoxLayout since this often gives the best results. Each game area is a vertical Box which contains, in order from top to bottom, Let GameArea be an inner class, to make it easy to create two instances of it beside each other in a horizontal box. The advantage of a box is the ability to put fixed spaces between the components inside. With the declaration Box box=Box.createHorizontalBox(); one can do this:
   box.add(me);  //GameArea me=new GameArea("Me:"); has already been declared
   box.add(Box.createHorizontalStrut(20)); //Spacer
   box.add(you); //GameArea you=new GameArea("Computer:"); has already been declared

Extra assignment: Add sound effects! (May require headphones on some computers).

Hints and advice