Einführung in die objektorientierte Programmierung

Aufg1 mit rmi

Server

import java.rmi.*;
   import java.rmi.server.*;
   import java.io.*; 
   import java.net.*; 
 
public class ZaehlerServer{
   public static void main(String[] args) throws Exception{
   ZaehlerImpl count= new ZaehlerImpl();
   //    Naming.rebind("zaehlerstand", count);
   }
   }
 
class ZaehlerImpl extends UnicastRemoteObject
   implements Zaehler { 
   
   private int counter;
   
   public  ZaehlerImpl() throws RemoteException{
   counter=0;
   }
   
   public String incr(){
   counter++;
   return  ""+counter;
   }
   
   public String decr(){
   counter--;
   return  ""+counter;
   }
   
   public String get(){
   return  ""+counter;
   }
   
   } // Ende: public class MeinEchoServer 
 

Interface

   import java.rmi.*;
   import java.rmi.server.*;
   import java.io.*; 
   import java.net.*; 
public interface Zaehler extends Remote{
   public String incr() throws InterruptedException, RemoteException;
   
   public String decr() throws InterruptedException, RemoteException;
   
   public String get() throws InterruptedException, RemoteException;
   }

Client

import java.awt.*;
   import java.awt.event.*;
   import java.net.*;
   import java.io.*; 
   import java.rmi.*;
   import java.rmi.server.*;
/**
   *
   * Beschreibung
   *
   * @version 1.0 vom 01.07.2015
   * @author 
   */
public class ZaehlerClient extends Frame {
   // Anfang Attribute
   private Button button1 = new Button();
   private Button button2 = new Button();
   private Button button3 = new Button();
   private TextField textField1 = new TextField();
   // Ende Attribute
   
   public ZaehlerClient(String title) { 
   // Frame-Initialisierung
   super(title);
   addWindowListener(new WindowAdapter() {
   public void windowClosing(WindowEvent evt) { dispose(); }
   });
   int frameWidth = 390; 
   int frameHeight = 189;
   setSize(frameWidth, frameHeight);
   Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
   int x = (d.width - getSize().width) / 2;
   int y = (d.height - getSize().height) / 2;
   setLocation(x, y);
   setResizable(false);
   Panel cp = new Panel(null);
   add(cp);
   // Anfang Komponenten
   
   button1.setBounds(64, 32, 33, 33);
   button1.setLabel("<");
   button1.addActionListener(new ActionListener() { 
   public void actionPerformed(ActionEvent evt) { 
   button1_ActionPerformed(evt);
   }
   });
   cp.add(button1);
   button2.setBounds(232, 32, 41, 33);
   button2.setLabel(">");
   button2.addActionListener(new ActionListener() { 
   public void actionPerformed(ActionEvent evt) { 
   button2_ActionPerformed(evt);
   }
   });
   cp.add(button2);
   button3.setBounds(64, 80, 209, 41);
   button3.setLabel("quit");
   button3.addActionListener(new ActionListener() { 
   public void actionPerformed(ActionEvent evt) { 
   button3_ActionPerformed(evt);
   }
   });
   cp.add(button3);
   textField1.setBounds(120, 32, 81, 33);
   cp.add(textField1);
   // Ende Komponenten
   
   setVisible(true);
   
   kommando("GET");
   
   } // end of public ZaehlerClient
   
   // Anfang Methoden
   public void button1_ActionPerformed(ActionEvent evt) {
   kommando("<");
   } // end of button1_ActionPerformed
   
   public void button2_ActionPerformed(ActionEvent evt) {
   kommando(">");
   } // end of button2_ActionPerformed
   
   public void kommando(String befehl){
   
   }
   
   public void button3_ActionPerformed(ActionEvent evt) {
   System.exit(0);
   } // end of button3_ActionPerformed
   
   // Ende Methoden
   
   public static void main(String[] args) throws Exception{
   new ZaehlerClient("ZaehlerClient");
   String url= "rmi://localhost/zaehlerstand";
   Zaehler z= (Zaehler) Naming.lookup(url);
   } // end of main
   
   } // end of class Zaehler