Thursday, February 12, 2009

Slide Show in java

Hi,


I am posting here a slide show demo in java.
Just change the path of folder containing images.

It is same as xp slide demo.You can just navigate all images by
next and previous button.
You have to just set the path containing lots of images in folder.

For the source code follow the link below

/*

* Program for implementing a Slide show in java

* Copyright 2009 @ yuvadeveloper

* Code By:- Prashant Chandrakar

*/

import javax.swing.*;

import java.awt.*;

import java.awt.image.*;

import java.io.*;

import javax.swing.*;

import java.awt.event.*;

class JSlideShow extends JFrame implements ActionListener

{

JLabel image;

File [] files;

int imageNo;

public JSlideShow()

{

super("SliderDemo by prashant chandrakar");

///for setting folder path containing images

setImageArray();

if(files.length > 0)

image = new JLabel(new ImageIcon(files[0].toString()));

////buttons for navigating images

JButton pre = new JButton("Prev");

pre.setActionCommand("pre");

pre.addActionListener(this);

JButton next = new JButton("Next");

next.setActionCommand("next");

next.addActionListener(this);

JPanel jp = new JPanel();

jp.add(pre);

jp.add(next);

this.setLayout(new BorderLayout());

this.getContentPane().add("North", image);

this.getContentPane().add("Center", jp);

this.setSize(1024, 768);

this.setVisible(true);

this.addWindowListener(new WindowAdapter()

{

public void windowClosing(WindowListener we)

{

System.exit(0);

}

});

}

public void setImageArray()

{

////just change the folder path containing images

File path = new File("d:/nondicom/images/");

files = path.listFiles();

}

public void setImage(int number)

{

image.setIcon(new ImageIcon(files[number].toString()));

}

public void actionPerformed(ActionEvent e)

{

if (e.getActionCommand().equals("pre"))

{

if (imageNo == 0)

{

imageNo = files.length-1;

}

else

{

imageNo--;

}

setImage(imageNo);

}

else if (e.getActionCommand().equals("next"))

{

if (imageNo == files.length-1)

{

imageNo = 0;

}

else

{

imageNo++;

}

setImage(imageNo);

}

}

public static void main(String a[])

{

new JSlideShow();

}

}

No comments:

Post a Comment