package GPClient; import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.net.InetAddress; /** *

Title:

*

Description:

*

Copyright: Copyright (c) 2000

*

Company:

* @author not attributable * @version 1.0 */ public class ConnectDialog extends JDialog { Game game; JPanel panel1 = new JPanel(); BorderLayout borderLayout2 = new BorderLayout(); FlowLayout flowLayout1 = new FlowLayout(); JLabel jLabel1 = new JLabel(); JFormattedTextField jFormattedTextField1 = new JFormattedTextField(new IPaddressFormatter()); JPanel Panel2 = new JPanel(); FlowLayout flowLayout2 = new FlowLayout(); JLabel jLabel2 = new JLabel(); JPanel Panel3 = new JPanel(); FlowLayout flowLayout3 = new FlowLayout(); JButton ConnectButton = new JButton(); JTextField jTextField1 = new JTextField(); public ConnectDialog(Frame frame, String title, boolean modal) { super(frame, title, modal); game = (Game) frame; try { jbInit(); pack(); } catch(Exception ex) { ex.printStackTrace(); } } public ConnectDialog() { this(null, "", false); } private void jbInit() throws Exception { panel1.setLayout(flowLayout1); this.getContentPane().setLayout(borderLayout2); jLabel1.setText("Server IP Address:"); Panel2.setLayout(flowLayout2); jLabel2.setRequestFocusEnabled(true); jLabel2.setText("Server Port nr:"); Panel3.setLayout(flowLayout3); ConnectButton.setActionCommand("ConnectButton"); ConnectButton.setText("Connect"); ConnectButton.addActionListener(new ConnectDialog_ConnectButton_actionAdapter(this)); jFormattedTextField1.setText(""); jFormattedTextField1.setPreferredSize(new Dimension(128, 19)); jTextField1.setText("5000"); getContentPane().add(panel1, BorderLayout.NORTH); panel1.add(jLabel1, null); panel1.add(jFormattedTextField1, null); this.getContentPane().add(Panel2, BorderLayout.CENTER); Panel2.add(jLabel2, null); Panel2.add(jTextField1, null); this.getContentPane().add(Panel3, BorderLayout.SOUTH); Panel3.add(ConnectButton, null); } void ConnectButton_actionPerformed(ActionEvent e) { int port = Integer.parseInt( jTextField1.getText() ); if( jFormattedTextField1.getValue() != null){ game.setServerIP( (InetAddress) jFormattedTextField1.getValue()); if( port > 1000){ game.setServerPort(port); close(); } else jTextField1.setText(""); } else jFormattedTextField1.setText("___.___.___.___"); } //Overridden so we can exit when window is closed protected void processWindowEvent(WindowEvent e) { if (e.getID() == WindowEvent.WINDOW_CLOSING) { close(); } super.processWindowEvent(e); } //Close the dialog void close() { dispose(); } } class ConnectDialog_ConnectButton_actionAdapter implements java.awt.event.ActionListener { ConnectDialog adaptee; ConnectDialog_ConnectButton_actionAdapter(ConnectDialog adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.ConnectButton_actionPerformed(e); } }