| package cloudTrading.buyer; |
| import jade.gui.TimeChooser; |
| import java.awt.; |
| import java.awt.event.; |
| import javax.swing.; |
| import javax.swing.border.; |
| import java.util.Date; |
| public class CloudBuyerGuiImpl extends JFrame implements CloudBuyerGui |
|
| public CloudBuyerGuiImpl() |
|
| super(); |
| addWindowListener(new WindowAdapter() |
| public void windowClosing(WindowEvent e) |
| myAgent.doDelete(); |
| ); |
| setDeadlineB.addActionListener(new ActionListener() |
| public void actionPerformed(ActionEvent e) |
| Date d = deadline; |
| if (d == null) |
| d = new Date(); |
|
| TimeChooser tc = new TimeChooser(d); |
| if (tc.showEditTimeDlg(CloudBuyerGuiImpl.this) == TimeChooser.OK) |
| deadline = tc.getDate(); |
| deadlineTF.setText(deadline.toString()); |
| ); |
| rootPanel.add(setCCB, gridBagConstraints); |
| buyB.addActionListener(new ActionListener() |
| public void actionPerformed(ActionEvent e) |
| String title = titleTF.getText(); |
| if (title != null && title.length() > 0) |
| if (deadline != null && deadline.getTime() > System.currentTimeMillis()) |
| maxCost = Float.valueOf(maxCostTF.getText()); |
| myAgent.purchase(title, maxCost, deadline); |
| notifyUser("PUT FOR BUY: "+title+" at max "+maxCost+" by "+deadline); |
| catch (Exception ex1) |
| JOptionPane.showMessageDialog(CloudBuyerGuiImpl.this, "Invalid max cost", "WARNING", |
| JOptionPane.WARNING_MESSAGE); |
| else |
| JOptionPane.showMessageDialog(CloudBuyerGuiImpl.this, "Invalid deadline", "WARNING", |
| JOptionPane.WARNING_MESSAGE); |
| else |
| JOptionPane.showMessageDialog(CloudBuyerGuiImpl.this, "No cloud title specified", "WARNING", |
| JOptionPane.WARNING_MESSAGE); |
| ); |
| resetB.addActionListener(new ActionListener() |
| public void actionPerformed(ActionEvent e) |
| titleTF.setText(""); |
| desiredCostTF.setText(""); |
| maxCostTF.setText(""); |
| deadlineTF.setText(""); |
| deadline = null; ); |
| exitB.addActionListener(new ActionListener() |
| public void actionPerformed(ActionEvent e) |
| myAgent.doDelete(); ); |
| public void setAgent(CloudBuyerAgent a) |
|
| myAgent = a; |
| setTitle(myAgent.getName()); |
|
| public void notifyUser(String message) |
| logTA.append(message+"∖n"); |
|