
- •Агентная платформа jade
- •1. Описание агентной платформы jade
- •1.1. Архитектурная модель
- •1.2. Функциональная модель
- •2. Архитектура и реализация платформы jade
- •2.1. Структуры компонент-соединитель
- •2.1.1. Агент
- •2.1.2. Поведения
- •2.1.3. Платформа
- •2.1.4. Сервис обмена сообщениями
- •2.1.5. Анализ атрибутов качества
- •2.1.5.1. Производительность
- •2.1.5.2. Масштабируемость
- •2.1.5.3. Готовность
- •2.2.2. Сервис обмена сообщениями
- •2.2.2.1. Модифицируемость
- •2.3.1.1. Безопасность
- •3. Установка и настройка
- •3.1. Требования к окружению
- •3.2. Eclipse интегрированная среда разработки
- •3.2.1. Установка
- •3.2.2. Настройка приложения
- •3.2.3. Добавление кода
- •3.2.4. Запуск и отладка кода
- •3.3. Установка и настройка jade
- •1.1. Файл CalcModel.Java
- •1.1. Файл CalcPanel.Java
- •1.1. Файл Calculator.Java
- •2.1.Листинг: Файл PingAgent.Java
- •2.2. Листинг: Файл PongAgent.Java
1.1. Файл CalcModel.Java
package com.devious.calculator;
import java.util.Observable;
/**
* The CalcModel class serves as the "mechanics" behind our
* calculator. It handles "presses" of the calculators "buttons",
* performs calculators, and keeps the "display" up-to-date.
* The CalcModel extends Observable and will notify subscribers
* whenever the calculators display should change.
*
*/
public class CalcModel extends Observable
{
/**
* No operation in progress
*/
public static final int OP_NONE = 0;
/**
* Addition operation
*/
public static final int OP_ADD = 1;
/**
* Subtration operation
*/
public static final int OP_SUB = 2;
/**
* Multiplication operation
*/
public static final int OP_MUL = 3;
/**
* Dividion operation
*/
public static final int OP_DIV = 4;
//-------------------------------------------------------------
/**
* The pendingOp represents the operation that the user
* is currently entering. Should be one of the OP_* constants
*/
private int pendingOp = 0;
/**
* The value previously entered by the user. Effectively, this
* is the number the user entered before pressing one of the
* operation (+,-,*,/) keys
*/
private int previousValue = 0;
/**
* The number the user is currently in the process of entering
*/
private int currentValue = 0;
//-------------------------------------------------------------
/**
* Returns a string representing the number the calculator
* should currently display.
*
* @return the String the calculator should display
*/
public String getValue()
{
return Integer.toString(currentValue);
}
/**
* Use this method to indicate when one of the calculator's numeric
* "keys" has been pressed.
*
* @param s a String representing the key wich was
* pressed (e.g. "0");
*/
public void addDigit(String s)
{
char c = s.charAt(0);
String val = getValue() + c;
setDisplay(Integer.parseInt(val));
}
/**
* Use this method to indicate when one of the calculator's numeric
* "keys" has been pressed.
*
* @param c a char representing the key wich was
* pressed (e.g. '0');
*/
public void addDigit(char c)
{
String val = getValue() + c;
setDisplay(Integer.parseInt(val));
}
/**
* Use this method to indicate when one of the calculator's
* operational keys have been pressed. If there is a pending
* operation, the calculation will be performed and the
* calculator's display will be updated.
*
* @param op one of the OP_* constants indicating which
* operation key was pressed
*/
public void setOperation(int op)
{
// handle case where user enters multiple operations
// without intervening '=' (e.g 1 + 1 + 1)
if (pendingOp != OP_NONE)
calculate();
previousValue = currentValue;
this.pendingOp = op;
currentValue = 0;
}
/**
* Changes the calculator's display and notifies any observers
* of the change.
*
* @param value the new value to be displayed by the calculator
*/
public void setDisplay(int value)
{
currentValue = value;
setChanged();
notifyObservers();
}
/**
* This method can be used to "clear" the calculator. Any pending
* operations and numeric entries are discarded. The calculator's
* display is updated appropriately.
*/
public void clear()
{
this.pendingOp = OP_NONE;
previousValue = 0;
setDisplay(0);
}
/**
* This method is used to process a pending calculation (e.g.
* because the equals key was pressed.
*/
public void calculate()
{
switch (pendingOp)
{
case OP_ADD:
setDisplay(previousValue + currentValue);
break;
case OP_SUB:
setDisplay(previousValue - currentValue);
break;
case OP_MUL:
setDisplay(previousValue * currentValue);
break;
case OP_DIV:
setDisplay(previousValue / currentValue);
break;
}
pendingOp = OP_NONE;
previousValue = 0;
}
}