//////////////////////////////////////////////////////////////////////////////////////////// //PIMS: Personal Invstment Management System //Class : Delete alerts. //This class provides the GUI to assist the user to delete the alerts //////////////////////////////////////////////////////////////////////////////////////////// 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 DeleteAlert extends JFrame implements ActionListener{ private Alerts AL; private JTable table; private String alertlist[][]; private String fieldHeads[]; private JScrollPane jsp3; private Container contentPane; private int numAlerts=0; public DeleteAlert(Alerts AL)throws Exception{ this.AL = AL; contentPane=getContentPane(); contentPane.setLayout(new BorderLayout()); Panel p=new Panel(); Button b1=new Button("Close"); Button b3=new Button("Delete"); b1.addActionListener(this); b3.addActionListener(this); p.add(b1); p.add(b3); alertlist = AL.readAlerts(); while(alertlist[numAlerts][0]!=null) numAlerts++; fieldHeads=new String[2]; fieldHeads[0]="Date"; fieldHeads[1]="Alert"; 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 numAlerts;//length;//numOfFalse; } public Object getValueAt(int row, int col){ return alertlist[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("Delete Alert"); setVisible(true); } public void actionPerformed(ActionEvent ae){ String str=ae.getActionCommand(); if(str.equals("Close")){ this.setVisible(false); return; } if(str.equals("Delete")){ int selectedRow = table.getSelectedRow(); if(selectedRow==-1){ new Error("Select some alert"); return; } try{ AL.deleteAlert(selectedRow); setVisible(false); new DeleteAlert(AL); } catch(Exception e){ new Error("Problem in deleting alert"); return; } } } }