View Javadoc
1 /***
2 * Copyright (c) 2003 held jointly by the individual authors.
3 *
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published
6 * by the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; with out even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; if not, write to the Free Software Foundation,
16 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 *
18 * > http://www.gnu.org/copyleft/lesser.html
19 * > http://www.opensource.org/licenses/lgpl-license.php
20 */
21 package net.mlw.gfw.ext.basic.action;
22
23 import java.awt.event.ActionEvent;
24 import java.awt.event.ActionListener;
25
26 import javax.swing.JFrame;
27
28 import net.mlw.gfw.client.ClientContext;
29 import net.mlw.gfw.client.ClientUtils;
30 import net.mlw.gfw.event.EventHandler;
31 import net.mlw.gfw.ext.basic.client.component.ServerOptionsPanel;
32 import net.mlw.gfw.server.impl.DefaultServerDecorator;
33
34 /*** This ActionListener starts up a new server dialog.
35 *
36 * @author Matthew L. Wilson
37 * @version $Revision: 1.3 $ $Date: 2004/07/01 14:31:39 $
38 */
39 public class NewGameActionListener implements ActionListener
40 {
41 /*** The Owner of the dialog. **/
42 private JFrame frame;
43 /*** The DefaultServerDecorator that a Server will be passed to. **/
44 private DefaultServerDecorator server;
45 /*** The ClientContext, used to get the username of the player. **/
46 private ClientContext clientContext;
47 /*** The EventHandler used by the client gui. **/
48 private EventHandler client;
49 /*** The Class of the server implementation. **/
50 private Class serverClass;
51
52
53 /*** The standard constructor.
54 *
55 * @param frame The Owner of the dialog.
56 * @param server The DefaultServerDecorator that a Server will be passed to.
57 * @param serverClass The classsName of the server implementation.
58 * @param clientContext The ClientContext, used to get the username of the player.
59 * @param client The EventHandler used by the client gui.
60 */
61 public NewGameActionListener(JFrame frame, DefaultServerDecorator server, Class serverClass, ClientContext clientContext, EventHandler client)
62 {
63 this.frame = frame;
64 this.server = server;
65 this.clientContext = clientContext;
66 this.client = client;
67 this.serverClass = serverClass;
68 }
69
70 /***
71 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
72 */
73 public void actionPerformed(ActionEvent e)
74 {
75 ServerOptionsPanel options = ServerOptionsPanel.prompt(frame);
76 /*** Set the username on the context. * */
77 clientContext.setUserName(options.getUserName());
78 try
79 {
80 server.setServer(ClientUtils.startServer(options, serverClass));
81 server.addClient(clientContext.getUserName(), client);
82 }
83 catch (Exception ignore)
84 {
85 throw new RuntimeException(ignore);
86 }
87 }
88 }
This page was automatically generated by Maven