//////////////////////////////////////////////////////////////////////////////////////////// //PIMS: Personal Invstment Management System //Class : AskNewPrice //This class contains the GUI for asking share price from //the user. //////////////////////////////////////////////////////////////////////////////////////////// import java.awt.*; import java.applet.*; import java.awt.event.*; import javax.swing.*; import javax.swing.tree.*; import javax.swing.plaf.*; import java.lang.*; import java.io.*; import javax.swing.table.*; import java.util.*; public class AskNewPrice extends JFrame implements ActionListener{ private Label label; private TextField tf; private Button b; private Container contentPane; private JTable t; private EditPrices ep; private int ns; private CurrentValueSystem CVS; public AskNewPrice(JTable table,EditPrices editprices,int numShares, CurrentValueSystem CVS){ t=table; ep=editprices; ns=numShares; this.CVS = CVS; label=new Label("New Price"); tf=new TextField(10); b=new Button("Change"); contentPane=getContentPane(); contentPane.setLayout(new FlowLayout()); contentPane.add(label); contentPane.add(tf); contentPane.add(b); setLocation(350,200); setSize(300,80); setTitle("Changing Prices"); setVisible(true); b.addActionListener(this); } public void actionPerformed(ActionEvent ae){ String str=ae.getActionCommand(); if(str.equals("Change")){ String newprice=tf.getText(); try{ double test = Double.parseDouble(newprice); if(test < 0){ new Error("Negative value of a share price not allowed"); return; } } catch(Exception e){ new Error("Price not entered properly"); return; } try{ int selectedRow=t.getSelectedRow(); if(selectedRow==-1){ new Error("No row selected"); return; } else{ CVS.updateCVS(t.getSelectedRow(), newprice); ep.setVisible(false); new EditPrices(CVS); setVisible(false); return; } } catch(Exception e){ new Error("Problem in updating the prices"); return; } } } }