String [] texts= new String[26];
for(int a=0; a<26; a++){
String te=money[a].getText();
texts[a] = te;
box[a].setText(te);
}
In this code I want to set Text boxs and box is a JLabel. I created moneys which are also JLabel and has texts. I want that if I click on a box I wan to remove that box and money which has the same text with that box. For this I wrote this code:
for(clickLoop=0; clickLoop<26; clickLoop++){
box[clickLoop].addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e){
clickCount++;
if(clickCount == 0){
box[26].setVisible(false);
JLabel labelReference=(JLabel)e.getSource();
ortaPanel.remove(welcome);
ortaPanel.revalidate();
ortaPanel.repaint();
ortaPanel.add(labelReference).setBounds(390,480,im.getIconWidth(),im.getIconHeight());
System.out.println("a");
ortaPanel.add(six).setBounds(305, 465, s.getIconWidth(), s.getIconHeight());
labelReference.removeMouseListener(this);
}else if(clickCount == 6){
e.getComponent().setVisible(false);
JLabel labelReference=(JLabel)e.getSource();
ortaPanel.remove(six);
ortaPanel.revalidate();
ortaPanel.repaint();
//ortaPanel.add(labelReference).setBounds(390,480,im.getIconWidth(),im.getIconHeight());
ortaPanel.add(five).setBounds(305, 465, s.getIconWidth(), s.getIconHeight());
labelReference.removeMouseListener(this);
}else {
e.getComponent().setVisible(false);
String esles=((JLabel) e.getComponent()).getText();
for(int i=0; i<money.length; i++){
if(esles.equals(money[i].getText()) ){
sagPanel.remove(money[i]);
}
}
}
System.out.println(clickCount);
}
});
}
}
Some labels are working truely but most of them didnt work. I dont know why? There is one more question I want to ask: As you can see the code above I created text of box[i] same as text of money[i]. Instead of doing like that I want to make it randomly. I tried but did not achive. Do you know how can I do that? Thanx in advance.