Hello everyone, I have work to do on a basic assignment that requires an ATM type of program working over XMLRPC so there is a server element where the data is held in a Hashtable and retrieved by a client form. I will state I am completely lost in the world of Java and do not understand it at all, as is the same for me with all programming languages. That said I do not want the program writing for me I would like a few pointers on where my program is falling down so I can attempt to work around it and learn from this exercise. So far I have spent a week playing around with the bits of code I have to get about as far as when I started ( We were given a previous exercise and code that founded the basis for this program so we could attempt to work it out)
Thank you for taking the time to even get this far it is much appreciated.
The code I have is as follows
The Client Form is
package XMLRPCClient;
import java.util.Vector;
import org.apache.xmlrpc.XmlRpcClient;
import org.apache.xmlrpc.XmlRpcException;
public class theClientForm extends javax.swing.JFrame
{
private String serverURL;
private XmlRpcClient client;
private Vector argBankAccounts;
private int BankAccounts;
private Vector argVect;
private String theName;
public String getBankAccounts()
{
try
{
theName = txtAccountBalance.getText();
argBankAccounts = new Vector();
argBankAccounts.addElement(theName);
BankAccounts = (Integer)client.execute("GetSize.sendTelNo", argBankAccounts);
System.out.println(argBankAccounts);
}
catch (XmlRpcException exception) {
System.err.println("JavaClient: XML-RPC Consumer Fault #" +
Integer.toString(exception.code) + ": " +
exception.getCause() + "" + exception.toString());
} catch (Exception exception) {
System.err.println("JavaClient: XML-RPC Consumer Fault #" + exception.toString());
}
String StrTelNo = Integer.toString(BankAccounts);
return StrTelNo;
}
public Vector getHash()
{
Vector Vect = new Vector();
try
{
argVect = new Vector<String>();
argVect.addElement("anything");
Vect = (Vector) client.execute("GetSize.sendHashtable", argVect);
}
catch (XmlRpcException exception) {
System.err.println("JavaClient: XML-RPC Consumer Fault #" +
Integer.toString(exception.code) + ": " +
exception.getCause() + "" + exception.toString());
} catch (Exception exception) {
System.err.println("JavaClient: XML-RPC Consumer Fault #" + exception.toString());
}
return Vect;
}
public theClientForm() {
initComponents();
try
{
serverURL = "http://localhost:8085/RPC2";
client = new XmlRpcClient(serverURL);
}
catch (Exception e)
{
e.printStackTrace();
}
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jButton1 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
txtAccountBalance = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("Enter Pin Number");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel1.setText("Bank Of Jar Var");
jLabel2.setText("Your Balance Is");
txtAccountBalance.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
txtAccountBalance.setText(":");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(145, 145, 145)
.addComponent(jLabel1)
.addContainerGap(147, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(170, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(31, 31, 31)
.addComponent(jButton1))
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtAccountBalance, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addGap(89, 89, 89)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(37, 37, 37)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(txtAccountBalance))
.addContainerGap(108, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
txtAccountBalance.setText(getBankAccounts());
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new theClientForm().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JTextField jTextField1;
private javax.swing.JLabel txtAccountBalance;
// End of variables declaration
}
The Bank Accounts Class in the server package is
package server;
import java.util.Hashtable;
import java.util.Enumeration;
import java.util.Vector;
public class BankAccounts {
private Hashtable BankAccounts = new Hashtable();
public BankAccounts() {
fillHash();
}
public void fillHash()
{
BankAccounts.put( "0001" , "1025");
}
public int getBankAccounts(String BankAccounts)
{
int intfoundit;
String foundit = (String)BankAccounts.get(BankAccounts);
intfoundit = Integer.parseInt(foundit);
return intfoundit;
}
public Vector getBankAccounts(){
Vector vhashtovect = new Vector();
String s = null;
String v = null;
Enumeration enumer;
Enumeration enumervalue;
enumer = BankAccounts.keys ();
enumervalue = BankAccounts.elements();
while ((enumer.hasMoreElements ()) && (enumervalue.hasMoreElements()))
{
s = (String) enumer.nextElement ();
v = (String) s + enumervalue.nextElement();
vhashtovect.add(v);
}
return vhashtovect;
}
}
And last but not least the XMLRPC Class looks like this
package server;
import org.apache.xmlrpc.WebServer;
public class XMLRPCServer
{
private BankAccounts theHashtable;
private int tNumber = 0;
public XMLRPCServer()
{
theHashtable = new BankAccounts();
}
public int sendTelNo(String TelRequest)
{
tNumber = (Integer)theHashtable.getBankAccounts(TelRequest);
return tNumber;
}
public static void main(String [] args)
{
try
{
int serverPort = 8085;
WebServer server = new WebServer(serverPort);
//server.addHandler("ourExample", new XMLRPCServer());
//server.addHandler("GetSize", new XMLRPCServer());
server.addHandler("GetBankAccounts", new XMLRPCServer());
server.addHandler("GetHashtable", new XMLRPCServer());
System.out.println("Server waiting for clients...");
}
catch (Exception e)
{
e.printStackTrace();
}
}
}