Advertisement
Guest User

Untitled

a guest
Jul 4th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. package program.zozidalom.remoteconsole;
  2.  
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import java.io.PrintWriter;
  8. import java.net.Socket;
  9.  
  10.  
  11. public class Gui {
  12. private Main main;
  13. private JPanel p;
  14. private JButton s;
  15. private JButton b;
  16. private JFrame f;
  17. private JPasswordField pf;
  18.  
  19. public void createGui() {
  20. f = new JFrame("RemoteConsole");
  21. f.setVisible(true);
  22. f.setSize(800, 600);
  23. f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  24. p = new JPanel();
  25. p.setBackground(Color.gray);
  26. s = new JButton("Stop");
  27. b = new JButton("Login");
  28. pf = new JPasswordField("Password comes here");
  29. p.add(b);
  30. p.add(pf);
  31. f.add(p);
  32. p.add(s);
  33. b.addActionListener(new ActionListener() {
  34. @Override
  35. public void actionPerformed(ActionEvent actionEvent) {
  36. char[] jk = pf.getPassword();
  37. String pw = String.valueOf(jk);
  38. System.out.print("Button pressed");
  39. System.out.print(pw);
  40. sendPw(pw);
  41.  
  42. }
  43. });
  44. s.addActionListener(new ActionListener() {
  45. @Override
  46. public void actionPerformed(ActionEvent actionEvent) {
  47. sendMsg("stop");
  48. System.out.print("Msg sent...");
  49. }
  50. });
  51.  
  52. }
  53.  
  54. public void sendPw(String pw) {
  55. try {
  56. Socket socket = new Socket("127.0.0.1", 1778);
  57. PrintWriter writer = new PrintWriter(socket.getOutputStream());
  58. writer.print(pw);
  59. writer.close();
  60. socket.close();
  61.  
  62.  
  63. } catch (Exception ex) {
  64.  
  65. }
  66.  
  67. }
  68.  
  69. public void sendMsg(String str) {
  70. try {
  71. Socket socket = new Socket("127.0.0.1", 1777);
  72. PrintWriter writer = new PrintWriter(socket.getOutputStream());
  73. writer.print(str);
  74. writer.close();
  75. socket.close();
  76.  
  77.  
  78. } catch (Exception ex) {
  79.  
  80. }
  81.  
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement