0
 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.

Dror Bereznitsky
  • 20,048
  • 3
  • 48
  • 57
user3075117
  • 49
  • 1
  • 9
  • For better help sooner, post an [MCVE](http://stackoverflow.com/help/mcve) (Minimal Complete and Verifiable Example). – Andrew Thompson Apr 05 '14 at 15:44
  • 1
    `ortaPanel.add(six).setBounds(..)` Java GUIs might have to work on a number of platforms, on different screen resolutions & using different PLAFs. As such they are not conducive to exact placement of components. To organize the components for a robust GUI, instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556), along with layout padding & borders for [white space](http://stackoverflow.com/q/17874717/418556). – Andrew Thompson Apr 05 '14 at 15:45

0 Answers0