Guest User

Untitled

a guest
Jan 21st, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package ws;
  6. import javax.jws.WebService;
  7. /**
  8. *
  9. * @author Joe
  10. */
  11. @WebService()
  12. public class Add2Int {
  13. public int add(int a, int b) {
  14. return (a+b);
  15. }
  16. }
  17.  
  18. /*
  19. * To change this template, choose Tools | Templates
  20. * and open the template in the editor.
  21. */
  22.  
  23. package myjavawsclient;
  24. //import java.io.*;
  25. import javax.swing.*;
  26. import java.awt.*;
  27. import java.awt.event.*;
  28.  
  29. /**
  30. *
  31. * @author Joe
  32. */
  33. public class Calculator extends JFrame implements FocusListener {
  34. JTextField value1 = new JTextField("", 5);
  35. JLabel plus = new JLabel("+");
  36. JTextField value2 = new JTextField("",5);
  37. JLabel equals = new JLabel("=");
  38. JTextField sum = new JTextField("", 5);
  39.  
  40. public Calculator() {
  41. super("The Calculator");
  42. setSize(350,90);
  43. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  44. FlowLayout flow = new FlowLayout(FlowLayout.CENTER);
  45. setLayout(flow);
  46. // add the listners
  47. value1.addFocusListener(this);
  48. value2.addFocusListener(this);
  49. // set up sum field
  50. sum.setEditable(true);
  51. //add componets
  52. add(value1);
  53. add(plus);
  54. add(value2);
  55. add(equals);
  56. add(sum);
  57. setVisible(true);
  58. }
  59.  
  60. public void focusGained(FocusEvent event){
  61. try { // Call Web Service Operation
  62. ws.Add2IntService service = new ws.Add2IntService();
  63. ws.Add2Int port = service.getAdd2IntPort();
  64. // TODO initialize WS operation arguments here
  65. int result = 0;
  66. int result2 = 0;
  67. result = Integer.parseInt(value1.getText());
  68. result2 = Integer.parseInt(value2.getText());
  69.  
  70. int total = port.add(result, result2);
  71. sum.setText("" +total);
  72.  
  73. //float plusTotal = Float.parseFloat(value1.getText()) +
  74. Float.parseFloat(value2.getText());
  75.  
  76. } catch (Exception ex) {
  77. // TODO handle custom exceptions here
  78. //value1.setText("0");
  79. //value2.setText("0");
  80. //sum.setText("0");
  81. }
  82. }
  83.  
  84. public void focusLost(FocusEvent event){
  85. focusGained(event);
  86. }
  87.  
  88. /**
  89. * @param args the command line arguments
  90. */
  91. public static void main(String[] args) {
  92.  
  93. // TODO code application logic here
  94.  
  95. Calculator frame = new Calculator();
  96. }
  97. }
  98.  
  99. @WebMethod public int add(int a, int b){
  100. return (a+b);
  101. }
Add Comment
Please, Sign In to add comment