dynamically chane icons on label

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MEENAKSHI123
    New Member
    • Mar 2014
    • 1

    dynamically chane icons on label

    I am doing a project on Nqueens and i need dynamically show the movement of queens but the screen shows only the final o/p and not the proc ess of how is it working!How can i visualize each step!
    i am giving a part of that code
    Code:
    //THIS FOR CREATING CHESS BOARD
    p3.setLayout(new GridLayout(i,i));
    					 gbl=new GridBagConstraints();
    					for(int m=0;m<i;m++)
    					{
    						for(int n=0;n<i;n++)
    						{	
    							gbl.gridx=m;
    							gbl.gridy=n;
    							l[m][n]=new JLabel();
    							l[m][n].setOpaque(true);
    							if((m+n)%2==0)
    							{
    								l[m][n].setBackground(Color.black);
    								l[m][n].setIcon(new ImageIcon("wb.jpg"));
    								p3.add(l[m][n],gbl);
    							}
    							else
    							{	l[m][n].setBackground(Color.white);
    								l[m][n].setIcon(new ImageIcon("ww.jpg"));	
    								p3.add(l[m][n],gbl);
    							}
    						}
    					}
    //THIS IS TO DYNAMICALLY GENERATE
    for(int hh=0;hh<n;hh++)
    		{	for(int m=0;m<n;m++)
    			{
    				if(l[hh][m].getIcon()!=null)
    					l[hh][m].setIcon(null);
    				
    			}
    		}
    
    	
    		if((k+ii)%2==0)
    		{
    
    			l[k][ii].setIcon(new ImageIcon("wb.jpg"));
    
    			//p3.add(l,gbl);
    
    		}
    		else
    		{
    
    			l[k][ii].setIcon(new ImageIcon("ww.jpg"));
    
    			//p3.add(l,gbl);
    
    		}
    Last edited by Rabbit; Mar 30 '14, 06:13 AM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • chaarmann
    Recognized Expert Contributor
    • Nov 2007
    • 785

    #2
    You can visualize it by using a debugger. In Eclipse switch to the "debug" view, set a breakpoint on line 3, start your program with "run"->"debug" and step through your program line by line.

    Another way is to print out the variables in every line
    for example with System.out.prin tln("line xx: myVariable=" + myVariable)

    Comment

    Working...