I am suppose to read a text file which contains info on cars and i have to display the filtered result on a defaultlistmodel....my code works fine when one combo box is chosen....but wen i give the condition if two combo boxes are chose it displays the || result on the list....how do i solve it....i need display only the && result on list(but the filter works just fine in the console)
Here is the code:-
Please Helppublic void actionPerformed(ActionEvent a) { // TODO Auto-generated method stub String result[]; String combobox[]={combo[0].getSelectedItem().toString(),combo[1].getSelectedItem().toString(), combo[2].getSelectedItem().toString(),combo[3].getSelectedItem().toString(), combo[4].getSelectedItem().toString(),combo[5].getSelectedItem().toString()}; // search is a JButton.. if(a.getSource()==search){ list.clear(); try{ FileInputStream fin=new FileInputStream ("carList.txt"); Scanner scanner = new Scanner(fin); scanner.useDelimiter(";"); scanner.skip("// List of cars to use:"); char d='"'; while (scanner.hasNext()){ String s1=scanner.next().replace(d, ' '); String s2=s1.replace("(", " "); String s3=s2.replace(")", " "); String s4=s3.replace("new",""); String s5=s4.replace(" ", ""); String s6=s5.replace("int", "*"); String s7=s6.replace("float", ""); result=scan.split(","); // When only one combobox option is chosen String scan=s7.replace("CarSpec", ""); if(scan.contains(combobox[0])||scan.contains(combobox[1])||scan.contains(combobox[2])||scan.contains(combobox[3]) ||scan.contains(combobox[4])||scan.contains(combobox[5])){ list.addElement(result[2]+" "+result[3]+","+result[0]); } // when all the option are any if(combobox[0]=="Any"&&combobox[1]=="Any"&&combobox[2]=="Any"&&combobox[3]=="Any"&& combobox[4]=="Any"&&combobox[5]=="Any"){ list.addElement(result[2]+" "+result[3]+","+result[0]); } //when options from combobox1 and combobox2 are chosen...combobox[0] =combo[1].getSelectedItem().toString if(scan.contains(combobox[0])&&scan.contains(combobox[1])){ list.addElement(result[2]+" "+result[3]+","+result[0]); System.out.println(result[2]+" "+result[3]+","+result[0]); } if(scan.contains(combobox[0])&&scan.contains(combobox[2])){ list.addElement(result[2]+" "+result[3]+","+result[0]); System.out.println(result[2]+" "+result[3]+","+result[0]); } }