Results 1 to 1 of 1
  1. #1
    schvuu is offline Member
    Join Date
    Oct 2013
    Rep Power

    Default Java RMI eclipse BANK, help!

    It's okey! Hold it whit them answers!! I figured it out, I added new 'account servers' ... ex: AccountServer klskl = new AccountServer, then set name with 'Naming'.

    But feel free to come with help anyway, on other things you see (this version is not updates doh, so don't worry about users)

    If u saw this before... It's all new now, anyhow.

    What I have here is a beginning on a banksystem, using RMI in eclipse, what I would like help with is how to add existing accounts, so that when you 'login' if you enter a 'id' number and it exists as an account number, you get that information (name, balance etc..). The program have a server, a client, an Interface, take a look

    Java Code:
    package bankrmi2;
    import java.rmi.Naming;
    import java.rmi.Remote;
    import java.rmi.RemoteException;
    import java.rmi.registry.LocateRegistry;
    import java.rmi.server.UnicastRemoteObject;
    import java.util.ArrayList;
    import java.util.List;
    interface Account extends Remote {
        public void deposit(int amount) throws RemoteException;
        public void withdraw(int amount) throws RemoteException;
        public int getBalance() throws RemoteException;
    public class AccountServer extends UnicastRemoteObject implements Account {
        private static final long serialVersionUID = 446895079020690009L;
        private int balance;
        public AccountServer() throws RemoteException {
        public void deposit(int amount) {
            balance += amount;
        public void withdraw(int amount) {
            balance -= amount;
        public int getBalance() {
            return balance;
        public static void main(String[] args) throws Exception {
            AccountServer server = new AccountServer();
            Naming.rebind("Bank", server);
            System.out.println("Account RMI server running");
    Java Code:
    package bankrmi2;
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.rmi.Naming;
    import java.rmi.RemoteException;
    import javax.swing.BorderFactory;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    import javax.swing.SwingUtilities;
    public class AccountClient extends JPanel { 
        private static final long serialVersionUID = 3255779371281665000L;
        private Account account;
        private JTextField amountField = new JTextField(30);
        private JTextArea balanceField = new JTextArea(4, 20);
        private JPanel buttonPanel = new JPanel();
        public AccountClient() {
            setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
            setLayout(new BorderLayout(10, 10));
            add(amountField, BorderLayout.NORTH);
            new Operation("Deposit") {
                protected void execute() throws RemoteException {
                    int amount = Integer.parseInt(amountField.getText());
            new Operation("Withdraw") {
                protected void execute() throws RemoteException {
                    int amount = Integer.parseInt(amountField.getText());
            add(new JScrollPane(balanceField), BorderLayout.CENTER);
            add(buttonPanel, BorderLayout.SOUTH);
        private void showBalance() {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    try {
                    	balanceField.setText("Balance: " + account.getBalance());
                    } catch (RemoteException e) {
        private abstract class Operation implements ActionListener {
            public Operation(String label) {
                JButton button = new JButton(label);
            public void actionPerformed(ActionEvent event) {
                try {
                } catch (Exception e) {
            protected abstract void execute() throws RemoteException;
        public static void main(String[] args) throws Exception {
            AccountClient client = new AccountClient();
            JFrame frame = new JFrame("ATM");
            String serverAddress = JOptionPane.showInputDialog(
                null, "Welcome to the Remote Account ATM\n" +
                "Enter IP Address of the Server:");
            client.account = (Account)Naming.lookup(
                "rmi://" + serverAddress + "/Bank");
            frame.getContentPane().add(client, BorderLayout.CENTER);
    Any thought on how to 'add' existing accounts?
    Last edited by schvuu; 11-26-2013 at 12:37 AM.

Similar Threads

  1. Replies: 2
    Last Post: 03-12-2012, 11:21 AM
  2. Help for write Bank application in Java
    By clapton in forum New To Java
    Replies: 4
    Last Post: 02-26-2012, 08:27 PM
  3. help java bank....
    By natsuki in forum Introductions
    Replies: 2
    Last Post: 07-25-2011, 03:36 AM
  4. java bank account problem
    By awil121 in forum New To Java
    Replies: 1
    Last Post: 10-13-2010, 10:47 PM
  5. Java Question Bank
    By mgm2010 in forum New To Java
    Replies: 2
    Last Post: 07-31-2009, 06:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts