Title: ??????
1?????????????
2?????
- ??????????????????????????
- ????????????????????????
- ?????(UML)??????????
- ?????????Java????????????????
- ?????????????????????????????
- ??????????????????????????
- ????????(??????)?????????
- ?????????Java????????????????
3????????????
- ??????????????????
- ?????????????????(VMButton)?
- ?????????????
- ??100???????????
- ??????????(CoinDeposit)?100????????
- ????????????????????
- ??????????????
- ???????(ProductOutlet)???????
- ???????????0????????
- ?????????????????????
4??????????
- ???????????????????????????????????
- ???????2??????
On?? Off??
5?????
- ?????????????????????????????????????????????????
???????????? - ?????????UML?????????
- ??????????????????????????????????????????????????
??
6????????
?????????
????
??A
??B
????
???????????????????
7????????????
8?????1(????)
9?????2(????)
10?????3(??)
- ??
- ????????
- ???????????????
Off??
On??
11?????4(??)
- ????
- ???????????????(????)?????
- ?????
Off??
On??
12?????5(????)
?????? ?????????lt????
Off??
On??
?????????????????? Off???On?????????????
13?????6(?????)
- ?????????????????????????????
- ????
?????? ?????????lt????
Off??
On??
????????????????? ????????????????? Off???On??????
???????
14?????7(?????)
- ????????????????????????????????
- ???????/???????
??????????? ???????? ??????????? ??????????
15?????8(??????)
- ???????????????????????????????????????????
- ??????????????????
??????????? ???????? ???????? ??????????? ????????
? ??????????
16????????????
17????????????
- ????????????????????????
- ?????UML??????????????
- ???????????????????????????????????
18??????????????
????????????????????
???????????????
19?????????????????
- ??????
- ??????????????????????????????????????????
- ????????????????????
- ????????????
20(No Transcript)
21?????????
- ????????????????????????????
- ????????????????????
- ?????????100???????????????????
22?????1(????????)
- ???????????????????????????
- ???????????????
???????????????
23?????2(????)
??????????? ???????????? ?????????????
24?????3(???)
?????? ????????? ?????? 100???????? ??????????? ?
?????? 100???????? ??????
25?????4(???)
?????? ?????????? ????? ???????????
???????
????????
26??????????????CoinDeposit?????? ???????????????
27???????????
- ?????????????????????????????????????????
- ????????????
- ???????????????????????????????????????????(??????
??????????????????????)
28?????????????????
29?????
- ???????????????????????
- ??????????????????
????????????? ?????????
30?????????(1)
- ???????????VendingMachineFrame???????
//VendingMachineFrame???? void
vMButton1_mousePressed(MouseEvent e)
productOutlet1.getModel().addItem(new
Item(itemInfo1)) void vMButton2_mousePress
ed(MouseEvent e) productOutlet1.getModel().a
ddItem(new Item(itemInfo2))
??????????????????????? VendingMachineFrame???????
?????
31VMButton???????????????!
- ???Button??????Button?????????????????????????????
??
32VMButton??????????
- ???Frame????????????????????
- ????VMButton.java???
- ?????????????
- ???????????????
- ?MouseClicked???????????
33VMButton???????(2)
- ???VMButton??????ItemInfo???????????
ItemInfo?VMButton?????? ????????????
34?????VMButton???
//????????? public class VMButton extends
JComponent private VMButtonModel
model//????Model???????
//?????? //???????
public VMButton() model new
VMButtonModel(this)//???Model?
//??????????? setUI(new VMButtonUI())//???Vie
w?????????
35ItemInfo????????????????????????
//??????VMButton??? public class VMButton extends
JComponent private VMButtonModel
model//????Model??????? private ItemInfo
itemInfo//?????iteminfo??????? //???????
public VMButton() //??
//?????iteminfo????????? public void
setItemInfo(ItemInfo newItemInfo) itemInfo
newItemInfo
36Frame???????????????????????
//Jbuilder??????????? //VendingMachineFrame???
private void jbInit() throws Exception
itemInfo1.setBounds(new Rectangle(48, 61, 60,
90)) itemInfo2.setItemName("calpis")
itemInfo2.setItemPrice(200)
itemInfo2.setBounds(new Rectangle(115, 62, 60,
90)) vMButton1.setBounds(new Rectangle(56,
181, 43, 20)) vMButton2.setBounds(new
Rectangle(123, 181, 43, 20))
vMButton1.setItemInfo(itemInfo1)//??????????????
vMButton2.setItemInfo(itemInfo2)//???????????
???
37???????????????
???????????
38???????????????????
?????????????? ????????? ?????????? ????????????
39???????????????????
???? CoinDeposit???? ?????
//????????????????????????? //VMButton???
public void amountChange(CoinDepositModel
cdModel) //??? off ???????
if(!model.isOn()) //??????????????????? on
?????? if(itemInfo.getModel().getPrice() lt
cdModel.getAmount()) model.setOn(true)
//??? on ??????? else
//????????????????????? off ??????
if(itemInfo.getModel().getPrice() gt
cdModel.getAmount()) model.setOn(false)
40??????????????????
- ???????????????????????????
- ????????CoinDepositModel????addMoney()????????
- ??????????????VMButton????????????????????
41?????????
public class CoinDepositModel private int
amount private CoinDeposit controller
public CoinDepositModel(CoinDeposit
initController) controller
initController public void addMoney(Money
money) amount amount money.getValue()
controller.repaint() //????????????????????
public int getAmount() return
amount public Money undo()
//???????????????!
????????
????? ??????????? ??????! ?????VMButton? ????????
42???????VMButton?????
- Frame????VMButton?static?????
public class VendingMachineFrame extends JFrame
BackgroundPanel backgroundPanel1 new
BackgroundPanel() ItemInfo itemInfo1 new
ItemInfo() ItemInfo itemInfo2 new
ItemInfo() static VMButton vMButton1 new
VMButton() static VMButton vMButton2 new
VMButton() CoinDeposit coinDeposit1 new
CoinDeposit() ProductOutlet productOutlet1
new ProductOutlet()
????????????????????????????? ??????????????
43????????????????????
???? ????? ?????
//CoinDepositModel??????? public void
addMoney(Money money) amount amount
money.getValue() controller.repaint()
//???????????????????? VendingMachineFrame.vMBu
tton1.amountChange(this) VendingMachineFrame.v
MButton2.amountChange(this)
?????????????? ??????.????????????????????????
44static??????????????
- ????????????????static?????????????????????????(gl
obal????????) - ??????????????????????????????10??????????????????
???????? - ????????????????????????????????????????
45????????on,off??
- ????????????????????????????on???????????off??????
?? - ??????????
- ????????100?????????????100?????????????????????
46?????1
- CoinDeposit????????????????
- VMButton?On?????????????????????????????????
- ??????????????????????????
47?????2
- ????????????????????????????????????
- ???????????????????????
- ??????????????????
- ??1???????????????
- ????????????????????????????????????
48????
- objprog-12_at_crew.sfc.keio.ac.jp???
- ??????(2)??????VendingMachineFrame,VMButton,Coin
DepositModel,CoinDeposit?????? - (?????????????)
- Subject?????????????????
- ex) t96844ym
- ????????????????
- ?????(2400)???
- ?????????????????????????!