Displaying An Array Of Images
So Here's My Code:
Code:
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.*;
public class GUI
{
public void ShowDialog(String Message)
{
JFrame frame = new JFrame("Message");
JOptionPane.showMessageDialog(frame,Message);
}
public void ShowResult(resultlist list[],JFrame f) throws MalformedURLException
{
JLabel lab[]=new JLabel[list.length];
for(int i=0;i<list.length;i++)
{lab[i]=new JLabel();}
File file[]=new File[list.length];
URL url[]=new URL[list.length];
Downloader X[]=new Downloader[list.length];
for(int i=0;i<list.length;i++)
{
file[i]=new File("\temp\\"+list[i].VideoName.toString()+".jpg");
System.out.println(list[i].ThumbnailUrl.toString());
System.out.println(list[i+1].ThumbnailUrl.toString());
url[i]=new URL(list[i].ThumbnailUrl.toString());
X[i]=new Downloader(url[i],file[i]);
X[i].run();
}
ImageIcon icon[]=new ImageIcon[list.length];
for(int i=0;i<list.length;i++)
{icon[i]=new ImageIcon("\temp\\"+list[i].VideoName.toString()+".jpg");}
for(int i=0;i<list.length;i++)
{lab[i].setIcon(icon[i]);}
Button b[]=new Button[list.length];
for(int i=0;i<list.length;i++)
{
f.add(lab[i]);
b[i] = new Button("Download");
f.add(b[i]);
b[i].addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
}
});
}
f.setVisible(true);
f.setSize(500,500);
f.revalidate();
}
}
Everything works fine when set to work out of for loop ie. for 3 or 4 images...but once put inside the for loop...images get downloaded....but somehow the frame does not display those images...it seems as if the frame is not being refreshed...
Can Anyone check the problem with the code?
Re: Displaying An Array Of Images
I gave you a link to a tutorial in your earlier thread. It doesn't look like you went through the section on layouts.
Oh, and Quote:
Everything works fine ...
The code you posted doesn't even compile. Apart from using two classes you haven't provided, one of which has a name that violates the coding conventions, there's a call to a nonexistent method of a standard JDK class.
db
Re: Displaying An Array Of Images
Thanks....Layout Manager Just Might Help Here...I'll Try It Out...The Code May Not Compile Coz Its Not The Full Code...It Is Divided Into 4-5 Files...I Just Posted The GUI Part...
Re: Displaying An Array Of Images
Quite apart from your 4-5 files, JFrame does not have a revalidate() method.
db