//////////////////////////////////////////////////////////////////////////////////////////// //PIMS: Personal Invstment Management System //Class : AskSecurityName //This contains the GUI for asking the user the //name of the security while creating a new security. //////////////////////////////////////////////////////////////////////////////////////////// import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; public class AskSecurityName extends JFrame implements ActionListener,ItemListener{ private Investment INV; private CurrentValueSystem CVS; private TextField name; private Label namep; private TextField info; private Label infop; private TextField name1; private Label namep1; private Label companyp; private Choice Companies; private Checkbox bank; private Checkbox share; private CheckboxGroup cbg; private String secName=""; private String task=""; private String pfName=""; private GUI g; private int col=0; private Container contentPane; public AskSecurityName(Investment INV, CurrentValueSystem CVS, String str,GUI gui,String pf)throws Exception{ super("Security Details"); this.INV = INV; this.CVS = CVS; g=gui; task=str; pfName=pf; makeGUI(); } private void makeGUI()throws Exception{ setBackground(Color.white); contentPane=getContentPane(); if(task.equals("Add Security")) col=4; if(task.equals("Delete Security")) col=2; if(task.equals("Rename Security")) col=3; contentPane.setLayout(new GridLayout(col,2)); name=new TextField(15); //name.setBackground(Color.white); namep=new Label("Security: "); namep.setBackground(Color.white); name1=new TextField(15); //name1.setBackground(Color.white); namep1=new Label("New Security: "); namep1.setBackground(Color.white); //Adding the choice of companies. companyp = new Label("Company"); companyp.setBackground(Color.white); Companies = new Choice(); showCompanies(Companies); Companies.setSize(200,100); Companies.setVisible(true); //Companies.setBackground(Color.white); Button b1=new Button("Ok"); b1.setBackground(Color.white); Button b2=new Button("Cancel"); b2.setBackground(Color.white); cbg=new CheckboxGroup(); bank=new Checkbox("bank",cbg,true); bank.setBackground(Color.white); share=new Checkbox("share",cbg,false); share.setBackground(Color.white); info=new TextField(15); //info.setBackground(Color.white); infop=new Label("Enter rate of interest"); infop.setBackground(Color.white); if(task.equals("Add Security") || task.equals("Delete Security")){ contentPane.add(namep); contentPane.add(name); } else{ contentPane.add(namep); contentPane.add(name); contentPane.add(namep1); contentPane.add(name1); } if(task.equals("Add Security")){ contentPane.add(bank); contentPane.add(share); } if(task.equals("Add Security")){ contentPane.add(infop); contentPane.add(info); } if(task.equals("Rename Security")){ namep1.setVisible(true); name1.setVisible(true); } else{ namep1.setVisible(false); name1.setVisible(false); } contentPane.add(b1); contentPane.add(b2); name.addActionListener(this); b1.addActionListener(this); b2.addActionListener(this); bank.addItemListener(this); share.addItemListener(this); if(task.equals("Rename Security") || task.equals("Delete Security")){ setSize(300,150); setLocation(120,150); } else{ setSize(400,200); setLocation(120,150); } setVisible(true); } private void showCompanies(Choice Companies)throws Exception{ String Line; int count = 0; String companies[] = CVS.companies(); for(int i=0;i