我已經創建了一個簡單的Web服務功能,如下所示;簡單的Web服務添加兩個數字
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package ws;
import javax.jws.WebService;
/**
*
* @author Joe
*/
@WebService()
public class Add2Int {
public int add(int a, int b) {
return (a+b);
}
}
我創建了一個非常簡單的gui,允許用戶輸入2個數字,哪個應該輸出結果,但這是行不通的?我嘗試沒有gui,它的工作原理,但是當我建立gui它不起作用?這裏是我的事情,邊碼
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package myjavawsclient;
//import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
*
* @author Joe
*/
public class Calculator extends JFrame implements FocusListener {
JTextField value1 = new JTextField("", 5);
JLabel plus = new JLabel("+");
JTextField value2 = new JTextField("",5);
JLabel equals = new JLabel("=");
JTextField sum = new JTextField("", 5);
public Calculator() {
super("The Calculator");
setSize(350,90);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
FlowLayout flow = new FlowLayout(FlowLayout.CENTER);
setLayout(flow);
// add the listners
value1.addFocusListener(this);
value2.addFocusListener(this);
// set up sum field
sum.setEditable(true);
//add componets
add(value1);
add(plus);
add(value2);
add(equals);
add(sum);
setVisible(true);
}
public void focusGained(FocusEvent event){
try { // Call Web Service Operation
ws.Add2IntService service = new ws.Add2IntService();
ws.Add2Int port = service.getAdd2IntPort();
// TODO initialize WS operation arguments here
int result = 0;
int result2 = 0;
result = Integer.parseInt(value1.getText());
result2 = Integer.parseInt(value2.getText());
int total = port.add(result, result2);
sum.setText("" +total);
//float plusTotal = Float.parseFloat(value1.getText()) +
Float.parseFloat(value2.getText());
} catch (Exception ex) {
// TODO handle custom exceptions here
//value1.setText("0");
//value2.setText("0");
//sum.setText("0");
}
}
public void focusLost(FocusEvent event){
focusGained(event);
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Calculator frame = new Calculator();
}
}
,我沒有得到我只是不能從2號獲得任何結果的任何錯誤,例如1 + 1 = 2一樣,但我的應用程序,它允許用戶輸入1 + 1 =?但問號沒有顯示。
我想知道是否有人可以爲我解決這個問題。哦,我使用NetBeans和GlassFish應用服務器與WSDL
喬