//////////////////////////////////////////////////////////////////////////////////////////// //PIMS: Personal Invstment Management System //Class : Delete alerts. //This class provides the GUI to assist the user to edit the prices of shares //////////////////////////////////////////////////////////////////////////////////////////// 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 EditPrices extends JFrame implements ActionListener{ private JTable table; private String pricelist[][]; private String fieldHeads[]; private JScrollPane jsp3; private Container contentPane; private int numShares=0; private CurrentValueSystem CVS; public EditPrices(CurrentValueSystem CVS)throws Exception{ this.CVS = CVS; contentPane=getContentPane(); contentPane.setLayout(new BorderLayout()); Panel p=new Panel(); Button b1=new Button("Close"); Button b2=new Button("Edit"); b1.addActionListener(this); b2.addActionListener(this); p.add(b1); p.add(b2); pricelist = CVS.readSharePrices(); while(pricelist[numShares][0]!=null) numShares++; fieldHeads=new String[2]; fieldHeads[0]="Company"; fieldHeads[1]="Price"; TableModel dataModel = new AbstractTableModel() { public String getColumnName(int col){ return fieldHeads[col];//fieldHeads[col];//actualFieldHeads[col]; } public int getColumnCount(){ return fieldHeads.length;//fieldHeads.length;//actualFieldHeads.length; } public int getRowCount(){ return numShares;//length;//numOfFalse; } public Object getValueAt(int row, int col){ return pricelist[row][col];//trans[row][col];//actualTrans[row][col]; } public boolean isCellEditable(int row,int col){ return false; } }; //dataModel.setBackground(Color.white); table = new JTable(dataModel); table.setBackground(Color.white); int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED; int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED; jsp3=new JScrollPane(table,v,h); jsp3.setBackground(Color.white); //panel.add(jsp2,BorderLayout.NORTH); contentPane.add(jsp3,BorderLayout.CENTER); contentPane.add(p,BorderLayout.SOUTH); contentPane.setVisible(true); setSize(250,400); setLocation(200,200); setTitle("Edit Prices of Shares"); setVisible(true); } public void actionPerformed(ActionEvent ae){ String str=ae.getActionCommand(); if(str.equals("Close")){ this.setVisible(false); return; } try{ if(str.equals("Edit")){ AskNewPrice ask=new AskNewPrice(table, this, numShares, CVS); return; } }catch(Exception e){ new Error("Problem in editing price"); return; } } }