Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2013
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.55 KB | None | 0 0
  1. package zarkopafilis.koding.io.rfslabs.servermanager;
  2.  
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5. import java.io.BufferedWriter;
  6. import java.io.IOException;
  7. import java.io.OutputStreamWriter;
  8.  
  9. public class SendListener implements ActionListener{
  10.  
  11.     private Frame f;
  12.    
  13.     public SendListener(Frame f){
  14.         this.f = f;
  15.     }
  16.    
  17.     public void actionPerformed(ActionEvent e){
  18.         System.out.println("a");
  19.         sendCommand();
  20.     }
  21.  
  22.     @SuppressWarnings("static-access")
  23.     public void sendCommand(){
  24.         if(f.started = true && !(f.cmdArea.getText().equalsIgnoreCase("Write your command here")) && !(f.cmdArea.getText() == null)){
  25.             if(!f.cmdArea.getText().equalsIgnoreCase("stop") || !f.cmdArea.getText().equalsIgnoreCase("reload")){
  26.             Thread sendCmd = new Thread(){
  27.                 @Override
  28.                 public void run(){
  29.                     f.log.append(f.cTag + "Sending command\n");
  30.                     final String command = f.cmdArea.getText();
  31.                     BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(f.outputStream));
  32.                     try {
  33.                         writer.write(command);
  34.                         writer.flush();
  35.                         writer.close();
  36.                         f.cmdArea.setText("Write your command here");
  37.                     } catch (IOException e) {
  38.                         e.printStackTrace();
  39.                     }
  40.                     f.log.append(f.cTag + "Sent command sucessfully\n");
  41.                     f.started = false;
  42.                 }
  43.             };
  44.            
  45.             sendCmd.start();
  46.  
  47.             }else{
  48.                 f.log.append(f.cTag + "This command is not allowed\n");
  49.             }
  50.            
  51.         }else{
  52.             f.log.append(f.cTag + "Please start your server first\n or make sure that you have entered a command\n");
  53.         }
  54.     }
  55.    
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement