I'm trying to add jbuttons via some if statements. For some reason , the last ifs are not working . For all 3 of the last ifs ( RJ1214 , PS1212 and MP1213 ) they don't even enter the if statement . If i try moving RJ1214 up on the list it does show up but the last IF still does not work . Any help please?
if(numePiesa=="MP")
{
if((scanFile("S:\\Files\\MP1009.txt"))>0)
{
this.setVisible(true);
JButton MP1009=new JButton("10.02 ora 09:00");
this.add(MP1009);
}
if((scanFile("S:\\Files\\MP1013.txt"))>0)
{
this.setVisible(true);
JButton MP1013=new JButton("10.02 ora 13:00");
this.add(MP1013);
}
if((scanFile("S:\\Files\\MP1109.txt"))>0)
{
this.setVisible(true);
JButton MP1109=new JButton("11.02 ora 09:00");
this.add(MP1109);
}
if((scanFile("S:\\Files\\MP1113.txt"))>0)
{
this.setVisible(true);
JButton MP1113=new JButton("11.02 ora 13:00");
this.add(MP1113);
}
if((scanFile("S:\\Files\\MP1209.txt"))>0)
{
this.setVisible(true);
JButton MP1209=new JButton("12.02 ora 09:00");
this.add(MP1209);
}
if((scanFile("S:\\Files\\MP1213.txt"))>0)
{
this.setVisible(true);
JButton MP1213=new JButton("12.02 ora 13:00");
this.add(MP1213);
}
}
else if(numePiesa=="PS")
{
if((scanFile("S:\\Files\\PS1010.txt"))>0)
{
this.setVisible(true);
JButton PS1010=new JButton("10.02 ora 10:00");
this.add(PS1010);
}
if((scanFile("S:\\Files\\PS1012.txt"))>0)
{
this.setVisible(true);
JButton PS1012=new JButton("10.02 ora 12:00");
this.add(PS1012);
}
if((scanFile("S:\\Files\\PS1110.txt"))>0)
{
this.setVisible(true);
JButton PS1110=new JButton("11.02 ora 10:00");
this.add(PS1110);
}
if((scanFile("S:\\Files\\PS1112.txt"))>0)
{
this.setVisible(true);
JButton PS1112=new JButton("11.02 ora 12:00");
this.add(PS1112);
}
if((scanFile("S:\\Files\\PS1210.txt"))>0)
{
this.setVisible(true);
JButton PS1210=new JButton("12.02 ora 10:00");
this.add(PS1210);
}
if((scanFile("S:\\Files\\PS1212.txt"))>0)
{
this.setVisible(true);
JButton PS1212=new JButton("12.02 ora 12:00");
this.add(PS1212);
}
}
else if(numePiesa=="RJ")
{
if((scanFile("S:\\Files\\RJ1008.txt"))>0)
{
this.setVisible(true);
JButton RJ1008=new JButton("10.02 ora 08:00");
this.add(RJ1008);
}
if((scanFile("S:\\Files\\RJ1014.txt"))>0)
{
this.setVisible(true);
JButton RJ1014=new JButton("10.02 ora 14:00");
this.add(RJ1014);
}
if((scanFile("S:\\Files\\RJ1108.txt"))>0)
{
this.setVisible(true);
JButton RJ1108=new JButton("11.02 ora 08:00");
this.add(RJ1108);
}
if((scanFile("S:\\Files\\RJ1114.txt"))>0)
{
this.setVisible(true);
JButton RJ1114=new JButton("11.02 ora 14:00");
this.add(RJ1114);
}
if((scanFile("S:\\Files\\RJ1208.txt"))>0)
{
this.setVisible(true);
JButton RJ1208=new JButton("12.02 ora 08:00");
this.add(RJ1208);
}
if((scanFile("S:\\Files\\RJ1214.txt"))>0)
{
this.setVisible(true);
JButton RJ1214=new JButton("12.02 ora 14:00");
this.add(RJ1214);
}
}
public static int scanFile(String fileName) throws FileNotFoundException {
Scanner scanner = new Scanner(new File(fileName));
int freeSeat=0;
while(scanner.hasNextLine()) {
String line=scanner.nextLine();
int a = Integer.valueOf(line);
if(a==0)
{
freeSeat+=1;
}
}
return freeSeat;
}
Sorry for the long code . For example : RJ1214 , PS1212 and MP1213 buttons are NOT added even if they are true . I know the code looks like trash and all that .
Aucun commentaire:
Enregistrer un commentaire