View Javadoc

1   /***
2    * RoomSelectPanel.java
3    * created on: 2005-12-09
4    * created by: Bocian
5    */
6   package pl.agh.iosr.ballamigos.client.gui;
7   
8   import java.awt.event.ActionEvent;
9   import java.awt.event.ActionListener;
10  import java.rmi.RemoteException;
11  
12  import javax.swing.JButton;
13  import javax.swing.JLabel;
14  import javax.swing.JOptionPane;
15  import javax.swing.JPanel;
16  
17  import pl.agh.iosr.ballamigos.client.GameClient;
18  
19  
20  /***
21   * Please insert any comment here.
22   * @author Bocian
23   *
24   */
25  public class RoomSelectPanel extends JPanel
26  {
27  
28  	/***
29  	 * 
30  	 */
31  	private static final long serialVersionUID = 6457890518147508888L;
32  	
33  	
34  	
35  	
36  
37  	private JLabel selectLabel;
38  	
39  	public RoomSelectPanel()
40  	{
41  		
42  		selectLabel = new JLabel("Choose a room:");
43  		
44  		this.setLayout(null);
45  		
46  		selectLabel.setBounds(150,100,200,20);
47  		this.add(selectLabel);
48  		
49  		
50  		int y=0;
51  		for (String roomName : GameClient.getInstance().getRoomNames())
52  		
53  		{
54  			JButton selectButton = new JButton(roomName);
55  		
56  			selectButton.setBounds(150,130+y,200,20);
57  			
58  			y+=30;
59  			selectButton.addActionListener
60  			(
61  				new ActionListener()
62  				{
63  
64  					public void actionPerformed(ActionEvent arg0)
65  					{
66  						
67  							try
68  							{
69  								GameClient.getInstance().setRoomName(((JButton)arg0.getSource()).getText());
70  								GameClient.getInstance().getCommunicator().moveToRoom(((JButton)arg0.getSource()).getText());
71  								GameClient.getInstance().showRoomPanel();
72  							}
73  							catch (RemoteException exception)
74  							{
75  								JOptionPane.showMessageDialog(null, "Connection with server lost."
76  										 , "Error", JOptionPane.ERROR_MESSAGE);
77  								GameClient.getInstance().reset();
78  							}
79  					
80  					}
81  					
82  				}
83  		
84  			);
85  			
86  			this.add(selectButton);
87  		
88  		
89  		}
90  	}
91  
92  
93  }