Advertisement
Guest User

Untitled

a guest
May 27th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. import java.awt.event.MouseEvent;
  2. import java.awt.event.MouseListener;
  3. import java.io.IOException;
  4. import java.io.OutputStream;
  5. import java.net.Socket;
  6.  
  7. import javax.swing.JButton;
  8.  
  9. public class Button extends JButton implements MouseListener {
  10.  
  11.  
  12. /**
  13. *
  14. */
  15. private static final long serialVersionUID = 1L;
  16. private String name;
  17. private int state;
  18. private Socket mainsocket;
  19. public GuiController button;
  20.  
  21.  
  22. public Button(String str, int state, Socket socket) {
  23. super(str);
  24. this.name = str;
  25. this.state = state;
  26. this.mainsocket = socket;
  27. this.addMouseListener(this);
  28. }
  29.  
  30. @Override
  31. public void mouseClicked(MouseEvent e) {
  32. // TODO Auto-generated method stub
  33.  
  34. }
  35.  
  36. @Override
  37. public void mousePressed(MouseEvent e) {
  38. if(e.getSource() == button.getForward()) {
  39. state = 1;
  40. }
  41.  
  42. else if(e.getSource() == button.getBackward()) {
  43. state = 2;
  44. }
  45.  
  46. else if(e.getSource() == button.getLeft()) {
  47. state = 3;
  48. }
  49.  
  50. else if(e.getSource() == button.getRight()) {
  51. state = 4;
  52. }
  53.  
  54. try {
  55. OutputStream os = mainsocket.getOutputStream();
  56. os.write(state);
  57. } catch (IOException e1) {
  58. // TODO Auto-generated catch block
  59. e1.printStackTrace();
  60. }
  61.  
  62.  
  63.  
  64. }
  65.  
  66. @Override
  67. public void mouseReleased(MouseEvent e) {
  68. state = 0;
  69.  
  70. try {
  71. OutputStream os = mainsocket.getOutputStream();
  72. os.write(state);
  73. } catch (IOException e1) {
  74. // TODO Auto-generated catch block
  75. e1.printStackTrace();
  76. }
  77.  
  78.  
  79. }
  80.  
  81. @Override
  82. public void mouseEntered(MouseEvent e) {
  83. // TODO Auto-generated method stub
  84.  
  85. }
  86.  
  87. @Override
  88. public void mouseExited(MouseEvent e) {
  89. // TODO Auto-generated method stub
  90.  
  91. }
  92.  
  93. public int getState() {
  94. return state;
  95. }
  96.  
  97.  
  98.  
  99.  
  100.  
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement