need help in storing data from JList into a vector
need help in doing the following.-
alright i click a skill on industryskills Jlist and press the add button and it'll be added to the applicantskills Jlist. how do i further store this data that i added onto the applicantskills JList into a vector.
here are the codes:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.text.*;
import java.util.*;
import java.util.Vector;
import javax.swing.JScrollPane.*;
//import javax.swing.event.ListSelectionListener;
publicclass Employmentextends JFrame
{
//declare class variables
private JPanel jpApplicant, jpEverything,jpWEST, jpCENTRE, jpEAST, jpAddEditDelete,
jpCentreTOP, jpCentreBOT, jpEastTOP, jpEastCENTRE, jpEastBOT,
jpBlank1, panel1, panel2, panel3, panel4,jpBottomArea,
jpEmptyPanelForDisplayPurposes;
private JLabel jlblApplicantForm, jlblAppList, jlblName, jlblPhone,
jlblCurrentSalary, jlblPassword, jlblDesiredSalary,
jlblNotes, jlblApplicantSkills, jlblIndustrySkills,
jlblBlank1, jlblBlank2, ApplicantListLabel,
NotesListLabel, ApplicantSkillsLabel,
IndustrySkillsLabel,jlblEmptyLabelForDisplayPurposes;
private JButton jbtnAdd1, jbtnEdit, jbtnDelete, jbtnSave, jbtnCancel,
jbtnAdd2, jbtnRemove;
private JTextField jtfName, jtfPhone, jtfCurrentSalary, jtfPassword,
jtfDesiredSalary;
private JTabbedPane tabbedPane;
private DefaultListModel/*listModel,*/listModel2;
String name,password,phone,currentsalary,desiredsalary,textareastuff,NotesText;
String selectedname;
final JTextArea Noteslist=new JTextArea();;
DefaultListModel listModel =new DefaultListModel();
JList ApplicantSkillsList =new JList(listModel);
private ListSelectionModel listSelectionModel;
JList ApplicantList,/*ApplicantSkillsList,*/ IndustrySkillsList;
//protected JTextArea NotesList;
//Vector details = new Vector();
Vector<StoringData> details =new Vector<StoringData>();
publicstaticvoid main(String []args)
{
Employment f =new Employment();
f.setVisible(true);
f.setDefaultCloseOperation(EXIT_ON_CLOSE);
f.setResizable(false);
}//end of main
public Employment()
{
setSize(800,470);
setTitle("E-commerce Placement Agency");
Font listfonts =new Font("TimesRoman", Font.BOLD, 12);
JPanel topPanel =new JPanel();
topPanel.setLayout(new BorderLayout() );
getContentPane().add( topPanel );
createPage1();
createPage2();
createPage3();
createPage4();
tabbedPane =new JTabbedPane();
tabbedPane.addTab("Applicant", panel1 );
tabbedPane.addTab("Job Order", panel2 );
tabbedPane.addTab("Skill", panel3 );
tabbedPane.addTab("Company", panel4 );
topPanel.add( tabbedPane, BorderLayout.CENTER );
}
publicvoid createPage1()//PAGE 1
{
/*******************TOP PART********************/
panel1 =new JPanel();
panel1.setLayout(new BorderLayout());
jpBottomArea =new JPanel();
jpBottomArea.setLayout(new BorderLayout());
jpApplicant=new JPanel();
jpApplicant.setLayout(new BorderLayout());
Font bigFont =new Font("TimesRoman", Font.BOLD,24);
jpApplicant.setBackground(Color.lightGray);
jlblApplicantForm =new JLabel("\t\t\t\tAPPLICANT FORM ");
jlblApplicantForm.setFont(bigFont);
jpApplicant.add(jlblApplicantForm,BorderLayout.EAST);
panel1.add(jpApplicant,BorderLayout.NORTH);
panel1.add(jpBottomArea,BorderLayout.CENTER);
/********************************EMPTY PANEL FOR DISPLAY PURPOSES*************************/
jpEmptyPanelForDisplayPurposes =new JPanel();
jlblEmptyLabelForDisplayPurposes =new JLabel(" ");
jpEmptyPanelForDisplayPurposes.add(jlblEmptyLabelForDisplayPurposes);
jpBottomArea.add(jpEmptyPanelForDisplayPurposes,BorderLayout.NORTH);
/*****************************************WEST*********************************/
jpWEST =new JPanel();
jpWEST.setLayout(new BorderLayout());
//Applicant List
listModel2=new DefaultListModel();
ApplicantList =new JList(listModel2);
listSelectionModel = ApplicantList.getSelectionModel();
listSelectionModel.addListSelectionListener(new SharedListSelectionHandler());
JScrollPane scrollPane3 =new JScrollPane(ApplicantList);
ApplicantList.setPreferredSize(new Dimension(20,40));
scrollPane3.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane3.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
ApplicantListLabel =new JLabel("Applicant List:");
jpWEST.add(ApplicantListLabel,"North");
jpWEST.add(scrollPane3,"Center");
jpBottomArea.add(jpWEST,BorderLayout.WEST);
/*****************************************************************/
/*********CENTRE*********/
jpCENTRE =new JPanel();
jpCENTRE.setLayout(new GridLayout(2,1));
jpCentreTOP =new JPanel();
jpBottomArea.add(jpCENTRE,BorderLayout.CENTER);
jpCENTRE.add(jpCentreTOP);
jpCentreTOP.setLayout(new GridLayout(6,2));
//Creating labels and textfields
jlblName =new JLabel("Name:");
jlblBlank1 =new JLabel ("");
jtfName =new JTextField(18);
jlblBlank2 =new JLabel("");
jlblPhone =new JLabel("Phone:");
jlblCurrentSalary =new JLabel("Current Salary:");
jtfPhone =new JTextField(13);
jtfCurrentSalary =new JTextField(7);
jlblPassword =new JLabel("Password:");
jlblDesiredSalary =new JLabel("Desired Salary:");
jtfPassword =new JTextField(13);
jtfDesiredSalary =new JTextField(6);
//Add labels and textfields to panel
jpCentreTOP.add(jlblName);
jpCentreTOP.add(jlblBlank1);
jpCentreTOP.add(jtfName);
jpCentreTOP.add(jlblBlank2);
jpCentreTOP.add(jlblPhone);
jpCentreTOP.add(jlblCurrentSalary);
jpCentreTOP.add(jtfPhone);
jpCentreTOP.add(jtfCurrentSalary);
jpCentreTOP.add(jlblPassword);
jpCentreTOP.add(jlblDesiredSalary);
jpCentreTOP.add(jtfPassword);
jpCentreTOP.add(jtfDesiredSalary);
//Noteslist
jpCentreBOT =new JPanel();
jpCentreBOT.setLayout(new BorderLayout());
jpCENTRE.add(jpCentreBOT);
jpBlank1 =new JPanel();
//Noteslist = new JTextArea(/*Document doc*/);
JScrollPane scroll3=new JScrollPane(Noteslist);
scroll3.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scroll3.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
NotesListLabel =new JLabel("Notes:");
jpCentreBOT.add(NotesListLabel,"North");
jpCentreBOT.add(scroll3,"Center");
jpCentreBOT.add(jpBlank1,"South");
jpBottomArea.add(jpCENTRE,BorderLayout.CENTER);
/******************************************************************/
/**********EAST**********/
//Applicant Skills Panel
//EAST ==> TOP
jpEAST =new JPanel();
jpEAST.setLayout(new BorderLayout());
jpEastTOP =new JPanel();
jpEastTOP.setLayout(new BorderLayout());
ApplicantSkillsLabel =new JLabel("Applicant Skills");
JScrollPane scrollPane1 =new JScrollPane(ApplicantSkillsList);
scrollPane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
ApplicantSkillsList.setVisibleRowCount(6);
jpEastTOP.add(ApplicantSkillsLabel,"North");
jpEastTOP.add(scrollPane1,"Center");
jpEAST.add(jpEastTOP,BorderLayout.NORTH);
jpBottomArea.add(jpEAST,BorderLayout.EAST);
//Add & Remove Buttons
//EAST ==> CENTRE
jpEastCENTRE =new JPanel();
jpEAST.add(jpEastCENTRE,BorderLayout.CENTER);
jbtnAdd2 =new JButton("Add");
jbtnRemove =new JButton("Remove");
//add buttons to panel
jpEastCENTRE.add(jbtnAdd2);
jpEastCENTRE.add(jbtnRemove);
//add listener to button
jbtnAdd2.addActionListener(new Add2Listener());
jbtnRemove.addActionListener(new RemoveListener());
//Industry Skills Panel
//EAST ==> BOTTOM
jpEastBOT =new JPanel();
jpEastBOT.setLayout(new BorderLayout());
String[] data ={"Access97","Basic Programming",
"C++ Programming","COBOL Programming",
"DB Design","Fortran programming"};
IndustrySkillsList =new JList(data);
JScrollPane scrollPane =new JScrollPane(IndustrySkillsList);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
IndustrySkillsLabel =new JLabel("Industry Skills:");
jpEastBOT.add(IndustrySkillsLabel,"North");
jpEastBOT.add(scrollPane,"Center");
jpEAST.add(jpEastBOT,BorderLayout.SOUTH);
/***********************************************************/
//BOTTOM
jpAddEditDelete=new JPanel();
jbtnAdd1=new JButton("Add");
jbtnEdit=new JButton("Edit");
jbtnDelete=new JButton("Delete");
jbtnSave=new JButton("Save");
jbtnCancel=new JButton("Cancel");
jpAddEditDelete.add(jbtnAdd1);
jpAddEditDelete.add(jbtnEdit);
jpAddEditDelete.add(jbtnDelete);
jpAddEditDelete.add(jbtnSave);
jpAddEditDelete.add(jbtnCancel);
jbtnEdit.addActionListener(new EditListener());
jbtnDelete.addActionListener(new DeleteListener());
jbtnEdit.addActionListener(new EditListener());
jbtnAdd1.addActionListener(new Add1Listener());
jbtnCancel.addActionListener(new CancelListener());
jpBottomArea.add(jpAddEditDelete,BorderLayout.SOUTH);
}
publicvoid createPage2()//PAGE 2
{
panel2 =new JPanel();
panel2.setLayout(new GridLayout(1,1) );
panel2.add(new JLabel("Sorry,under construction" ) );
}
publicvoid createPage3()//PAGE 3
{
panel3 =new JPanel();
panel3.setLayout(new GridLayout( 1, 1 ) );
panel3.add(new JLabel("Sorry,under construction" ) );
}
publicvoid createPage4()//PAGE 4
{
panel4 =new JPanel();
panel4.setLayout(new GridLayout( 1, 1 ) );
panel4.add(new JLabel("Sorry,under construction" ) );
}
publicclass Add1Listenerimplements ActionListener
{
publicvoid actionPerformed(ActionEvent e)
{
name = jtfName.getText();
password = jtfPassword.getText();
phone = jtfPhone.getText();
currentsalary = jtfCurrentSalary.getText();
int i= Integer.parseInt(currentsalary);
desiredsalary = jtfDesiredSalary.getText();
int j= Integer.parseInt(desiredsalary);
StoringData person =new StoringData(name,password,phone,i,j);
//StoringData AppSkillsList = new StoringData(listModel);
details.add(person);
//details.add(AppSkillsList);
listModel2.addElement(name);
jtfName.setText("");
jtfPassword.setText("");
jtfPhone.setText("");
jtfCurrentSalary.setText("");
jtfDesiredSalary.setText("");
//NotesList.setText("");
}
}
publicclass Add2Listenerimplements ActionListener
{
publicvoid actionPerformed(ActionEvent e)
{
String temp1;
temp1 = (String)IndustrySkillsList.getSelectedValue();
listModel.addElement(temp1);
}
}
publicclass RemoveListenerimplements ActionListener
{
publicvoid actionPerformed(ActionEvent e)
{
int index = ApplicantSkillsList.getSelectedIndex();
listModel.remove(index);
}
}
publicclass EditListenerimplements ActionListener
{
publicvoid actionPerformed(ActionEvent e)
{
jtfName.setEditable(true);
jtfPassword.setEditable(true);
jtfPhone.setEditable(true);
jtfCurrentSalary.setEditable(true);
jtfDesiredSalary.setEditable(true);
Noteslist.setEditable(true);
jbtnAdd2.setEnabled(true);
jbtnRemove.setEnabled(true);
jbtnSave.setEnabled(true);
jbtnCancel.setEnabled(true);
}
}
publicclass DeleteListenerimplements ActionListener
{
publicvoid actionPerformed(ActionEvent e)
{
int index1 = ApplicantList.getSelectedIndex();
listModel2.remove(index1);
}
}
publicclass SaveListenerimplements ActionListener
{
publicvoid actionPerformed(ActionEvent e)
{
}
}
publicclass CancelListenerimplements ActionListener
{
publicvoid actionPerformed(ActionEvent e)
{
jtfName.setText("");
jtfPassword.setText("");
jtfPhone.setText("");
jtfCurrentSalary.setText("");
jtfDesiredSalary.setText("");
}
}
publicclass SharedListSelectionHandlerimplements ListSelectionListener
{
publicvoid valueChanged(ListSelectionEvent e)
{
selectedname =ApplicantList.getSelectedValue().toString();
StoringData selectedPerson =null;
jtfName.setEditable(false);
jtfPassword.setEditable(false);
jtfPhone.setEditable(false);
jtfCurrentSalary.setEditable(false);
jtfDesiredSalary.setEditable(false);
Noteslist.setEditable(false);
jbtnAdd2.setEnabled(false);
jbtnRemove.setEnabled(false);
jbtnSave.setEnabled(false);
jbtnCancel.setEnabled(false);
for (StoringData person : details)
{
if (person.getName1().equals(selectedname))
{
selectedPerson = person;
jtfName.setText(person.getName1());
jtfPassword.setText(person.getPassword1());
jtfPhone.setText(person.getPhone1());
//String sal1 = Integer.parseString(currentsalary);
// String sal2 = Integer.parseString(desiredsalary);
// jtfCurrentSalary.setText(sal1);
// jtfDesiredSalary.setText(sal2);
break;
}
}
//if (selectedPerson != null)
//{
//
//}
}
}
}

