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)

//{

//

//}

}

}

}

[24598 byte] By [j123456789a] at [2007-11-26 18:04:41]
# 1

and the other code required for the programme to work is :

//StoringData class

class StoringData{

private String name;

private String password;

private String phone;

private int currentsalary;

private int desiredsalary;

public StoringData()

{

name = null;

password = null;

phone = null;

currentsalary = 0;

desiredsalary = 0;

}

public StoringData(String n,String pw, String p, int c, int d)

{

name = n;

password = pw;

phone = p;

currentsalary = c;

desiredsalary = d;

}

public String getName1()

{

return name;

}

public String getPassword1()

{

return password;

}

public String getPhone1()

{

return phone;

}

public int getCurrentSalary1()

{

return currentsalary;

}

public int getdesiredsalary1()

{

return desiredsalary;

}

}

j123456789a at 2007-7-9 5:35:08 > top of Java-index,Desktop,Core GUI APIs...
# 2

vector is a pretty simple class, look at the API.

create a vector with:

Vector myVector = new Vector();

add something like a String with

myVector.add(stringName);

get with:

(String)myVector.get(elementIndex);

note the cast on the get, you will need to keep track of what types you are storing, best to keep all same type in a Vector so you can get them back ok. There are loads of other Vector methods for finding elements in the Vector just look up the API.

--

http://www.magiksafe.com

grilleda at 2007-7-9 5:35:08 > top of Java-index,Desktop,Core GUI APIs...
# 3

Quit posting 300 line programs to ask a question. We don't care about your entire application. We only care about code that demonstrates your current problem. We don't want to read through 300 lines to try and find the line of code that is causing the problem.

If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program[/url] (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.

And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url] so the code retains its original formatting.

Here is a simple SSCCE. Now make your changes and if you still have problems you have something simple to post. If it works then you add it to your real application.

Learn to simplify your problem by simplifying the code.

import java.awt.*;

import javax.swing.*;

public class ListTest2 extends JFrame

{

JList list;

public ListTest2()

{

String[] numbers = { "one", "two", "three", "four", "five", "six", "seven" };

list = new JList( numbers );

JScrollPane scrollPane = new JScrollPane( list );

getContentPane().add( scrollPane );

}

public static void main(String[] args)

{

ListTest2 frame = new ListTest2();

frame.setDefaultCloseOperation( EXIT_ON_CLOSE );

frame.setSize(200, 200);

frame.setLocationRelativeTo( null );

frame.setVisible( true );

}

}

camickra at 2007-7-9 5:35:08 > top of Java-index,Desktop,Core GUI APIs...