Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.client.core;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JComponent;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JTextField;
- public class ActLis implements ActionListener {
- private Main main = new Main();;
- private JTextField ipadress = new JTextField(),
- portnumber = new JTextField(),
- actionField;
- private String username;
- final JComponent[] ipinp = new JComponent[]{new JLabel("Enter Hostname (IP Adress): "),
- ipadress,
- new JLabel("Enter Port number: "), portnumber};
- public ActLis(){
- }
- public ActLis(JTextField t){
- actionField = t;
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- String cmd = e.getActionCommand();
- if(cmd == "Exit"){
- System.exit(0);
- } else if(cmd == "Connect to IP"){
- main.getSocketM().close();
- JOptionPane.showMessageDialog(null, ipinp, "Connect to IP", JOptionPane.PLAIN_MESSAGE);
- main.getSocketM().connect(ipadress.getText(), Integer.parseInt(portnumber.getText()));
- try{
- //network.close();
- //network = new SocketManager(ipadress.getText(),Integer.parseInt(portnumber.getText()));
- }catch(Exception ee){
- JOptionPane.showMessageDialog(null, "Could not connect. Check IP adress or internet connection","Error - Could not connect", JOptionPane.ERROR_MESSAGE);
- }
- } else if (cmd == "chatWriter"){
- if( actionField.getText() != ""){
- main.getSocketM().send(actionField.getText());
- actionField.setText("");
- actionField.requestFocus();
- }
- } else if (cmd == "setUsername"){
- username = actionField.getText();
- System.out.println("Username is " + username);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement