mardi 30 décembre 2014

updating an array after boxes are checked in java

i am really stuck. I want to update the projects and researchers array so that next time they are added to each others list is checked. Here is what ive done so far for this class. Any help would be appreciated, Thank you


code:



package view;


//all the imports are here



public class selectTeamMembers extends JFrame implements ActionListener, ItemListener{
ArrayList<Researchers> all;
ArrayList<Researchers> local;

ArrayList<Researchers> localselected;
int UREPcheck_count=-1;
int NPRPcheck_count=-1;
int type=0;//type=1 is UREP,type=2 is NPRP
Project pro;


JButton b1=new JButton("Add");
JButton b2=new JButton("Clear");
JButton b3=new JButton("Exit");
JPanel p1=new JPanel();

public selectTeamMembers(Arrays arr,Project pro){

super("selecting team members");
all=arr.getAllResearchers();
this.pro=pro;
if(pro instanceof UREP){
type=1;
JLabel label1=new JLabel("select the researchers that are on the team of this UREP project:");
Box box=Box.createVerticalBox();
box.add(label1);
for(int i=0;i<all.size();i++){
if(all.get(i) instanceof Faculty ||all.get(i) instanceof UnderGraduate){
JCheckBox b1=new JCheckBox(all.get(i).getName());
//checkboxes.add(b1);
box.add(b1);
//local.add(all.get(i));

b1.addItemListener(this);

UREPcheck_count=UREPcheck_count+1;


}//end if

} //end for
add(box,BorderLayout.CENTER);

} //end if urep


else if (pro instanceof NPRP){
type=2;
JLabel label1=new JLabel("select the researchers that are on the team of this NPRP project:");
Box box=Box.createVerticalBox();
box.add(label1);
for(int i=0;i<all.size();i++){
if(all.get(i) instanceof Faculty ||all.get(i) instanceof PostDoc||all.get(i) instanceof RA){
JCheckBox b1=new JCheckBox(all.get(i).getName());
box.add(b1);
//b1.addItemListener(this);
local.add(all.get(i));
NPRPcheck_count=NPRPcheck_count+1;

}

}

add(box,BorderLayout.CENTER);



}

p1.add(b1);
p1.add(b2);
p1.add(b3);

b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);

add(p1,BorderLayout.SOUTH);
setSize(200,200);
setVisible(true);

}

@Override
public void actionPerformed(ActionEvent arg0) {

if(arg0.getSource()==b1){ //add



}


else if(arg0.getSource()==b2){ //clear



}

else if(arg0.getSource()==b3){ //exit
System.exit(0);

}


}

@Override
public void itemStateChanged(ItemEvent e) {
JOptionPane.showMessageDialog(null, "checked");

}


}




Aucun commentaire:

Enregistrer un commentaire