6 Replies - 283 Views - Last Post: 20 April 2013 - 12:03 AM Rate Topic: -----

#1 metesis  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 17-April 13

want to create image array but only show bug image file not bug1..bug6

Posted 17 April 2013 - 09:02 AM


Icon[] hug = new ImageIcon[7];
hug[0]=new ImageIcon(("bug.JPG"));
for(j=1;j<7;j++)
{
hug[j] = new ImageIcon(("bug"+j+".GIF"));

}

int i =0;
JLabel[] label = new JLabel[7];
for(i=2;i<7;i++)
{
label[i]=new JLabel(""+i,hug[i],SwingConstants.LEFT);
label[i].setToolTipText("this is label"+i);
add(label[i]);

}




i named the image file as bug,bug1,bug2....bug6....but the code only show bug image file.......but image file named bug1,bug2.....bug6 is not show instead of them bug image file is shown,any solution

Is This A Good Question/Topic? 0
  • +

Replies To: want to create image array but only show bug image file not bug1..bug6

#2 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2684
  • View blog
  • Posts: 11,342
  • Joined: 20-September 08

Re: want to create image array but only show bug image file not bug1..bug6

Posted 17 April 2013 - 09:20 AM

Please post output of

System.out.println(getContentPane().getLayout().getClass());

Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8328
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: want to create image array but only show bug image file not bug1..bug6

Posted 17 April 2013 - 07:49 PM

add(label[i]);

to what are you adding these JLabel ?
What is the Layout of that Component ?

Better to post a bit more code.
Was This Post Helpful? 0
  • +
  • -

#4 metesis  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 17-April 13

Re: want to create image array but only show bug image file not bug1..bug6

Posted 17 April 2013 - 11:18 PM

View Postg00se, on 17 April 2013 - 09:20 AM, said:

Please post output of

System.out.println(getContentPane().getLayout().getClass());


i'm trying your solution but the state is same .i think the problem is on hug[j] = new ImageIcon(getClass().getResource("bug"+j+".GIF")); line cause it only finds bug.gif file,the "+j" is not working.......so instead of bug1..bug6 it assign bug.gif...... any solution

View Postpbl, on 17 April 2013 - 07:49 PM, said:

add(label[i]);

to what are you adding these JLabel ?
What is the Layout of that Component ?

Better to post a bit more code.

here's the code


import java.awt.FlowLayout;
import javax.swing.SwingConstants;
import javax.swing.JLabel;
import javax.swing.Icon;
import javax.swing.JFrame;
import javax.swing.ImageIcon;

//
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;


 public class LabelFrame extends JFrame
{
	
	private JLabel label1;
	
	
	public LabelFrame()
	{
		super("testing label");
		setLayout(new FlowLayout());
		label1 = new JLabel("01");
		label1.setToolTipText("this is label1");
		add(label1);
		Icon[] hug = new ImageIcon[7];
		int j;
		hug[0]=new ImageIcon(("bug.JPG"));
		for(j=1;j<7;j++)
		{
			 hug[j] = new ImageIcon(getClass().getResource("bug"+j+".GIF"));
		
		
		}
		
		
		
		
		int i =0;
		JLabel[] label = new JLabel[7];
		for(i=2;i<7;i++)
		{
			label[i]=new JLabel(""+i,hug[i],SwingConstants.LEFT);
			label[i].setToolTipText("this is label"+i);
			add(label[i]);
			
			
			
			
			
			
			}
		

		
		
		
		}
		
		}
		
	





Was This Post Helpful? 0
  • +
  • -

#5 metesis  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 17-April 13

Re: want to create image array but only show bug image file not bug1..bug6

Posted 17 April 2013 - 11:26 PM

the problem is solved.....thanks for help
Was This Post Helpful? 0
  • +
  • -

#6 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2684
  • View blog
  • Posts: 11,342
  • Joined: 20-September 08

Re: want to create image array but only show bug image file not bug1..bug6

Posted 18 April 2013 - 04:05 AM

Wouldn't it be a lot easier to make them the same image type and to number them 0-6? ;)
Was This Post Helpful? 0
  • +
  • -

#7 metesis  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 17-April 13

Re: want to create image array but only show bug image file not bug1..bug6

Posted 20 April 2013 - 12:03 AM

View Postg00se, on 18 April 2013 - 04:05 AM, said:

Wouldn't it be a lot easier to make them the same image type and to number them 0-6? ;)/>

yeah,i'm doing so.......thanks:p
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1