欢迎来到天天文库
浏览记录
ID:37921478
大小:60.00 KB
页数:7页
时间:2019-06-02
《JADE的booktrading中GUI套用解析》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、内容摘要:... &......那末某个例子看不懂,便览java的读书还要加强一点...... &... jade的bookTrading中关于于Agent与gui应用界面结合的例子,实则gui在jade中的套用多么简约,主要是要把jade的Agent类当成一个平常类来应用就足以了。那末某个例子看不懂,便览java的读书还要加强一点。现在我来解析一下,主要是对准BoolSellerAgent类材料和BookSellerGui类文书。大家看BookSellerGui.java的主要框架:impo
2、rtjava.awt.*;//表明要用哪些类来兑现gui界面,importjava.awt.event.*;importjavax.swing.*;/** @authorGiovanniCaire-TILAB*/classBookSellerGuiextendsJFrame{ privateBookSellerAgentmyAgent;//该Agent作为一个分子,所以在添加图书的时机要调用该事物成员的诀要 privateJTextFieldtitleField,priceField; BookSellerGui(BookSellerAgenta){
3、 super(a.getLocalName()); myAgent=a;//Agent成员初始化 JPanelp=newJPanel(); p.setLayout(newGridLayout(2,2)); p.add(newJLabel("Booktitle:")); titleField=newJTextField(15); p.add(titleField); p.add(newJLabel("Price:")); priceField=newJTextFiel
4、d(15); p.add(priceField); getContentPane().add(p,BorderLayout.CENTER); JButtonaddButton=newJButton("Add"); addButton.addActionListener(newActionListener(){ publicvoidactionPerformed(ActionEventev){ try{ Stringtitle=titleField.getText()
5、.trim(); Stringprice=priceField.getText().trim(); myAgent.updateCatalogue(title,Integer.parseInt(price));//调用该成员的法子对图书数据进行更新 titleField.setText(""); priceField.setText(""); } catch(Exceptione){ JOptionPane.s
6、howMessageDialog(BookSellerGui.this,"Invalidvalues."+e.getMessage(),"Error",JOptionPane.ERROR_MESSAGE); } } }); p=newJPanel(); p.add(addButton); getContentPane().add(p,BorderLayout.SOUTH); //Maketheagentterminatewhentheusercloses //theGUI
7、usingthebuttonontheupperrightcorner addWindowListener(new WindowAdapter(){ publicvoidwindowClosing(WindowEvente){ myAgent.doDelete();//同样是调用某个方法,干什么的自己猜猜 } }); setResizable(false); } publicvoidshow(){ pac
此文档下载收益归作者所有