Java Reference
In-Depth Information
script-driven visual development environments. Listing 3.1 is an attempt at a
bank account program.
Listing 3.1
A bank account without Model-View-Controller
import java.util.*;
import java.text.*;
public class BitterAccount {
public String balance;
public String fieldValue;
public int radioButtons;
public float balanceNumber; o Model logic
public BitterAccount() {
balance="0";
}
o View logic
public String buttonPressed() {
radioButtons = userInterface.getRadioState();
if (radioButtons == 1) {
fieldValue = userInterface.getEntryField();
balanceNumber = balanceNumber + o Model logic
Float.valueOf(fieldValue.trim()).floatValue();
o View logic
o View and
model logic
balance = Float.toString(balanceNumber);
return balance;
} else if (radioButtons == 2) {
fieldValue = userInterface.getEntryField();
balanceNumber = balanceNumber - o Model logic
Float.valueOf(fieldValue.trim()).floatValue();
o Model logic
o View logic
o View and
model logic
balance = Float.toString(balanceNumber);
return balance;
} else if (radioButtons == 3) { o View logic
o Model logic
return balance; o Model logic
}
}
}
This application is the logic for a simple ATM program. It takes the amount in
an entry field and debits or credits the account appropriately, based on the
state of a radio button. Notice that no attempt has been made to break out the
business logic (the account) and the user interface. In fact, the model and view
are so tightly intertwined that, in many places, both the model and view are
Search WWH ::




Custom Search