主题:java问题,着急,希望高手帮忙看一下!
这个程序现在是本地运行,要把它改成在网络运行。
一共两个文件
老师说就把actionperformed中的方法改一下就行
着急希望高手给解答一下,十分感谢!
TaxCalcApplet.java里的代码:
import javax.swing.JPanel;
import javax.swing.JApplet;
import javax.swing.JLabel;
import java.awt.Rectangle;
import javax.swing.JTextField;
import javax.swing.JButton;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import javax.xml.rpc.ParameterMode;
import javax.xml.namespace.QName;
public class TaxCalcApplet extends JApplet {
/**
*
*/
private static final long serialVersionUID = 5155545647115275026L;
private JPanel jContentPane = null;
private JLabel taxratelabel = null;
private JTextField taxRateTextField = null;
private JLabel goodsnamelabel = null;
private JTextField goodNameTextField = null;
private JLabel unitpricelabel = null;
private JTextField unitPriceTextField = null;
private JLabel pricewithtaxlabel = null;
private JTextField priceWithTaxTextField = null;
private JButton CalcButton = null;
/**
* This is the xxx default constructor
*/
public TaxCalcApplet() {
super();
}
/**
* This method initializes this
*
* @return void
*/
public void init() {
this.setSize(300, 200);
this.setContentPane(getJContentPane());
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
pricewithtaxlabel = new JLabel();
pricewithtaxlabel.setBounds(new Rectangle(21, 131, 65, 19));
pricewithtaxlabel.setText("Price");
unitpricelabel = new JLabel();
unitpricelabel.setBounds(new Rectangle(21, 92, 67, 20));
unitpricelabel.setText("Unit price");
goodsnamelabel = new JLabel();
goodsnamelabel.setBounds(new Rectangle(18, 56, 83, 25));
goodsnamelabel.setText("Goods Name");
taxratelabel = new JLabel();
taxratelabel.setBounds(new Rectangle(16, 17, 61, 25));
taxratelabel.setText("Tax Rate");
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(taxratelabel, null);
jContentPane.add(getTaxRateTextField(), null);
jContentPane.add(goodsnamelabel, null);
jContentPane.add(getGoodNameTextField(), null);
jContentPane.add(unitpricelabel, null);
jContentPane.add(getUnitPriceTextField(), null);
jContentPane.add(pricewithtaxlabel, null);
jContentPane.add(getPriceWithTaxTextField(), null);
jContentPane.add(getCalcButton(), null);
}
return jContentPane;
}
/**
* This method initializes taxRateTextField
*
* @return javax.swing.JTextField
*/
private JTextField getTaxRateTextField() {
if (taxRateTextField == null) {
taxRateTextField = new JTextField();
taxRateTextField.setBounds(new Rectangle(110, 16, 109, 23));
}
return taxRateTextField;
}
/**
* This method initializes goodNameTextField
*
* @return javax.swing.JTextField
*/
private JTextField getGoodNameTextField() {
if (goodNameTextField == null) {
goodNameTextField = new JTextField();
goodNameTextField.setBounds(new Rectangle(114, 60, 143, 21));
}
return goodNameTextField;
}
/**
* This method initializes unitPriceTextField
*
* @return javax.swing.JTextField
*/
private JTextField getUnitPriceTextField() {
if (unitPriceTextField == null) {
unitPriceTextField = new JTextField();
unitPriceTextField.setBounds(new Rectangle(111, 97, 110, 16));
}
return unitPriceTextField;
}
/**
* This method initializes priceWithTaxTextField
*
* @return javax.swing.JTextField
*/
private JTextField getPriceWithTaxTextField() {
if (priceWithTaxTextField == null) {
priceWithTaxTextField = new JTextField();
priceWithTaxTextField.setBounds(new Rectangle(108, 130, 126, 18));
}
return priceWithTaxTextField;
}
/**
* This method initializes CalcButton
*
* @return javax.swing.JButton
*/
private JButton getCalcButton() {
if (CalcButton == null) {
CalcButton = new JButton();
CalcButton.setBounds(new Rectangle(197, 162, 73, 23));
CalcButton.setText("Calc");
CalcButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
// TODO Auto-generated Event stub actionPerformed()
//TaxCalc taxCalc = new TaxCalc();
//int price = taxCalc.calcR(10, "test", 100);
//System.out.println(price);
int taxRate = 10;
String goodsName = "test";
int priceUnit =100;
try {
String URL = "http://localhost:8080/axis/services/TestService";
Service service = new Service();
Call call = (Call)service.createCall();
call.setTargetEndpointAddress(URL);
call.addParameter("taxrate", XMLType.XSD_INT, ParameterMode.IN);
call.addParameter("goodsname", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("priceunit", XMLType.XSD_INT, ParameterMode.IN);
call.setOperationName( new QName("TaxService", "calcR"));
call.setReturnType( org.apache.axis.encoding.XMLType.XSD_INT);
Object[] invokeArgs = new Object[] { new Integer(taxRate), new String(goodsName), new Integer(priceUnit) };
Integer result = (Integer)call.invoke(invokeArgs);
System.out.println(result.toString());
}catch(Exception e1) {e1.printStackTrace();}
}
});
};
return CalcButton;
}
}
另一个文件TaxCalc.java
public class TaxCalc {
public int calcR(int taxRate, String goods, int unitPrice)
{
int priceWithTax;
if (goods.equals("prepaidcard")){
priceWithTax = unitPrice;
} else {
priceWithTax = unitPrice*(100+taxRate)/100;
}
return priceWithTax;
}
}