Advertisement
Guest User

Untitled

a guest
May 13th, 2012
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.72 KB | None | 0 0
  1. package com.client.core;
  2.  
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5.  
  6. import javax.swing.JComponent;
  7. import javax.swing.JLabel;
  8. import javax.swing.JOptionPane;
  9. import javax.swing.JTextField;
  10.  
  11. public class ActLis implements ActionListener {
  12.    
  13.     private Main main = new Main();;
  14.     private JTextField ipadress = new JTextField(),
  15.             portnumber = new JTextField(),
  16.             actionField;
  17.    
  18.     private String username;
  19.    
  20.     final JComponent[] ipinp = new JComponent[]{new JLabel("Enter Hostname (IP Adress): "),
  21.             ipadress,
  22.             new JLabel("Enter Port number: "), portnumber};
  23.    
  24.    
  25.     public ActLis(){
  26.     }
  27.    
  28.     public ActLis(JTextField t){
  29.         actionField = t;
  30.  
  31.     }
  32.    
  33.     @Override
  34.     public void actionPerformed(ActionEvent e) {
  35.     String cmd = e.getActionCommand();
  36.    
  37.    
  38.     if(cmd == "Exit"){
  39.         System.exit(0);
  40.     } else if(cmd == "Connect to IP"){
  41.         main.getSocketM().close();
  42.         JOptionPane.showMessageDialog(null, ipinp, "Connect to IP", JOptionPane.PLAIN_MESSAGE);
  43.         main.getSocketM().connect(ipadress.getText(), Integer.parseInt(portnumber.getText()));
  44.        
  45.         try{
  46.         //network.close();
  47.         //network = new SocketManager(ipadress.getText(),Integer.parseInt(portnumber.getText()));
  48.         }catch(Exception ee){
  49.             JOptionPane.showMessageDialog(null, "Could not connect. Check IP adress or internet connection","Error - Could not connect", JOptionPane.ERROR_MESSAGE);
  50.         }
  51.        
  52.     } else if (cmd == "chatWriter"){
  53.        
  54.         if( actionField.getText() != ""){      
  55.             main.getSocketM().send(actionField.getText());
  56.             actionField.setText("");
  57.             actionField.requestFocus();
  58.            
  59.         }
  60.        
  61.     } else if (cmd == "setUsername"){
  62.         username = actionField.getText();
  63.         System.out.println("Username is " + username);
  64.        
  65.        
  66.     }
  67.        
  68.        
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement